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
|
* @file serial.h
|
||||||
* @author William Woodall <wjwwood@gmail.com>
|
* @author William Woodall <wjwwood@gmail.com>
|
||||||
|
* @author John Harrison <ash.gti@gmail.com>
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
*
|
||||||
* @section LICENSE
|
* @section LICENSE
|
||||||
@ -143,6 +144,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
void open();
|
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. */
|
/** Closes the serial port and terminates threads. */
|
||||||
void close();
|
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() {
|
void Serial::close() {
|
||||||
// Cancel the current timeout timer and async reads
|
// Cancel the current timeout timer and async reads
|
||||||
this->timeout_timer.cancel();
|
this->timeout_timer.cancel();
|
||||||
|
|||||||
@ -13,6 +13,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
serial::Serial serial(port, 115200, 250);
|
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;
|
int count = 0;
|
||||||
while (count >= 0) {
|
while (count >= 0) {
|
||||||
int bytes_wrote = serial.write("Testing.");
|
int bytes_wrote = serial.write("Testing.");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user