hparra / ruby-serialport

ruby-serialport is a Ruby library that provides a class for using RS-232 serial ports
http://rubygems.org/gems/serialport
GNU General Public License v2.0
246 stars 58 forks source link

Support for POSIX tcflush(3) #47

Closed MaG21 closed 10 years ago

MaG21 commented 11 years ago

ruby-serialport lacks the capability to discard data transmitted and/or received through the serial effectively, function that is already provided by the tcflush(3) function from termios on POSIX compliant system.

This pull add support to flush the data received and/or transmitted through the following method.

  1. SerialPort#flush_input()
  2. SerialPort#flush_output()
  3. SerialPort#flush # both input and output.
hparra commented 11 years ago

Sorry for delay. And thank you for this major addition.

If possible, I would like to create a release that also supports this flushing on Windows, but I'm not sure if that is possible. Seems FlushFileBuffer handles this a la drain, but it may be for output only. Are you familiar with this at all? I just asked around.

Will probably merge this to a new feature branch in the meantime.

hparra commented 11 years ago

PR merged at https://github.com/hparra/ruby-serialport/tree/feature-io-flush

MaG21 commented 11 years ago

Opss this PR was meant for the feature-io-flush branch. Sorry about that :\

Support for SerialPort#flush_input() and SerialPort#flush_output() on Windows added. Method SerialPort#flush() was removed due to a possible conflict with the IO#flush method, to produce the same behaviour a combination of flush_input() and flush_output() should be used instead.

The PurgeComm function from Winbase.h was used to produce the same behaviour the POSIX tcflush(3) provides on non-windows systems.

hparra commented 10 years ago

Released as v1.3.0. Thank you.