Applet with access to port serials

F

Fran García

I´m developing an application that must access to port serials. I need
execute an applet which reads the information through the port serial. I´m
testing if that is possible with this example:

import javax.comm.*;
import com.sun.comm.*;

import javax.swing.*;
import java.awt.*;

import java.lang.*;
import java.util.*;
import java.io.*;

public class Applet1 extends JApplet{

static Enumeration listaPuertos;
static CommPortIdentifier idPuerto;

public void init() {
//String cadena = new String((new
Integer(CommPortIdentifier.PORT_SERIAL)).toString());
//getContentPane().add(new JLabel(cadena));
listaPuertos = CommPortIdentifier.getPortIdentifiers();

while( listaPuertos.hasMoreElements() ) {
idPuerto = (CommPortIdentifier)listaPuertos.nextElement();
if( idPuerto.getName().equals("COM1") )
getContentPane().add(new JLabel(idPuerto.getName()));
}
}
}

but it doesn´t work. I think that I have problems with the CLASSPATH for the
comm serial extension. Can anybody help me? Can anybody say any tip for this
work?

Regards

Fran García
 
K

Ken Larson

Fran said:
I´m developing an application that must access to port serials. I need
execute an applet which reads the information through the port serial. I´m
testing if that is possible with this example:

import javax.comm.*;
import com.sun.comm.*;

import javax.swing.*;
import java.awt.*;

import java.lang.*;
import java.util.*;
import java.io.*;

public class Applet1 extends JApplet{

static Enumeration listaPuertos;
static CommPortIdentifier idPuerto;

public void init() {
//String cadena = new String((new
Integer(CommPortIdentifier.PORT_SERIAL)).toString());
//getContentPane().add(new JLabel(cadena));
listaPuertos = CommPortIdentifier.getPortIdentifiers();

while( listaPuertos.hasMoreElements() ) {
idPuerto = (CommPortIdentifier)listaPuertos.nextElement();
if( idPuerto.getName().equals("COM1") )
getContentPane().add(new JLabel(idPuerto.getName()));
}
}
}

but it doesn´t work. I think that I have problems with the CLASSPATH for the
comm serial extension. Can anybody help me? Can anybody say any tip for this
work?

Regards

Fran García
I don't do a lot of applets, but I would check:
1. that javacomm is installed properly. this is generally separate from
the JRE/JDK. make sure comm.jar, javax.comm.properties, and
win32comm.dll are in the locations they are supposed to be (mine are in
jre\lib\ext, jre\lib, and jre\bin) (the name of the jar/dll may vary
depending on your platform and where you are getting javacomm from, sun,
ibm, etc).

If these files are in the right place, you shouldn't need to change your
classpath.

2. It seems to me you would also have to make sure that the security
settings for the applet allowed you to use comm. The symptom here would
be some kind of security exception.

3. Also, you should be aware of which JRE your browser is using, it may
not be the same as the JDK you are using. Make sure step 1. is correct
for the JRE that the browser is using.
 
A

Andrew Thompson

| I´m developing an application that must access to port serials.
I need
| execute an applet which reads the information through the port
serial. I´m
| testing if that is possible with this example:
...
No you are not, that example does not compile.
_Please_ copy and paste code, rather than
typing it in.

| but it doesn´t work.

That is why the java console is so handy,
it shows errors in applets, as well as any
System.out.println() messages.

| ..I think that I have problems with the CLASSPATH for the
| comm serial extension. Can anybody help me? Can anybody say any
tip for this
| work?

Check the java console, it may well
be saying SecurityAccessException
or similar.

Do this in an application _first_ and
check it works, _then_ worry about
getting it to work as an applet.
(Applications do not have the same
security restrictions imposed on applets.)

When you get back to the applet, give
an URL so people can check it easily.

For futher tips on getting help, have a
look at this document..
http://www.physci.org/codes/sscce.jsp

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top