25#ifndef _osaSerialPort_h
26#define _osaSerialPort_h
33#if (CISST_OS == CISST_WINDOWS)
59#if (CISST_OS == CISST_WINDOWS)
63 #define CBR_230400 230400
66 #define CBR_460800 460800
80 #define B460800 460800
82 enum BaudRateType {BaudRate300 = B300,
85 BaudRate19200 = B19200,
86 BaudRate38400 = B38400,
87 BaudRate57600 = B57600,
88 BaudRate115200 = B115200,
89 BaudRate230400 = B230400,
90 BaudRate460800 = B460800};
96#if (CISST_OS == CISST_WINDOWS)
102 enum CharacterSizeType {CharacterSize5 = CS5,
103 CharacterSize6 = CS6,
104 CharacterSize7 = CS7,
105 CharacterSize8 = CS8};
111#if (CISST_OS == CISST_WINDOWS)
116 enum ParityCheckingType {ParityCheckingNone,
139 PortName(
"Undefined"),
147#if (CISST_OS == CISST_WINDOWS)
148 memset(&OverlappedStructureRead, 0,
sizeof(OverlappedStructureRead));
149 memset(&OverlappedStructureWrite, 0,
sizeof(OverlappedStructureWrite));
161 this->BaudRate = baudRate;
163 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
168 this->CharacterSize = characterSize;
170 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
175 this->ParityChecking = parityChecking;
177 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
182 this->StopBits = stopBits;
184 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
189 this->FlowControl = flowControl;
191 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
196 this->PortName = portName;
201 return this->PortName;
211 bool Open(
bool blocking =
false);
219 return this->IsOpenedFlag;
224 int Write(
const char * data,
int nBytes);
225 int Write(
const unsigned char * data,
int nBytes);
226 inline int Write(
const std::string & data) {
227 return this->
Write(data.c_str(),
static_cast<int>(data.size()));
232 int Read(
char * data,
int nBytes);
233 int Read(
unsigned char * data,
int nBytes);
256 std::string PortName;
266#if (CISST_OS == CISST_WINDOWS)
268 OVERLAPPED OverlappedStructureRead, OverlappedStructureWrite;
269 COMMTIMEOUTS TimeOuts;
Base class for high level objects.
Definition cmnGenericObject.h:53
Serial port.
Definition osaSerialPort.h:49
FlowControlType
Definition osaSerialPort.h:124
@ FlowControlSoftware
Definition osaSerialPort.h:125
@ FlowControlNone
Definition osaSerialPort.h:124
@ FlowControlHardware
Definition osaSerialPort.h:126
void SetParityChecking(const ParityCheckingType &parityChecking)
Definition osaSerialPort.h:174
bool IsOpened(void) const
Definition osaSerialPort.h:218
void SetBaudRate(const BaudRateType &baudRate)
Definition osaSerialPort.h:160
BaudRateType
Definition osaSerialPort.h:68
@ BaudRate300
Definition osaSerialPort.h:68
@ BaudRate19200
Definition osaSerialPort.h:71
@ BaudRate230400
Definition osaSerialPort.h:75
@ BaudRate1200
Definition osaSerialPort.h:69
@ BaudRate115200
Definition osaSerialPort.h:74
@ BaudRate460800
Definition osaSerialPort.h:76
@ BaudRate57600
Definition osaSerialPort.h:73
@ BaudRate38400
Definition osaSerialPort.h:72
@ BaudRate9600
Definition osaSerialPort.h:70
virtual ~osaSerialPort(void)
ParityCheckingType
Definition osaSerialPort.h:112
@ ParityCheckingOdd
Definition osaSerialPort.h:114
@ ParityCheckingEven
Definition osaSerialPort.h:113
@ ParityCheckingNone
Definition osaSerialPort.h:112
int Write(const char *data, int nBytes)
CharacterSizeType
Definition osaSerialPort.h:97
@ CharacterSize6
Definition osaSerialPort.h:98
@ CharacterSize7
Definition osaSerialPort.h:99
@ CharacterSize5
Definition osaSerialPort.h:97
@ CharacterSize8
Definition osaSerialPort.h:100
StopBitsType
Definition osaSerialPort.h:130
@ StopBitsTwo
Definition osaSerialPort.h:131
@ StopBitsOne
Definition osaSerialPort.h:130
int Write(const unsigned char *data, int nBytes)
void SetPortName(const std::string &portName)
Definition osaSerialPort.h:195
int Read(char *data, int nBytes)
int Write(const std::string &data)
Definition osaSerialPort.h:226
void SetCharacterSize(const CharacterSizeType &characterSize)
Definition osaSerialPort.h:167
bool WriteBreak(double breakLengthInSeconds)
std::string GetPortName(void) const
Definition osaSerialPort.h:200
bool Open(bool blocking=false)
void SetStopBits(const StopBitsType &stopBits)
Definition osaSerialPort.h:181
osaSerialPort(void)
Definition osaSerialPort.h:138
int Read(unsigned char *data, int nBytes)
void SetFlowControl(const FlowControlType &flowControl)
Definition osaSerialPort.h:188
std::string SetPortNumber(unsigned int portNumber)
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Defines cmnGenericObject.
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
#define CMN_LOG_CLASS_INIT_VERBOSE
Definition cmnLogger.h:115
Portability across compilers and operating systems tools.
Macros to export the symbols of cisstOSAbstraction (in a Dll).
#define CBR_230400
Definition osaSerialPort.h:63
#define CBR_460800
Definition osaSerialPort.h:66