cisst-saw
|
Serial port. More...
#include <osaSerialPort.h>
Public Types | |
enum | BaudRateType { BaudRate300 = CBR_300, BaudRate1200 = CBR_1200, BaudRate9600 = CBR_9600, BaudRate19200 = CBR_19200, BaudRate38400 = CBR_38400, BaudRate57600 = CBR_57600, BaudRate115200 = CBR_115200 } |
enum | CharacterSizeType { CharacterSize5 = 5, CharacterSize6 = 6, CharacterSize7 = 7, CharacterSize8 = 8 } |
enum | ParityCheckingType { ParityCheckingNone = NOPARITY, ParityCheckingEven = EVENPARITY, ParityCheckingOdd = ODDPARITY } |
enum | FlowControlType { FlowControlNone, FlowControlSoftware, FlowControlHardware } |
enum | StopBitsType { StopBitsOne, StopBitsTwo } |
Public Member Functions | |
osaSerialPort (void) | |
virtual | ~osaSerialPort (void) |
void | SetBaudRate (const BaudRateType &baudRate) |
void | SetCharacterSize (const CharacterSizeType &characterSize) |
void | SetParityChecking (const ParityCheckingType &parityChecking) |
void | SetStopBits (const StopBitsType &stopBits) |
void | SetFlowControl (const FlowControlType &flowControl) |
void | SetPortName (const std::string &portName) |
std::string | GetPortName (void) const |
std::string | SetPortNumber (unsigned int portNumber) |
bool | Open (bool blocking=false) |
bool | Configure (void) |
bool | Close (void) |
bool | IsOpened (void) const |
int | Write (const char *data, int nBytes) |
int | Write (const unsigned char *data, int nBytes) |
int | Write (const std::string &data) |
int | Read (char *data, int nBytes) |
int | Read (unsigned char *data, int nBytes) |
bool | WriteBreak (double breakLengthInSeconds) |
bool | Flush (void) |
![]() | |
virtual | ~cmnGenericObject (void) |
virtual const cmnClassServicesBase * | Services (void) const =0 |
bool | ReconstructFrom (const cmnGenericObject &other) |
std::string | ToString (void) const |
virtual void | ToStream (std::ostream &outputStream) const |
virtual void | ToStreamRaw (std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const |
virtual bool | FromStreamRaw (std::istream &inputStream, const char delimiter= ' ') |
virtual void | SerializeRaw (std::ostream &outputStream) const |
virtual void | DeSerializeRaw (std::istream &inputStream) |
virtual cmnLogger::StreamBufType * | GetLogMultiplexer (void) const |
virtual size_t | ScalarNumber (void) const |
virtual bool | ScalarNumberIsFixed (void) const |
virtual double | Scalar (const size_t CMN_UNUSED(index)) const throw (std::out_of_range) |
virtual std::string | ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const |
Serial port.
Create a serial port for sending and receiving data.
Type used to define the baud rate.
Enumerator | |
---|---|
BaudRate300 | |
BaudRate1200 | |
BaudRate9600 | |
BaudRate19200 | |
BaudRate38400 | |
BaudRate57600 | |
BaudRate115200 |
Type used to define the character size.
Enumerator | |
---|---|
CharacterSize5 | |
CharacterSize6 | |
CharacterSize7 | |
CharacterSize8 |
Type used to define the flow control.
Enumerator | |
---|---|
FlowControlNone | |
FlowControlSoftware | |
FlowControlHardware |
Type used to define the parity checking.
Enumerator | |
---|---|
ParityCheckingNone | |
ParityCheckingEven | |
ParityCheckingOdd |
|
inline |
Default constructor. Set parameters to default 8N1 (8 bits per character, no parity checking, 1 stop bit) and 9600 baud rate. This constructor doesn't start anything, use Open() to actually start the serial port connection.
|
virtual |
Destructor.
bool osaSerialPort::Close | ( | void | ) |
bool osaSerialPort::Configure | ( | void | ) |
bool osaSerialPort::Flush | ( | void | ) |
Flush.
|
inline |
Get the current port name.
|
inline |
Indicates if the port has been opened or closed correctly.
bool osaSerialPort::Open | ( | bool | blocking = false | ) |
Open the serial port. This method starts the serial port based on the parameters previously set (either the defaults of those defined by SetBaudRate, SetCharacterSize, SetParityChecking, SetHardwareFlowControl, ...).
int osaSerialPort::Read | ( | char * | data, |
int | nBytes | ||
) |
Receive raw data.
int osaSerialPort::Read | ( | unsigned char * | data, |
int | nBytes | ||
) |
|
inline |
Set a different baud rate.
|
inline |
Set a different character size.
|
inline |
Set different flow control.
|
inline |
Set a different parity checking.
|
inline |
Set the port name. For a more portable code, use SetPortNumber.
std::string osaSerialPort::SetPortNumber | ( | unsigned int | portNumber | ) |
Set the serial port name based on a number, starting from 1.
|
inline |
Set different stop bits.
int osaSerialPort::Write | ( | const char * | data, |
int | nBytes | ||
) |
Send raw data.
int osaSerialPort::Write | ( | const unsigned char * | data, |
int | nBytes | ||
) |
|
inline |
bool osaSerialPort::WriteBreak | ( | double | breakLengthInSeconds | ) |
Sends a serial break for a given duration in seconds.
On Linux, if the break duration is set to 0, the actual duration will be at least 0.25 seconds and at most 0.5 seconds.
On Mac OS, the implementation doesn't use the breakLengthInSeconds. To provide a similar runtime, osaSleep is used internaly. As the default duration on MacOS it 0.4 seconds, the actual sleep time is breakLengthInSeconds - 0.4.
On Windows, this method is implemented using SetCommBreak, osaSleep and ClearCommBreak.