-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for pyserial exclusive access mode. #1961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to be platform independent, so "posix only" is not acceptable for a parameter. Secondly there are no need for a parameter, since it is never allowed to share the serial port...if there is a need for code it should be built in fixed at the lowest level possible.
Furthermore I am not sure I understand the problem, currently 2 app cannot open the same device (in this case serial port), this is handled at OS level at least on my machine.
janiversen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are not setting the exclusive parameter for the sync client.
I think other platforms may behave more like
What's actually enforcing that?
Isn't that what this is doing? It's passing the exclusive param to pyserial which implements this exclusivity using low level os features.
What platform are you using? I've seen issues with pyserial that this should reliably prevent, such as multiple applications instances trying to use the same serial device at the same time.
Oh, where is that one? It appears to me that there is sync client code I added it to. |
|
Normally the OS prevent a device from being opened multiple times in parallel, depending on the parameters in your open call. You added the exclusive to the pyserial call in the async mode, but you did not add it in the sync mode. I do not understand your question "Oh, where is that one?", Pyserial is sync, which is why we have a special async addon in transport. I have no problem accepting exclusive=true in the pyserial call and leave it to pyserial to handle it on different platforms....but I do not see the need to make it a parameter in pymodbus, since we always demand exclusive access. I work on different platforms, currently mostly on macos and raspian. |
So that's from my understanding what passing exclusive to pyserial essentially tells the OS to enforce, by setting the exclusive lock here by calling
Ok, I'll go through the code again and try to find where to add it for sync mode.
I'm confused, how would we pass the param from pymodbus to pyserial without making it also a pymodbus param? I also don't see how we currently demand exclusive access since we don't currently set the exclusive param in pyserial.
Hmm, so I recall seeing issues on linux based platforms where if you don't set the exclusive param in pyserial you can get multiple simultaneous connections to the same serial port. Maybe macos enforces exclusive access without a |
ddcddd5 to
4efd113
Compare
| stopbits=self.comm_params.stopbits, | ||
| baudrate=self.comm_params.baudrate, | ||
| parity=self.comm_params.parity, | ||
| exclusive=self.comm_params.exclusive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the part of the sync client where I'm already passing the exclusive param to pyserial? Or are you referring to something different?
Handy for preventing two applications from trying to access the same port simultaneously.
4efd113 to
d24163d
Compare
|
I checked again and it looks like setting |
Handy for preventing two applications from trying to access the same port simultaneously.