Applet with access to port serials

Discussion in 'Java' started by Fran García, Jan 20, 2004.

  1. Fran García

    Fran García Guest

    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
    Fran García, Jan 20, 2004
    #1
    1. Advertising

  2. Fran García

    Ken Larson Guest

    Fran García wrote:
    > 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.
    Ken Larson, Jan 20, 2004
    #2
    1. Advertising

  3. "Fran García" <> wrote in message
    news:buiuit$4m9$...
    | 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

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
    Andrew Thompson, Jan 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    596
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,249
    Joerg Jooss
    Apr 28, 2005
  3. b3ny
    Replies:
    11
    Views:
    919
    Babu Kalakrishnan
    Nov 20, 2004
  4. Gerald Klix
    Replies:
    0
    Views:
    1,268
    Gerald Klix
    Oct 26, 2005
  5. Replies:
    1
    Views:
    545
    Andrew Thompson
    Nov 19, 2007
Loading...

Share This Page