mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Added isOpen, and credited John Harrison as an author as well.
This commit is contained in:
parent
50581b4c96
commit
4eb3e51aa2
@ -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();
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user