Duration of CommPortIdentifier.getPortIdentifiers() ?

Hi all,
I have a questino about the duration of CommPortIdentifier.getPortIdentifiers()
In my code I use CommPortIdentifier.getPortIdentifiers() and place it into an Enumeration portList, the problem is that it takes about 120 seconds to execute portList = CommPortIdentifier.getPortIdentifiers().
I use Windows 2000 as OS, i don't know if that is the cause that it takes 120 seconds or is that the normal behaviour of CommPortIdentifier.getPortIdentifiers()?
Greetings

On a Windows XP operating system it seems to work faster then on my own computer with windows 2000.

Similar Messages

  • Bug in CommPortIdentifier.getPortIdentifiers()

    Hi,
    CommPortIdentifier.getPortIdentifiers()
    From java communications API, when called again returns resultset twice. After each successive invokation it keeps adding the ports to the last result set.
    Here is the test code:
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    Every call to listPorts keep adding machine port list to the last result set.
    Any idea what's going on? Is this a bug?
    I am trying the same logic in an Applet. Even if I call listPorts from applet init method, it still has the same problem.import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    import javax.comm.*;
    import java.util.Enumeration;
    public class Test {
         public static String listPorts() {
              System.out.println("listPorts Called");
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
              // Discard it
              StringBuffer portList = new StringBuffer("");
              Enumeration ports =
              CommPortIdentifier.getPortIdentifiers();
              int portCount = 0;
              while (ports.hasMoreElements()) {
              portCount++;
              CommPortIdentifier port =
                   (CommPortIdentifier)ports.nextElement();
              String type;
              switch (port.getPortType()) {
                   case CommPortIdentifier.PORT_PARALLEL:
                   type = "Parallel";
                   break;
                   case CommPortIdentifier.PORT_SERIAL:
                   type = "Serial";
                   break;
                   default: /// Shouldn't happen
                   type = "Unknown";
                   break;
              // System.out.println(port.getName() + ": " + type);
              portList.append(port.getName() + ": " + type + " ");
              System.out.println("portCount="+portCount);
              System.out.println(portList.toString());
              return portList.toString();
         public static void main(String[] args) {
              listPorts();
              listPorts();
              listPorts();
              listPorts();
    The program prints ports for the first call and then keeps adding the ports to the result set for each successive call to listPorts from main.
    I am trying to run this from an applet. If I put the same code inside applet init method. I get the same behavior between page loads. Looks like it's per JVM invocation.
    Any help is appreciated.
    Thanks,
    Prashant Rane

    Each call to initialise will add its ports to the commportidentifier. This is how its supposed to work, as each driver is only supposed to be initialized once.
    Why don't you follow the examples on the javax.comm pages?
    http://java.sun.com/products/javacomm/javadocs/API_users_guide.html

  • Comm api 2.0 - CommPortIdentifier.getPortIdentifiers() returns empty enum

    Hi,
    I'm trying to open connetion with my GSM modem which it connected to my PC by RS-232 cable.
    I'm trying to run my program on Windows XP.
    But, when i'm running the following piece of code, the enumeration return empty.
    How it can be solved?
    Enumeration en = CommPortIdentifier.getPortIdentifiers();
    System.out.println(en);
    // Iterate through the ports.
    while (en.hasMoreElements()) {
    portId = (CommPortIdentifier) en.nextElement();
    if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    System.out.println(portId.getName());
    On the Widows, Device manager, i can find the modem under Ports section/
    Thanks,
    Eyal.

    eyalm_nm wrote:
    But, when i'm running the following piece of code, the enumeration return empty.Welcome to the Sun Forums,
    First of all, Enumerations and enums are completely different things. Don't use those terms interchangeably. Second, when posting code please highlight it in the editor and click the CODE button.
    Is the Enumeration empty, or does it not contain an element where getPortType() == CommPortIdentifier.PORT_SERIAL?

  • CommPortIdentifier.getPortIdentifiers() returns nothing on linux

    Sorry for bad english, please.
    I does theese steps:
    1. Read manual about installing java comm
    2. Download java comm for Windows and for Linux
    3. Exec installation steps (comm.jar into %JAVA_HOME%/lib/ext, native libs into %JAVA_HOME%/lib/<platform named dir>, javax.comm.properties with correct driver name into %JAVA_HOME%/lib).
    4. Run demo app "BlackBox" on Windows. All ok. Port found, works correctly.
    5. Run demo on Linux. It writes "No com ports found".
    I cannot understand, why. Can someone help me?
    PS external lib RXTX causes same result - "No com ports found".
    However, it is fact, that com ports phisycally exists.
    After I write my app, I found, that method CommPortIdentifier.getPortIdentifiers() returns empty values list on linux. Can any tell, why?

    eyalm_nm wrote:
    But, when i'm running the following piece of code, the enumeration return empty.Welcome to the Sun Forums,
    First of all, Enumerations and enums are completely different things. Don't use those terms interchangeably. Second, when posting code please highlight it in the editor and click the CODE button.
    Is the Enumeration empty, or does it not contain an element where getPortType() == CommPortIdentifier.PORT_SERIAL?

  • Comm API problems (getPortIdentifier)

    Hi! I wrote an applet that uses the javax.comm API to manage a serial port in the host machine. When first develop it with JDK 1.1.8 the applet (and an application) runs perfectly. I now have Java 2 (jdk1.3.1._02) and I'm trying to run this applet and when it arrives to a CommPortIdentifier.getPortIdentifier(String) call, I got this message:
    "java.io.lang: name can't be null"
    First I thought that was my applet, that my application was wrong, so I try to use de SerialDemo example that comes with the javax.comm and It doesn't work either! If I run it with the latest beta version of JDK (1.4 I think) it runs again... any idea???
    Thanks a lot! =)

    in jdk1.3...
    u have to copy the win32com.dll and comm.properties file in the jre\1.3\bin folder of the machine
    and comm.jar in the jre\1.3\lib folder....
    remember, in windows, u will get the
    ...\program files\javasoft\jre\1.3\lib or ..\bin
    ther u have to store not in ur c:\jdk1.3\bin
    Regards,
    Ritesh

  • CommPortIdentifier Problem

    Hey everyone,
    So I installed javax.comm unto my windows computer (all the files are in the right place) and I was then able to import javax.comm package with no problems. I then tried to run Sun's SimpleRead class program to check that all things were in order and I keep getting the error that the CommPortIdentifier.class is not found. I was prompted for its source document, but wasn't too sure what this meant. I simply put the file extension for the comm.jar, but is tells me that the comm.jar does not contain the source for the CommPortIdentifier.class. I also built a path for the comm.jar in the specific project that I am working on.
    Any help or ideas as to why this problem is occurring would be greatly appreciated.
    Thanks
    -José

    I added the JAR file into the project classpath using the Eclipse IDE, but I still keep having problems.
    1. When I try to compile the line:
    portList = CommPortIdentifier.getPortIdentifiers();
    I keep getting a window that says "The source attachment does not contain the source for the file CommPortIdentifier.class. You can change the source attachment by clicking Change Attached Source below." However, I'm not sure what to change the source to; currently, I have it to the folder extension of the javaxcomm download that contained the 3 files (i.e. comm.jar, javax.comm.properties, and win32com.dll).
    2. This one just occurred today as I was trying to fix the problem. I got an error that reads
    Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jre6\bin\win32com.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
    This leads me to a new questions as well: does the JAVA Communications API support windows 64-bit clients?

  • RXTX getPortIdentifiers stuck

    Hello.
    I'm trying to use RXTX, taken from http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip
    It's ready binaries. I've just put .jar file in jre/lib/ext and .dll file to windows/system32
    I work under WindowsXP and use NetBeans 6.5
    My program compiles, but stuck up when calling CommPortIdentifier.getPortIdentifiers();
    I was also trying CommPortIdentifier.getPortIdentifier("COM1"); with the same result.
    So, the following program never ends:
    package mypack;
    import java.util.*;
    import gnu.io.*;
    public class Main {
    public static void main(String[] args) {
    System.loadLibrary("rxtxSerial");
    Enumeration portList = CommPortIdentifier.getPortIdentifiers();
    }How do you think, why?

    This is fixed.
    I've just deleted bluetooth adapter com port. Somehow, it made RXTX too long to get ports list.

  • Application working under NetBeans but not as a *.jar file

    Hello,
    recently I found a little problem. I wrote application that shows all available ports in my computer. When I am running this applications under NetBeans it works with no problem - finds all available ports. Then I am building it to the *.jar file. Application is working with no problem but command:
    Enumeration PortIds = CommPortIdentifier.getPortIdentifiers();
    is not returning any identifiers - PortIds is empty.
    Anyone knows a solution for this type of problems? Thanks

    Hi Venkatesh,
    Few questions.
    1. What is your JDeveloper version? (Always better to post your JDev version along with the question, which would help us to help you better).
    2. Did you try adding webserviceclient.jar to the classpath? (Search in your JDev installation directory for the location of this jar file).
    -Arun

  • AT Commands , Hyper Terminal and java

    Hi,
    I have following problem, i have PCMCIA Type -11 Wireless modem.its installed on my system COM4 port.
    Now first problem is that when i try to connect with hyper terminal to COM4 there is no response from it .It become Idle.but when i connect with COM3 which is my Dialup modem port it works fine with all AT commands.
    Now 2nd things is that same with below code i tried to send sms using AT command on COM4 its has same behaviour as it was in Hyper terminal mean no response. no Data Available event occour
    Please help me in this regard and suggest me a solution.
    package serialio;
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class SimpleWrite
        implements Runnable, SerialPortEventListener
      public void run()
      static Enumeration portList;
      static CommPortIdentifier portId;
      static String dest = "0517111930";
      static String messageString = "Hello";
      InputStream inputStream;
      static SerialPort serialPort;
      static OutputStream outputStream;
      public void serialEvent(SerialPortEvent event)
        switch (event.getEventType())
          case SerialPortEvent.BI:
          case SerialPortEvent.OE:
          case SerialPortEvent.FE:
          case SerialPortEvent.PE:
          case SerialPortEvent.CD:
          case SerialPortEvent.CTS:
          case SerialPortEvent.DSR:
          case SerialPortEvent.RI:
          case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
          case SerialPortEvent.DATA_AVAILABLE:
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line = "";
            try
              while ( (line = reader.readLine()) != null)
                System.out.println(line);
            catch (IOException e)
              System.err.println("Error while reading Port " + e);
            break;
        } //switch
      public SimpleWrite(SerialPort serial)
        try
          inputStream = serial.getInputStream();
          try
            serial.addEventListener(this);
          catch (TooManyListenersException e)
            System.out.println("Exception in Adding Listener" + e);
          serial.notifyOnDataAvailable(true);
        catch (Exception ex)
          System.out.println("Exception in getting InputStream" + ex);
      public static void main(String[] args)
    //    String line1="AT+CMGF=1\r\n";
    //    String line2="AT+CMGS=\""+ dest+"\"\r\n";
    //    String line3=messageString+"\r\n";
    //    String line4="\u001A";
        String line1 = "AT+CMGF=1\r\n";
        String line2 = "AT+CMGS=" + dest + "\r\n";
        String line3 = messageString + "^Z\r\n";
    //    String line4 = "\u001A";
        portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements())
          portId = (CommPortIdentifier) portList.nextElement();
          if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
            System.out.println("SMS Sending........");
            if ( portId.getName().equals("COM4"))
              System.out.println("SMS Sending....Port Found");
              try
                serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
                SimpleWrite wr = new SimpleWrite(serialPort);
              catch (PortInUseException e)
                System.out.println("Port In Use " + e);
              try
                outputStream = serialPort.getOutputStream();
              catch (IOException e)
                System.out.println("Error writing to output stream " + e);
              try
                serialPort.setSerialPortParams(
                    2400,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
              catch (UnsupportedCommOperationException e)
              try
                outputStream.write(line1.getBytes());
                outputStream.write(line2.getBytes());
                outputStream.write(line3.getBytes());
                outputStream.flush();
              catch (IOException e)
                System.out.println("Error writing message " + e);
      /** show text in the text window
       * @param Text text string to show on the display
      public static void showText(String Text)
        System.out.println(Text);
    }

    * SerialWrite.java
    * Created on September 10, 2008, 2:51 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package com.sms;
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class SerialWrite implements Runnable, SerialPortEventListener
    static String output="";
    public void run()
    static Enumeration portList;
    static CommPortIdentifier portId;
    static String dest = "+91999999999";
    static String messageString = "Hello Testing11";
    InputStream inputStream;
    static SerialPort serialPort;
    static OutputStream outputStream;
    public void serialEvent(SerialPortEvent event)
    switch (event.getEventType())
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
              System.out.println("Error");
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    String line = "";
    try
    while ( (line = reader.readLine()) != null)
    if(line.equalsIgnoreCase("OK") || (line.indexOf("+CMGS") != -1))
         output=line;
              Thread.sleep(10);
    catch (Exception e)
    System.err.println("Error while reading Port " + e);
    break;
    } //switch
    public SerialWrite(SerialPort serial)
    try
    inputStream = serial.getInputStream();
    try
    serial.addEventListener(this);
    catch (TooManyListenersException e)
    System.out.println("Exception in Adding Listener" + e);
    serial.notifyOnDataAvailable(true);
    catch (Exception ex)
    System.out.println("Exception in getting InputStream" + ex);
    public static void main(String[] args) throws Exception
         int i=0;
    String line0 = "ATZ\r\n";
    String line1 = "AT+CMGF=1\r\n";
    String line2 = "AT+CSCA=\"+919888888\"\r\n";
    //String line3 = "AT+CMGS="+"\""+ dest + "\""+"\r\n";
    String line3 = "AT+CMGS="+"\""+ args[0] + "\""+"\r\n";
    //String line4 = messageString;
    String line4 = args[1];
         portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements())
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
    System.out.println("SMS Sending........");
    if ( portId.getName().equals("/dev/ttyACM0"))
    System.out.println("SMS Sending....Port Found");
    try
    serialPort = (SerialPort) portId.open("SerialTestApp", 2000);
    SerialWrite wr = new SerialWrite(serialPort);
    catch (PortInUseException e)
    System.out.println("Port In Use " + e);
    try
    outputStream = serialPort.getOutputStream();
    catch (IOException e)
    System.out.println("Error writing to output stream " + e);
    try
    serialPort.setSerialPortParams(
    115200,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    catch (UnsupportedCommOperationException e)
    try
    outputStream.write(line0.getBytes());
              Thread.sleep(10);
    while(!output.equalsIgnoreCase("ok"))
              Thread.sleep(10);
              output="";
    outputStream.write(line1.getBytes());
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
    outputStream.write(line2.getBytes());
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
         for(i=0;i<3;i++)
    outputStream.write(line3.getBytes());
    Thread.sleep(10);
    outputStream.write(line4.getBytes());
    Thread.sleep(10);
    outputStream.write(26);
    outputStream.write("\r\n".getBytes());
    outputStream.flush();
    while(!output.equalsIgnoreCase("ok"))
                   Thread.sleep(10);
              output="";
              System.out.println("Message Sent !!!!!!!!!1");
    catch (IOException e)
    System.out.println("Error writing message " + e);
    /** show text in the text window
    * @param Text text string to show on the display
    public static void showText(String Text)
    System.out.println("TEXT "+Text);
    }

  • Problem printing out to a parallelport printer

    Hello, I am using the javax.comm.*; package and I am having problems
    printing to the parallelport.
    Well, it prints out the string but the problem is that the light for paper feed
    starts blinking eventhough there is paper , once I click the paper feed button
    the printer then prints out the string.
    So, basically, everything is ok, apart from that I have to press the paper feed
    button for each time I want to print something.
    There is an error in my code somewhere, but as I am new to port communications I cannot understand what to do.
    Below is my code, please help.
    Thanks!
    public void print(String s){
    Enumeration ports;
    CommPortIdentifier portId;
         try{
              portId = CommPortIdentifier.getPortIdentifier("LPT1");
             addPort(portId,s);
         }catch (NoSuchPortException e){
                     e.printStackTrace();
    public static void addPort(CommPortIdentifier portId,String s){
         try{
              ParallelPort port = (ParallelPort)portId.open("LPT1",2000);
            /*port.notifyOnError(true);
            port.notifyOnBuffer(true);
            port.addEventListener(new ParallelPortEventListener(){
                   public void parallelEvent(ParallelPortEvent ppe){
                           System.out.println(ppe.toString());
                           System.out.println("An event has occured");
              try{
                   OutputStream os = port.getOutputStream();
                   if(os == null){
                        System.out.println("Os is null");
                   else{          
                          os.write(s.getBytes());
                   //os.flush();
              catch(Exception eis){
                   eis.printStackTrace();
              port.close();
         catch(PortInUseException e){
              System.out.println(e.currentOwner);
              e.printStackTrace();
         catch(Exception ecl){
              ecl.printStackTrace();
    }Of course this class imports :
    import java.util.Enumeration;
    import javax.comm.*;
    import javax.comm.CommPort;
    import javax.comm.CommPortIdentifier;
    import javax.comm.ParallelPort;
    import javax.comm.NoSuchPortException;
    import javax.comm.PortInUseException;
    import java.io.*;

    Wow - I wonder how the OP thought that the
    Developers Home > Developer Forums > Java Forums >
    Java Mobility Forums > Consumer and Commerce >Consumer and Commerce General >
    Forum was a correct choice for this problem??It's the same logic that leads one to believe that being new to port communications omits them from the responsibility of using general troubleshooting techniques to isolate/identify a problem.
    This logic often leads to obscure questions also, sadly.

  • How to share an array among members of a package

    I need to share the value of h among members of a package. The values for Byte h are generated by button events in the other program in the package [ sample below ]. That is transformed into ASCII code, h, which ideally should go through SerialWriter and out the serial port.
    private void menuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
            Charset asciiCharset = Charset.forName("US-ASCII");
         CharsetDecoder decoder = asciiCharset.newDecoder();
         byte h[] = {33, 48, 48, 66, 77, 69, 78, 85, 13}; //brings menu up
         ByteBuffer asciiBytes = ByteBuffer.wrap(h);
         CharBuffer hChars = null;
         try {
              hChars = decoder.decode(asciiBytes);
         } catch (CharacterCodingException e) {
              System.err.println("Error decoding");
              System.exit(-1);
              System.out.println(hChars);
        }                                          Predictably, when trying to run the main member of the package -- listed below -- h is not transferred, hence not instantiated, and I get a Null Pointer Exception. How can I transfer the value of h so that is seen by the "connect" method below? thanks
    package desktopapplication1;
    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.ByteBuffer.*;
    import java.nio.charset.*;
    import java.lang.String.*;
    import java.io.*;
    import java.util.*;
    import gnu.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.ByteBuffer.*;
    import java.nio.charset.*;
    import gnu.io.CommPort;
    import gnu.io.CommPortIdentifier;
    import gnu.io.SerialPort;
    * The main class of the application.
    public class DesktopApplication1 extends SingleFrameApplication {
            String defaultPort = "/dev/ttyS0";
         * At startup create and show the main frame of the application.
        @Override protected void startup() {
            show(new DesktopApplication1View(this));
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
        @Override protected void configureWindow(java.awt.Window root) {
         * A convenient static getter for the application instance.
         * @return the instance of DesktopApplication1
        public static DesktopApplication1 getApplication() {
            return Application.getInstance(DesktopApplication1.class);
        public void connect ( String portName ) throws Exception {
         String defaultPort = "/dev/ttyS0";
            Byte h;
            CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
            if ( portIdentifier.isCurrentlyOwned() )
                System.out.println("Error: Port is currently in use");
            else
                CommPort commPort = portIdentifier.open(this.getClass().getName(),200);
                if ( commPort instanceof SerialPort )
                    SerialPort serialPort = (SerialPort) commPort;
                    serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
                    InputStream in = serialPort.getInputStream();
                    OutputStream out = serialPort.getOutputStream();
                    (new Thread(new SerialReader(in))).start();
                    (new Thread(new SerialWriter(out))).start();
              out.write(h);
              out.flush();
                else
                    System.out.println("Error: Only serial ports are addressable by this application.");
         public static class SerialReader implements Runnable
            InputStream in;
            public SerialReader ( InputStream in )
                this.in = in;
            public void run ()
                byte[] buffer = new byte[1024];
                int len = -1;
                try
                    while ( ( len = this.in.read(buffer)) > -1 )
                        System.out.print(new String(buffer,0,len));
                catch ( IOException e )
                    e.printStackTrace();
        public static class SerialWriter implements Runnable {
            OutputStream out;
            SerialPort     serialPort;
            public SerialWriter ( OutputStream out )
                this.out = out;
            public void run ()
                try
                    int c = 0;
                    while ( ( c = System.in.read()) > -1 )
                        this.out.write(c);
                catch ( IOException e )
                    e.printStackTrace();
             try {
                     Thread.sleep(2000);  // Be sure data is xferred before closing
                  } catch (Exception e) {}
                  serialPort.close();
                  System.exit(1);
         * Main method launching the application.
        public static void main(String[] args) {
            launch(DesktopApplication1.class, args);
          try
                (new DesktopApplication1()).connect("/dev/ttyS0");
            catch ( Exception e )
                e.printStackTrace();
    }

    Make h global, and make an getH method in that class. And then make an instance of the class containing the getH() method, and call it from the connect() method.
    private byte h[] = {33, 48, 48, 66, 77, 69, 78, 85, 13};
    public byte[] getH() {
         return h;
    private void menuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
            Charset asciiCharset = Charset.forName("US-ASCII");
         CharsetDecoder decoder = asciiCharset.newDecoder();
          //brings menu up
         ByteBuffer asciiBytes = ByteBuffer.wrap(h);
         CharBuffer hChars = null;
         try {
              hChars = decoder.decode(asciiBytes);
         } catch (CharacterCodingException e) {
              System.err.println("Error decoding");
              System.exit(-1);
              System.out.println(hChars);
        }

  • Using a button to call a method

    I am trying to get the button actionPerformed to call the connect method. But I get this error message on compile:
    ras@2[nuvu]$ /usr/jdk/jdk1.6.0_04/bin/javac MonitorView2.java
    MonitorView2.java:77: connectPort(java.lang.String) in MonitorView2 cannot be applied to ()
    connectPort();
    Can someone decipher this for me? Why can't this be done? thx
    public class MonitorView2 extends JFrame {
         static SerialPort     serialPort;
         ByteArrayOutputStream asciiStream = new ByteArrayOutputStream();
         public MonitorView2()  {
              super("Monitor View 2");
         JPanel pane = new JPanel();
         setContentPane(pane);
         JButton testButton = new JButton("Test Comm On");
         pane.add(testButton);
         setSize(600, 300);
         setVisible(true);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         class TestButtonHandler implements ActionListener  {
              public void actionPerformed(ActionEvent e) {
                   System.out.println("Test button action works!");
                   try
                   String a = "33, 48, 48, 66, 67, 78, 49, 13"; //comm on;
                   //ByteArrayOutputStream asciiStream = new ByteArrayOutputStream();
                   byte[] buf = a.getBytes();
                   asciiStream.write(buf);
                   System.out.println("Buffer as a string");
                   System.out.println(asciiStream.toString());
                   System.out.println("Into array");
                   byte[] b = asciiStream.toByteArray();
                   for (int i=0; i<b.length; i++) {
                   System.out.print((char) b);
                   catch (Exception ex)
                        System.out.println("Exception has been thrown :" + ex);
                   connectPort();
              testButton.addActionListener( new TestButtonHandler());
         public void connectPort ( String portName ) throws Exception {
         String defaultPort = "/dev/ttyS0";
         String                asciiString;
         Charset asciiCharset = Charset.forName("US-ASCII");
         CharsetDecoder decoder = asciiCharset.newDecoder();
         //byte[] b = {33, 48, 48, 66, 67, 78, 49, 13}; //comm on
         byte[] b = asciiStream.toByteArray();
         ByteBuffer asciiBytes = ByteBuffer.wrap(b);
         CharBuffer bChars = null;
         try {
              bChars = decoder.decode(asciiBytes);
         } catch (CharacterCodingException e) {
              System.err.println("Error decoding");
              System.exit(-1);
              System.out.println(bChars);
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if ( portIdentifier.isCurrentlyOwned() )
    System.out.println("Error: Port is currently in use");
    else
    CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
    if ( commPort instanceof SerialPort )
    SerialPort serialPort = (SerialPort) commPort;
    serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    InputStream in = serialPort.getInputStream();
    OutputStream out = serialPort.getOutputStream();
    (new Thread(new SerialReader(in))).start();
    (new Thread(new SerialWriter(out))).start();
              out.write(b);
              out.flush();
    else
    System.out.println("Error: Only serial ports are handled by this example.");

    Seriously, learn the basics.
    Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    [http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
    Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

  • How to access the serial port in Java?

    How can I initialise and access the serial port for writing and reading data from it? Are there any code examples available?

    I tried that and I tried compiling and executing one of its examples, the one below:
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleWrite {
    static Enumeration portList;
    static CommPortIdentifier portId;
    static String messageString = "Hello, world!\n";
    static SerialPort serialPort;
    static OutputStream outputStream;
    public static void main(String[] args) {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    //if (portId.getName().equals("/dev/term/a")) {
    try {
    serialPort = (SerialPort)
    portId.open("SimpleWriteApp", 2000);
    } catch (PortInUseException e) {}
    try {
    outputStream = serialPort.getOutputStream();
    } catch (IOException e) {}
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}
    try {
    outputStream.write(messageString.getBytes());
    } catch (IOException e) {}
    But when I execute this I get the error:
    Exception in thread "main" java.lang.NoClassDefFoundError: SimpleWrite
    What is wrong with this example??

  • Is it a path problem, or what is it?? Please...

    Hi every one! I am just trying to open a Serial Port
    This is my code
    package demo2;
    * Titre :
    * Description :
    * Copyright : Copyright (c) 2002
    * Soci�t� :
    * @author
    * @version 1.0
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class Alert
    static CommPortIdentifier portId;
    static Enumeration portList;
    PrintStream out=null;
    BufferedReader in=null;
    SerialPort serialPort;
    int n=0;
    byte[] data=new byte[100];
    public static void main(String[] args)
    System.out.println("Main running OK");
    Alert app=new Alert();
    } // main
    public Alert()
    System.out.println("AlertClass OK");
    portList=CommPortIdentifier.getPortIdentifiers();
    if (portList==null)
    System.out.println("No Port Found");
    return;
    }// if
    System.out.println(portList.hasMoreElements());
    System.out.println("Port List Avalaible:");
    while (portList.hasMoreElements())
    portId=(CommPortIdentifier)portList.nextElement();
    System.out.println("Owner : "+portId.getCurrentOwner()
    +"("+portId.isCurrentlyOwned()+")");
    System.out.println("Port : "+portId.getName());
    if (portId.getPortType()
    ==CommPortIdentifier.PORT_SERIAL)
    if (portId.getName().equals("COM1"))
    System.out.println("Opening Serial Port "+portId.getName());
    try
    serialPort=(SerialPort)
    portId.open("Yeeehaaa!!!",2000);
    out=new PrintStream
    (serialPort.getOutputStream());
    in=new BufferedReader(new InputStreamReader
    (serialPort.getInputStream()));
    serialPort.notifyOnDataAvailable(true);
    serialPort.setSerialPortParams
    (57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    out.println("ATZ");
    in=new BufferedReader(new InputStreamReader
    (serialPort.getInputStream()));
    System.out.println("Received :"+in.readLine());
    System.out.println("Received :"+in.readLine());
    String jgf=in.readLine();
    System.out.println("Real one"+jgf);
    }// try
    catch (Exception e)
    System.err.println
    ("Alert : "+e);
    }// catch
    }// if
    }// if
    } // while
    }// Alert
    This is the results
    C:\PROGRAM FILES\JDK1.3\bin\javaw -classpath "C:\Program Files\demo2\bak;C:\Program Files\jdk1.3\jre\lib\ext\comm.jar;C:\PROGRAM FILES\JDK1.3\demo\jfc\Java2D\Java2Demo.jar;C:\PROGRAM FILES\JDK1.3\jre\lib\i18n.jar;C:\PROGRAM FILES\JDK1.3\jre\lib\jaws.jar;C:\PROGRAM FILES\JDK1.3\jre\lib\rt.jar;C:\PROGRAM FILES\JDK1.3\jre\lib\sunrsasign.jar;C:\PROGRAM FILES\JDK1.3\lib\dt.jar;C:\PROGRAM FILES\JDK1.3\lib\tools.jar" demo2.Alert
    Main running OK
    AlertClass OK
    false
    Port List Avalaible:
    No port List, nothing I've been here for 3 days... Badly need help!! please...

    Hi, (here edo)
    its� right now my prog. works good.
    But what i have done? By following the instruction there was no success:
    win32comm.dll put in <jdk>\bin\
    javax.comm.properties put in <jdk>\jre\lib
    comm.jar put in <jdk>\jre\lib\ext
    I put the javax.comm.properties and comm.jar file into the folder where MyApplication is in it.
    than:(change in the folder where your Application is)
    -javac -classpath .;<jdk>\jre\lib\ext\comm.jar MyApplication.java
    -java -cp .;comm.jar MyApplication
    and TATA it works :)
    First i think i have to tell my conditions:
    WinNT 4.0 Sp 6
    Jdk 1.3.0
    Comm Package 2.0
    (I think what also important is by this problem)
    WinNT is on device C:\
    JDK is on device D:\Programm\jdk...
    and my prog. is on device e:\...
    (i think the source of all my problems was this wide spreed stuff)
    maybe there are some links in the classes of the javax.comm where do not match,
    but i don't know (can somebody explain this?)
    by the way can somebody tell me
    what is the "java -cp ..." -cp option for?
    And it is possible to read from the ParallelPort?
    When i try it, this is the result:
    E:\...\TEST>java -cp .;comm.jar KommParallel
    java.io.IOException: Unsupported operation. Output only mode
    at com.sun.comm.Win32ParallelPort.getInputStream(Win32ParallelPort.java:102)
    at KommParallel.main(KommParallel.java:19)
    Thnax by edo

  • Does the Communications API work with Studio 4

    I just installed Studio 4 along with the JDK. The Java version that I am running now is:
    java version "1.4.1_02"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
    Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
    Running on MS XP.
    The Communications API seemed to work just fine on JDK 1.3 with Forte 1.0.
    I installed the Comm API as instructed and set my ClassPath:
    CLASSPATH=D:\PROGRA~1\s1studio_jdk\j2sdk1.4.1_02\lib\comm.jar;D:\MyProjects\java\GarxFace
    A call to:
    Enumeration portList;
    portList = CommPortIdentifier.getPortIdentifiers();
    does not yield any ports at all.
    Stranger yet, if I use the auto complete feature in the editor. For example if I type: m_PortID. then no members of PortID show up.
    But the code compiles just fine.
    Any idea what is going on?

    First I found the reason that the auto complete was not working. I had to mount the comm.jar file (you did not have to do this in Forte 1,0, just set the classpath). I thought that I had done that. That is the problem when you work late. ;)
    Here is a eexcerpt that I found on a search in another post:
    Copy javax.comm.properties to your <JDK>\lib directory.
    C:\>copy c:\commapi\javax.comm.properties c:\jdk1.1.6\lib
    The javax.comm.properties file must be installed. If it is not, no ports will be found by the system.
    Notice it says that "javax.comm.properties file must be installed"
    javax.comm.properties is indeed installed in my JDK lib subrirectory, but it is almost like it is not being found.

Maybe you are looking for