Fazecast / jSerialComm

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

Failed to open the port #506

Closed mjchow closed 1 year ago

mjchow commented 1 year ago

Hello, I am using version 2.10.2 of JSerialComm. Sometimes, when I call openPort(), it fails. The value of getLastErrorCode is 2 and getLastErrorLocation is 710. However, if I restart my program, openPort() succeeds and I receive the correct data. But if I don't restart my program and try openPort() multiple times, it always fails. My platform is Windows 10. Thank you for your response.

NorbertSandor commented 1 year ago

Can you try it with an older library version, like 2.9.x?

mjchow commented 1 year ago

Can you try it with an older library version, like 2.9.x?

Is it the reason why I am using a higher version?

NorbertSandor commented 1 year ago

Is it the reason why I am using a higher version?

I don't know :)

You can try an earlier version (like 2.9.3) if you don't use any new APIs introduced in the 2.10.x versions. I recommend it because there was lots of changes in the 2.10.x versions, and it usually helps to figure out what the problem may be if an older version works. But it is just an idea :)

mjchow commented 1 year ago

Is it the reason why I am using a higher version?

I don't know :)

You can try an earlier version (like 2.9.3) if you don't use any new APIs introduced in the 2.10.x versions. I recommend it because there was lots of changes in the 2.10.x versions, and it usually helps to figure out what the problem may be if an older version works. But it is just an idea :)

This problem is difficult to reproduce. I will try to reproduce this issue using version 2.9.x.

hedgecrw commented 1 year ago

Also, the error code and location you posted indicate that you are trying to open a port that was previously opened in your own code and never properly closed. Are you certain that all of your code paths properly call closePort() before trying to open the port again?

mjchow commented 1 year ago

Also, the error code and location you posted indicate that you are trying to open a port that was previously opened in your own code and never properly closed. Are you certain that all of your code paths properly call closePort() before trying to open the port again?

Thank you for your reply, I will double-check my code.