This is simple code to enumerate your serial port names.
public static String[] listSerialPorts() {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
ArrayList portList = new ArrayList();
String portArray[] = null;
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
portList.add(port.getName());
}
}
portArray = (String[]) portList.toArray(new String[0]);
return portArray;
}
If the serial ports are not detected, use this option as execution parameter: -Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0:/dev/ttyUSB0:/dev/<your port name>
Is this applicable to J2ME?
Comment by kawaii — February 22, 2011 @ 6:57 pm