Skip to content

Conversation

@the-moog
Copy link

Ref #58
close() method added for unix and windows.
As Rust has no std::fs close() method and using the underlying OS calls would be unsafe, instead implemented by simply re-opening the 'port' as /dev/null on unix and \.\NUL on Windows.
It would be useful if subsequent reads or writes then failed with some error, but that was not included (yet).

@de-vri-es
Copy link
Owner

Hello! Thank you for the PR! I think a close() method can be nice, but should consume self. Calling an unsafe function is fine in this case. Since we're using OS API's, almost everything is unsafe anyway.

A SerialPort object represents an open and usable serial port. If you wish to have a possibly closed serial port, you should use an Option<SerialPort>.

@the-moog
Copy link
Author

Test passing (after a couple attempts) I'm new to Rust.....

@the-moog
Copy link
Author

Hello! Thank you for the PR! I think a close() method can be nice, but should consume self. Calling an unsafe function is fine in this case. Since we're using OS API's, almost everything is unsafe anyway.

A SerialPort object represents an open and usable serial port. If you wish to have a possibly closed serial port, you should use an Option<SerialPort>.

Is there an example of that?
My issue is that it's a GUI app, with a message loop. So initially (at startup) the serial port is closed ( as it has no name) but when opened I can't then close it, meaning a subsequent open or an open in another app fails. As both Windows and especially Linux struggle to ensure the device gets the same port every time it's plugged in I need to probe for the embedded hardware, leaving at least one port open even if unused. A problem made more difficult by the fact that FTDI never got their serial numbers under control, so multiple FTDI devices are impossible to tell apart without asking what's on the end of it.

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.

2 participants