Fazecast / jSerialComm

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

Linux Suse -11 Issue :Multiple java application getting connected to the same port(Serial/USB) #195

Closed Vishal0802 closed 5 years ago

Vishal0802 commented 5 years ago

Linux Suse -11 Issue :Port is not getting locked in the first instance(Java Application) which is allowing another instance(Another java application) to connect with the same port of first instance. Example : ttys0 (Serial port) is connected with first Java application.Now if I start another java application on the same ttys0 port then it is able to connect which is not correct behavior. Ideally it should lock the port when first java application is connected and running. This scenario is working properly in windows.

Please provide the solution to handle this scenario. Thanks in advance.

hedgecrw commented 5 years ago

Thanks for the request. So this functionality is already a part of the jSerialComm library. As soon as a port is opened, the TIOCEXCL flag is set on the port which disables any other processes from opening the port while the current process has it opened. The caveat to this, however, is that a "root" user (or a root-like user with CAP_SYS_ADMIN permissions) will always be able to open the port, no matter what flags are set. This is just a Linux implementation detail, not mine.

Since you are experiencing this problem, I assume you are running multiple processes all from root. Is there the possibility of not using a root user to run your applications? If so, that would be preferable to trying to implement a hacky file-based locking mechanism, if only because it will most likely create additional runtime issues down the line if/when somebody has an application that crashes and the custom locks aren't properly released. Let me know. Thanks!

hedgecrw commented 5 years ago

As a follow-up, I went ahead and implemented an additional method of locking the device using flock() since that should still get cleaned up automatically if a process crashes unexpectedly. Please test the following and see if it works for you:

https://www.dropbox.com/s/ffpxcr0qqphl32k/jSerialComm-2.4.2.jar?dl=0

Vishal0802 commented 5 years ago

Hi Will, Thank you so much for your prompt response and the way you guided and then implemented to resolve the same. 1.Yes you are right, we are running through "root" user(As we have this requirement to run project from "root" as well as from any other user account in suse ) in Suse 11 thats why we were getting this issue.

  1. jSerialComm-2.4.2.jar : It is working perfectly and resolved my problem even with "root" user. Currently I am doing testing with this build and if any thing comes will let you know.

Just a ask and request ,As it looks fine as of now,will you include this feature into your main build. Thanks again the way you worked,It is unexceptionally great.

Regards, Vishal Gupta

hedgecrw commented 5 years ago

No problem. This will be included in version 2.4.2 which will be released publicly today. Thanks!