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

Removal of opened port not detected properly. #238

Open
randohinn opened this issue Feb 23, 2021 · 2 comments
Open

Removal of opened port not detected properly. #238

randohinn opened this issue Feb 23, 2021 · 2 comments
Labels

Comments

@randohinn
Copy link

See https://github.com/Teaduskeskus-AHHAA/oskar_driver/blob/cf0a9f6b7cb7d4382fb9ac8d07a1e08d070df620/src/board_comms.cpp for how I'm using this serial library in ros/ubuntu18.04

I've developed a bit of a problem.. When transmitting, if I remove my serial port.. it will thrown a exception, in which serial_.isOpen will still be true. When I try to manually close, it will complain about calling terminate after a portnotopened exception. As you may see, I have a interval configure to reconnect, since the serial instance will not detect a proper disconnect, that reconnection attempt will not run. Are there any ways to make serial_isOpen properly detect removal of the serial device?

@wjwwood
Copy link
Owner

wjwwood commented Jun 10, 2021

The short answer is "I'm not sure". It has been long enough that I don't know what the expected behavior should be.

I know that in the past, Linux had some issues with hardware disconnects, e.g. read would report ready but the device was actually not connected:

serial/src/impl/unix.cc

Lines 587 to 591 in 33e5a31

// Disconnected devices, at least on Linux, show the
// behavior that they are always ready to read immediately
// but reading returns nothing.
throw SerialException ("device reports readiness to read but "
"returned no data (device disconnected?)");

But I don't know if this is related to your use case. Perhaps you can just catch the exception when you try to close it and keep going? But I'm honestly not sure.

@zacgibson21
Copy link

I am running into the same issue on Windows where once a port is disconnected "isOpen" still returns true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants