Fazecast/jSerialComm

Attempting to implement an event handler for disconnects

brianmichalk1 opened this issue · 2 comments

My objective is to implement a listener based on USB connects and disconnects and handle the JSerialport correctly.
one one side, I can list all of the USB devices, but I can't figure out how to map any of them to the Serial port device.
In the serial port side, I can see:

Object o1 = serialPort.getDescriptivePortName();
Object o2 = serialPort.getPortDescription();
String portLocation = serialPort.getPortLocation();
Object o4 = serialPort.getSystemPortName();
Object o5 = serialPort.getSystemPortPath();
Object o6 = serialPort.getSerialNumber();
Object o7 = serialPort.getProductID();
Object o8 = serialPort.getVendorID();

It looks like getPortLocation is almost what I need, matching up with LibUsb's getBusNumber and getPortNumber. Is this true across multiple devices, like two serial ports connected at the same time? I'm assuming if I replugged into a different USB socket, this number would change, but otherwise is always tied to the physical port?

Alternatively, is there a way to get the native USB device from the SerialPort?

Yes, your analysis is correct. Using getPortLocation() would be the function call you should use to ensure that a USB device that is plugged into your system comes back with the same result across reboots. Aside from the PID/VID/Serial Number, there is no other way to obtain USB-specific identifying information.

As to your second question, there is no way to obtain a native USB handle from the serial port object, because there isn't one. This library is serial-port specific, so any USB functionality comes from the OS and/or a driver making that USB device appear like a native serial port, and that's what we use to implement the native functionality in this library.

Closing as "nothing to fix."