Skip to content

Commit 208e74a

Browse files
author
Dwatkins
committed
added flush function for serial port
1 parent 90c3176 commit 208e74a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/serial/include/serial/SerialPort.h

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class SerialPort {
2525
int sendArray(unsigned char *buffer, int len);
2626
int sendString(std::string msg);
2727
int getArray (unsigned char *buffer, int len);
28+
29+
void flushPort(boost::asio::serial_port& serial_port, flush_type what);
30+
31+
enum flush_type
32+
{
33+
flush_receive = TCIFLUSH,
34+
flush_send = TCIOFLUSH,
35+
flush_both = TCIOFLUSH
36+
};
2837
};
2938

3039

src/serial/src/serial/SerialPort.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "serial/SerialPort.h"
55

66

7+
78
SerialPort::SerialPort() {
89
port = new boost::asio::serial_port(io);
910
}
@@ -38,4 +39,10 @@ int SerialPort::getArray (unsigned char *buffer, int len){
3839
return i;
3940
}
4041

42+
void SerialPort::flushPort(boost::asio::serial_port& serial_port, flush_type what)
43+
{
44+
::tcflush(serial_port.lowest_layer().native_handle(), what);
45+
}
46+
47+
4148

0 commit comments

Comments
 (0)