Serial communications API. More...
#include <Robots/LoBot/io/LoSerial.H>
Public Member Functions | |
Serial (const ModelManager &, const std::string &device, int baud_rate) | |
Initialization. | |
bool | ready () |
Check if the serial port has data available for reading. | |
int | read (char buf[], int n) |
void | write (char buf[], int n) |
Send data to the serial port. | |
void | read_full (char buf[], int n) |
void | eat (int n) |
Read and discard the specified number of bytes. | |
~Serial () | |
Clean-up. |
Serial communications API.
The robot's motors are controlled by a motor driver that is in turn controlled by a Propeller-based I/O board. This board connects to the Robolocust computer (the mini-ITX Debian box) over a USB port. The lobot::Serial class provides an API for interfacing with the Propeller using a serial port. It uses libserial for the serial communications if that library is available. Otherwise, it falls back to using INVT's support for serial communications.
Definition at line 85 of file LoSerial.H.
Serial::Serial | ( | const ModelManager & | , | |
const std::string & | device, | |||
int | baud_rate | |||
) |
Initialization.
Definition at line 109 of file LoSerial.C.
Serial::~Serial | ( | void | ) |
Clean-up.
Definition at line 283 of file LoSerial.C.
void Serial::eat | ( | int | n | ) |
Read and discard the specified number of bytes.
Definition at line 276 of file LoSerial.C.
References read_full().
int Serial::read | ( | char | buf[], | |
int | n | |||
) |
Receive data from the serial port. Returns the number of bytes successfully read. Client should check that this is equal to the expected number.
Definition at line 133 of file LoSerial.C.
Referenced by read_full().
void Serial::read_full | ( | char | buf[], | |
int | n | |||
) |
Read the specified number of bytes and don't return until they're all read in.
Definition at line 269 of file LoSerial.C.
References read().
Referenced by eat().
bool Serial::ready | ( | ) |
Check if the serial port has data available for reading.
Definition at line 127 of file LoSerial.C.
void Serial::write | ( | char | buf[], | |
int | n | |||
) |
Send data to the serial port.
Definition at line 148 of file LoSerial.C.