cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
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
}
 
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
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::StreamBufTypeGetLogMultiplexer (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
 

Detailed Description

Serial port.

Create a serial port for sending and receiving data.

Member Enumeration Documentation

Type used to define the baud rate.

See Also
SetBaudRate
Enumerator
BaudRate300 
BaudRate1200 
BaudRate9600 
BaudRate19200 
BaudRate38400 
BaudRate57600 
BaudRate115200 

Type used to define the character size.

See Also
SetCharacterSize
Enumerator
CharacterSize5 
CharacterSize6 
CharacterSize7 
CharacterSize8 

Type used to define the flow control.

See Also
SetFlowControl
Enumerator
FlowControlNone 
FlowControlSoftware 
FlowControlHardware 

Type used to define the parity checking.

See Also
SetParityChecking
Enumerator
ParityCheckingNone 
ParityCheckingEven 
ParityCheckingOdd 

Type used to define stop bits.

See Also
SetStopBits
Enumerator
StopBitsOne 
StopBitsTwo 

Constructor & Destructor Documentation

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.

virtual osaSerialPort::~osaSerialPort ( void  )
virtual

Destructor.

Member Function Documentation

bool osaSerialPort::Close ( void  )
bool osaSerialPort::Configure ( void  )
bool osaSerialPort::Flush ( void  )

Flush.

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

Get the current port name.

bool osaSerialPort::IsOpened ( void  ) const
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 
)
void osaSerialPort::SetBaudRate ( const BaudRateType baudRate)
inline

Set a different baud rate.

void osaSerialPort::SetCharacterSize ( const CharacterSizeType characterSize)
inline

Set a different character size.

void osaSerialPort::SetFlowControl ( const FlowControlType flowControl)
inline

Set different flow control.

void osaSerialPort::SetParityChecking ( const ParityCheckingType parityChecking)
inline

Set a different parity checking.

void osaSerialPort::SetPortName ( const std::string &  portName)
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.

void osaSerialPort::SetStopBits ( const StopBitsType stopBits)
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 
)
int osaSerialPort::Write ( const std::string &  data)
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.


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