I use the following code to identify the comports. In my system there are three ports but it is showing false in ports.hasMoreElements() method. I also added comm.jar in the library and i am using windows xp (service pack 3). Kindly look into the code and help me.
import java.util.*;
import javax.comm.*;
public class Main
{
public static void main(String[] args)
{
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
System.out.println(ports.hasMoreElements());
while(ports.hasMoreElements())
{
CommPortIdentifier cpi =
(CommPortIdentifier)ports.nextElement();
System.out.println("Port " + cpi.getName());
}
}
}
Thanks in advance..
There are some tricks involved in getting the Java Communications API to correctly interact with the Windows system. Among the items that you download from Sun are three very important files:
For the JVM to recognize the serial ports, proper placement of these files is important.
Use the following installation methods to be effective:
comm.jar should be placed in:
win32com.dll should be placed in:
javax.comm.properties should be placed in: