you're close to get connected ^^
when you scan your system for com-ports, just print them out!
while (e.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) e.nextElement();
if(serialPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println(serialPortId.getName());//print the serial port name
}
}
your output should be something like
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
/dev/ttyS1
/dev/ttyS0
now that you know the name of the serial port you can use this information to open that port! Let's say your GPS is connected to serial port ttyS1...
go again into your code and adapt it like this:
enumComm = CommPortIdentifier.getPortIdentifiers();
while(enumComm.hasMoreElements()) {
serialPortId = (CommPortIdentifier) enumComm.nextElement();
if (serialPortId.getName().equalsIgnoreCase("/dev/ttyS1")) { //HERE you get your serial port
try {
SerialPort sp = (SerialPort) id.open("SerialExample", 30);
//continue with your code here
} catch (PortInUseException e) {
System.out.println("port in use");
}
}
}
this only works because your usb-device creates a virtual serial port!