From 208e74a4a6b00335a5909f487f99b301ad46a774 Mon Sep 17 00:00:00 2001 From: Dwatkins Date: Fri, 18 Aug 2017 10:33:03 -0500 Subject: [PATCH] added flush function for serial port --- src/serial/include/serial/SerialPort.h | 9 +++++++++ src/serial/src/serial/SerialPort.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/serial/include/serial/SerialPort.h b/src/serial/include/serial/SerialPort.h index 663f5aa..e9f42ed 100644 --- a/src/serial/include/serial/SerialPort.h +++ b/src/serial/include/serial/SerialPort.h @@ -25,6 +25,15 @@ class SerialPort { int sendArray(unsigned char *buffer, int len); int sendString(std::string msg); int getArray (unsigned char *buffer, int len); + + void flushPort(boost::asio::serial_port& serial_port, flush_type what); + + enum flush_type + { + flush_receive = TCIFLUSH, + flush_send = TCIOFLUSH, + flush_both = TCIOFLUSH + }; }; diff --git a/src/serial/src/serial/SerialPort.cpp b/src/serial/src/serial/SerialPort.cpp index 12db12f..5480cc4 100644 --- a/src/serial/src/serial/SerialPort.cpp +++ b/src/serial/src/serial/SerialPort.cpp @@ -4,6 +4,7 @@ #include "serial/SerialPort.h" + SerialPort::SerialPort() { port = new boost::asio::serial_port(io); } @@ -38,4 +39,10 @@ int SerialPort::getArray (unsigned char *buffer, int len){ return i; } +void SerialPort::flushPort(boost::asio::serial_port& serial_port, flush_type what) +{ + ::tcflush(serial_port.lowest_layer().native_handle(), what); +} + +