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

Add operators for reading and writing binary data from a serial port #959

Merged
merged 13 commits into from
Jul 4, 2023

Conversation

glopesdev
Copy link
Member

@glopesdev glopesdev commented Jul 3, 2022

This PR introduces two new operators SerialRead and SerialWrite which can be used to interface with a serial port using low-level binary representations. The main difference from SerialStringRead is that no message terminator is assumed.

Instead, the maximum number of bytes to read is specified, and the sequence will either terminate after this number of bytes is read, or the serial port read timeout elapses. If a source sequence is provided to SerialRead, the operator will try to read a byte buffer for each incoming notification.

Conversely, the SerialWrite operator will write each of the binary buffers in the source sequence to the serial port. An overload supporting ArraySegment is provided.

In preparation for a larger reorganization of the IO package, this PR also refactors the core serial port operators into a new namespace Bonsai.IO.Ports mirroring the .NET namespace System.IO.Ports. The legacy character based operators SerialStringRead and SerialStringWrite are also renamed in this new namespace to SerialReadLine and SerialWriteLine, respectively.

Note that the new SerialWriteLine no longer guarantees exclusive access to the port. In general the language is now much better equipped with synchronization primitives using subjects that in general should be used instead of scattering low-level hardware details inside the workflow.

A compatibility layer is provided to ensure all previous workflows can operate as normal (including preserving exclusive access in SerialStringWrite). Deprecation notices have been placed on all legacy types.

Fixes #952

@glopesdev glopesdev added the feature New planned feature label Jul 3, 2022
@glopesdev glopesdev added this to the 2.7.0 milestone Jul 3, 2022
@glopesdev

This comment was marked as resolved.

@glopesdev
Copy link
Member Author

The PR has been rewritten to include a source operator that reads a fixed number of bytes from the serial port. The operator can be chained in a sequence or used standalone.

@glopesdev glopesdev added this to the 2.8 milestone Jul 4, 2023
@glopesdev glopesdev changed the title Add operator for writing both binary and text data Add operators for reading and writing binary data from a serial port Jul 4, 2023
@glopesdev glopesdev merged commit b770d2d into bonsai-rx:main Jul 4, 2023
@glopesdev glopesdev deleted the issue-952 branch July 4, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New planned feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for streaming byte buffers into a SerialPort
1 participant