cisst-saw
Loading...
Searching...
No Matches
osaSerialPort Class Reference

Serial port. More...

#include <osaSerialPort.h>

Inheritance diagram for osaSerialPort:
cmnGenericObject

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 , BaudRate230400 = CBR_230400 ,
  BaudRate460800 = CBR_460800
}
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)
Public Member Functions inherited from cmnGenericObject
virtual ~cmnGenericObject (void)
virtual const cmnClassServicesBaseServices (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::StreamBufTypeGetLogMultiplexer (void) const
virtual size_t ScalarNumber (void) const
virtual bool ScalarNumberIsFixed (void) const
virtual double Scalar (const size_t CMN_UNUSED(index)) const CISST_THROW(std
virtual std::string ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const

Detailed Description

Serial port.

Create a serial port for sending and receiving data.

Member Enumeration Documentation

◆ BaudRateType

Enumerator
BaudRate300 
BaudRate1200 
BaudRate9600 
BaudRate19200 
BaudRate38400 
BaudRate57600 
BaudRate115200 
BaudRate230400 
BaudRate460800 

◆ CharacterSizeType

Type used to define the character size.

See also
SetCharacterSize
Enumerator
CharacterSize5 
CharacterSize6 
CharacterSize7 
CharacterSize8 

◆ FlowControlType

Type used to define the flow control.

See also
SetFlowControl
Enumerator
FlowControlNone 
FlowControlSoftware 
FlowControlHardware 

◆ ParityCheckingType

Type used to define the parity checking.

See also
SetParityChecking
Enumerator
ParityCheckingNone 
ParityCheckingEven 
ParityCheckingOdd 

◆ StopBitsType

Type used to define stop bits.

See also
SetStopBits
Enumerator
StopBitsOne 
StopBitsTwo 

Constructor & Destructor Documentation

◆ osaSerialPort()

osaSerialPort::osaSerialPort ( void )
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.

◆ ~osaSerialPort()

virtual osaSerialPort::~osaSerialPort ( void )
virtual

Destructor.

Member Function Documentation

◆ Close()

bool osaSerialPort::Close ( void )

◆ Configure()

bool osaSerialPort::Configure ( void )

◆ Flush()

bool osaSerialPort::Flush ( void )

Flush.

◆ GetPortName()

std::string osaSerialPort::GetPortName ( void ) const
inline

Get the current port name.

◆ IsOpened()

bool osaSerialPort::IsOpened ( void ) const
inline

Indicates if the port has been opened or closed correctly.

◆ Open()

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, ...).

◆ Read() [1/2]

int osaSerialPort::Read ( char * data,
int nBytes )

Receive raw data.

◆ Read() [2/2]

int osaSerialPort::Read ( unsigned char * data,
int nBytes )

◆ SetBaudRate()

void osaSerialPort::SetBaudRate ( const BaudRateType & baudRate)
inline

Set a different baud rate.

◆ SetCharacterSize()

void osaSerialPort::SetCharacterSize ( const CharacterSizeType & characterSize)
inline

Set a different character size.

◆ SetFlowControl()

void osaSerialPort::SetFlowControl ( const FlowControlType & flowControl)
inline

Set different flow control.

◆ SetParityChecking()

void osaSerialPort::SetParityChecking ( const ParityCheckingType & parityChecking)
inline

Set a different parity checking.

◆ SetPortName()

void osaSerialPort::SetPortName ( const std::string & portName)
inline

Set the port name. For a more portable code, use SetPortNumber.

◆ SetPortNumber()

std::string osaSerialPort::SetPortNumber ( unsigned int portNumber)

Set the serial port name based on a number, starting from 1.

◆ SetStopBits()

void osaSerialPort::SetStopBits ( const StopBitsType & stopBits)
inline

Set different stop bits.

◆ Write() [1/3]

int osaSerialPort::Write ( const char * data,
int nBytes )

Send raw data.

◆ Write() [2/3]

int osaSerialPort::Write ( const std::string & data)
inline

◆ Write() [3/3]

int osaSerialPort::Write ( const unsigned char * data,
int nBytes )

◆ WriteBreak()

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.


The documentation for this class was generated from the following file: