Skip to content

Add a purge() method#59

Draft
danieldulaney wants to merge 2 commits intodcuddeback:masterfrom
danieldulaney:purge
Draft

Add a purge() method#59
danieldulaney wants to merge 2 commits intodcuddeback:masterfrom
danieldulaney:purge

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

Comments