Thread: Serial Port
View Single Post
  #5 (permalink)  
Old 11-16-2007, 11:50 AM
hobbyist hobbyist is offline
Member
 
Join Date: Nov 2007
Posts: 5
hobbyist is on a distinguished road
I also have an issue with serial comm API.
I am trying to write a JavaSE application using Swing to access the virtual COM port created when connecting a Modem aware device to the USB.
I can see data coming across via Hyperterminal and I want to write a hyperterminal type application to react to and filter messaging.
I have tried using the Comm API and followed in the API instructions to the letter.
I am using the following code in my JavaSE app:

{
...
private void initCommPorts() {
CommPortIdentifier portId;
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
if (portList == null) {
System.out.println("portList is null");
}
else {
System.out.println(portList.toString());
}

String comPort = "";
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
System.out.print("Port found");
comPort = portId.getName();
System.out.println("Found port: " + comPort);
// Add COM port to visual object selection list
comChoice.addItem(comPort);
}

}
...
}

The issue is that this code never finds the COM port. The Enumeration is always empty.

Am I using the right API here. Can the Comm API be used to create a connection to the virtual COM ports in Windows XP?

Thanks guys - and sorry for my ignorance on this matter!
Reply With Quote