From 4eb3e51aa25b25968ad3f7841a7f6095627ffb99 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Thu, 24 Mar 2011 11:14:13 -0500 Subject: [PATCH] Added isOpen, and credited John Harrison as an author as well. --- include/serial.h | 7 +++++++ src/serial.cpp | 6 ++++++ src/test_serial.cpp | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/include/serial.h b/include/serial.h index 7946ebe..537e58e 100644 --- a/include/serial.h +++ b/include/serial.h @@ -1,6 +1,7 @@ /** * @file serial.h * @author William Woodall + * @author John Harrison * @version 0.1 * * @section LICENSE @@ -143,6 +144,12 @@ public: */ void open(); + /** Gets the status of the serial port. + * + * @return A boolean value that represents whether or not the serial port is open. + */ + const bool isOpen(); + /** Closes the serial port and terminates threads. */ void close(); diff --git a/src/serial.cpp b/src/serial.cpp index cc21e85..19abbb8 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -182,6 +182,12 @@ void Serial::open() { } } +const bool Serial::isOpen() { + if(this->serial_port != NULL) + return this->serial_port->is_open(); + return false; +} + void Serial::close() { // Cancel the current timeout timer and async reads this->timeout_timer.cancel(); diff --git a/src/test_serial.cpp b/src/test_serial.cpp index 568707b..9048b0d 100644 --- a/src/test_serial.cpp +++ b/src/test_serial.cpp @@ -13,6 +13,12 @@ int main(int argc, char **argv) serial::Serial serial(port, 115200, 250); + std::cout << "Is the serial port open?"; + if(serial.isOpen()) + std::cout << " Yes." << std::endl; + else + std::cout << " No." << std::endl; + int count = 0; while (count >= 0) { int bytes_wrote = serial.write("Testing.");