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

Missed support for tcflush() #56

Open
matwey opened this issue Feb 23, 2019 · 2 comments
Open

Missed support for tcflush() #56

matwey opened this issue Feb 23, 2019 · 2 comments

Comments

@matwey
Copy link

matwey commented Feb 23, 2019

There is a call tcflush() in termios Unix interface that is quite useful when used in TCIFLUSH queue selector. It allows us to efficiently clear OS input buffer from possible garbage data appeared during RS232 line idle. it is quite common when the peripheral RS232 device works in transaction mode, i.e. it is listening for host requests and responding on each request, not initiating transfer on its own. In this case calling tcflush() before writing the request at host side is a good practice.

@danieldulaney
Copy link

For what it's worth, Windows has an analogous PurgeComm method.

I'd be happy to take on the Windows implementation if there was consensus on the broader API.

@danieldulaney
Copy link

After taking a look at both tcflush and PurgeComm, it looks like it's plausible to encapsulate them both inside a SerialPort::purge(&mut self, queue: Queue) method. Queue could be an enum that selects between the input queue, the output queue, or both:

enum Queue {
    Input,
    Output,
    Both,
}

Then it gets implemented with a single call to tcflush or PurgeComm as appropriate.

Does this look like a reasonable API? I would also find this useful for one of my projects.

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

No branches or pull requests

2 participants