Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.34k stars 287 forks source link

openPort() failed #394

Closed elicec closed 2 years ago

elicec commented 2 years ago

openPort failed OS Windows 10 21H2

How to get detailed error information?

elicec commented 2 years ago

image

I try all port,and any port can not opened

hedgecrw commented 2 years ago

To retrieve the native error code and source code location, you can use the functions getLastErrorCode() and getLastErrorLocation(), and either post the results back here or look up the location of the error in source code under src/main/c/Windows/SerialPort_Windows.c to see which line causes the open call to fail.

But in this case, I can almost guarantee that there is simply a problem with whatever String you are using to try to call SerialPort.getCommPort(...). It looks like you're just passing whatever description is present in some sort of dropdown box, which is incorrect. The ideal way to retrieve the SerialPort object would be to store the array of objects resulting from SerialPort.getCommPorts() and use the index of whatever is selected in your choice box to retrieve the corresponding SerialPort object from your stored array. If you don't want to store the array of actual SerialPort objects, you will need to translate from whatever String selection you are trying to make to the correct raw system port name (like 'COM1' etc.) for use in getCommPort(...).

elicec commented 2 years ago

That's great. You helped me a lot.