Skip to content
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

sp_close(): disable exclusive mode to allow re-opening the port later #5

Closed
wants to merge 1 commit into from

Conversation

jpnurmi
Copy link
Contributor

@jpnurmi jpnurmi commented Aug 9, 2020

No description provided.

@martinling
Copy link
Contributor

I'm not sure why you're finding you need this. After close() is called on the file descriptor being used to access the port, there should be no problem with calling open() on the same device node.

I'm not familar with Dart, your bindings for it, or what your users might be doing with them - is it possible the user having that issue has a race where another open() is happening before the first close() is complete?

Or is it possible to demonstrate the EBUSY with a simple C program? I'd be surprised if so because I'm sure we have programs out there that re-open the same port without this patch.

@jpnurmi
Copy link
Contributor Author

jpnurmi commented Sep 26, 2020

Hmm, it's fairly possible that this occurs specifically with socat, because that's what I'm using for emulation when developing anything related to serial ports.

@mdjurfeldt
Copy link

mdjurfeldt commented Jan 16, 2023

[Cross-posting this comment to PR #4 and #5.]

Hi @martinling, @jpnurmi and @luizribeiro,

I have a setup with a Riden RD6012P. I'm using the esp-link firmware in my Wifi module which makes it possible to run modbus over telnet. Thus, I do:

sudo socat pty,link=/dev/virtualcom0,raw,group-late=dialout,mode=660 tcp:192.168.nnn.nnn:23

PRs #4 and #5 together make sigrok work with the socat pty and makes it possible for me to use the PSU over Wifi.

(And, yes, it is funny that PR #5 is needed. If PR #5 is not applied, there is an "sr: serial-libsp: Error opening port (16): Device or resource busy." error occurring after the first call to sp_open. This occurs also if the pty has been opened before in the same session with a different (erroneous) specified device. It is as if the socat opened pty is dependent on the port being in non-exclusive mode to close (fully).)

It would make life easier if you applied these two PRs. And I don't think it is strange at all to make it possible for libserialport to handle a "forwarded" serial port in this way.

@abraxa
Copy link
Member

abraxa commented Aug 30, 2024

While I agree with Martin's argument that the current implementation isn't showing problems elsewhere as far as we know, I also don't see the problem with releasing the exclusive mode right before closing the port.

Hence, merged as https://sigrok.org/gitaction?p=libserialport.git;a=commit;h=32b94b12cac47933b0e06d317eaa37a539d207c1, thank you!

@abraxa abraxa closed this Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants