Closed wenhuancui closed 2 years ago
Please change your openPort code to the following and report back what gets printed:
if (!yourPort.openPort()) {
System.out.println("Failed to open port with error code " + yourPort.getLastErrorCode() + " at Line " + yourPort.getLastErrorLocation());
}
@hedgecrw
Thank you for the hint.
Sadly, it provides little clue (V2.8.1, Ubuntu 20.04 X86_64, port is not occupied and can be opened by cutecom):
Failed to open port with error code 0 at Line -1
strange: openPort returns false and error code is 0?
I am seeing this error as well, and I also get "error code 0 at Line -1". Mine is on Raspberry Pi running buster though. The same code works fine on Windows.
I can also confirm reverting to 2.7.0 gets it working again on RPi, so it seems to be related to an update after that version.
Ahh yes, I see the problem with the error code not printing out properly. It relies on a valid port descriptor being returned from native code which obviously doesn't happen when openPort() fails. I've made a fix so that we can retrieve the error code regardless of the port's status. Could either/both of you please try the following version and report back the error code and line number:
I too have been using this on Raspberry pi and had to revert to 2.7.0. Tried both buster and bullseye. I added your library from dropbox and I got
"Failed to open port with error code 25 at Line 477"
I would like to note with my experience, 2.8.0/2.8.1 can open ttyUSB0 but not ttyAMA2. Also thank you so much for this library.
Great, that's very helpful! It looks like for some devices, the ioctls for RS-485 mode are completely unimplemented which is causing the error (at least in the case of @mkarier). I have added an additional check to only throw an error if the user is explicitly requesting RS-485 mode and the device driver doesn't implement it.
Please test with the following library version and see if your problem is resolved:
https://www.dropbox.com/t/TKIbuNhB0K03KFPO
It would be great if both @wenhuancui and @joshellissh could also test this and see if it fixes their problem as well. If so, I'll make a new release.
@hedgecrw Thank you! It is working for me as expected now.
@hedgecrw Tested. It's working now. Mine port is ttyS0. Thanks very much!
I am having the same problem but the second dropbox link is dead so I can't test it.
link fixed now, not sure why. but it works for me as well
Great! Everyone that has tested this fix says it has resolved their issue; therefore, I'm closing the issue as resolved with the release of jSerialComm v2.8.2 today.
the problem is gone after reverting jSerialComm version to 2.7.0.