diff --git a/include/serial.h b/include/serial.h index 7946ebef68ec93fb33899995c729f9468a191b3d..537e58eb5d8bb15103c872ac8553b9b6e9494399 100644 --- a/include/serial.h +++ b/include/serial.h @@ -1,6 +1,7 @@ /** * @file serial.h * @author William Woodall <wjwwood@gmail.com> + * @author John Harrison <ash.gti@gmail.com> * @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 cc21e8578b9507b2ee7f32f3eaf8146256a4321a..19abbb8fc62cc171501325e39a9c96aff4fe86df 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 568707b686db82f333ff73d871f243d98fafdbb9..9048b0d82e2a7d2b7b1fb1fb22ec7a61cce0e55a 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.");