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 a purge() method #59

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

danieldulaney
Copy link

@danieldulaney danieldulaney commented Nov 2, 2019

Both Windows and Unix have functions (PurgeComm and tcflush) that clear out the underlying send and receive buffers without sending the data. This can be useful for call-and-response serial connections, where it makes sense to discard any existing data as invalid. There is a user demand for this addition (#56). This PR proposes a purge API and provides a Windows implementation.

Both PurgeComm and tcflush are single functions that accept a parameter indicating whether the input/receive queue, the output/send queue, or both queues should be flushed. This mimics that arrangement, adding a purge(&self, queue: Queue) to SerialPort and SerialDevice. The Queue enum allows for input, output, or both.

On Windows, purge is implemented using a single call to PurgeComm. The Unix implementation should be similar, but I don't have a machine nearby to test with, so this is submitted as a draft PR for now with no Unix implementation.

Daniel Dulaney added 2 commits November 2, 2019 01:31
Also added to SerialDevice and the default implementation. A queue
selection enum is included to easily signal which queue should be
purged.
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.

1 participant