27 #ifndef _osaSerialPort_h
28 #define _osaSerialPort_h
35 #if (CISST_OS == CISST_WINDOWS)
61 #if (CISST_OS == CISST_WINDOWS)
63 BaudRate1200 = CBR_1200,
64 BaudRate9600 = CBR_9600,
65 BaudRate19200 = CBR_19200,
66 BaudRate38400 = CBR_38400,
67 BaudRate57600 = CBR_57600,
68 BaudRate115200 = CBR_115200};
70 enum BaudRateType {BaudRate300 = B300,
73 BaudRate19200 = B19200,
74 BaudRate38400 = B38400,
75 BaudRate57600 = B57600,
76 BaudRate115200 = B115200};
82 #if (CISST_OS == CISST_WINDOWS)
88 enum CharacterSizeType {CharacterSize5 = CS5,
91 CharacterSize8 = CS8};
97 #if (CISST_OS == CISST_WINDOWS)
99 ParityCheckingEven = EVENPARITY,
100 ParityCheckingOdd = ODDPARITY};
102 enum ParityCheckingType {ParityCheckingNone,
112 FlowControlHardware};
125 PortName(
"Undefined"),
127 BaudRate(BaudRate9600),
128 CharacterSize(CharacterSize8),
129 ParityChecking(ParityCheckingNone),
130 StopBits(StopBitsOne),
131 FlowControl(FlowControlNone)
133 #if (CISST_OS == CISST_WINDOWS)
134 memset(&OverlappedStructureRead, 0,
sizeof(OverlappedStructureRead));
135 memset(&OverlappedStructureWrite, 0,
sizeof(OverlappedStructureWrite));
147 this->BaudRate = baudRate;
149 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
154 this->CharacterSize = characterSize;
156 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
161 this->ParityChecking = parityChecking;
163 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
168 this->StopBits = stopBits;
170 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
175 this->FlowControl = flowControl;
177 <<
" on port " << this->PortName <<
" (not effective until Configure)" << std::endl;
182 this->PortName = portName;
187 return this->PortName;
191 std::string SetPortNumber(
unsigned int portNumber);
197 bool Open(
bool blocking =
false);
199 bool Configure(
void);
205 return this->IsOpenedFlag;
210 int Write(
const char * data,
int nBytes);
211 int Write(
const unsigned char * data,
int nBytes);
212 inline int Write(
const std::string & data) {
213 return this->Write(data.c_str(),
static_cast<int>(data.size()));
218 int Read(
char * data,
int nBytes);
219 int Read(
unsigned char * data,
int nBytes);
235 bool WriteBreak(
double breakLengthInSeconds);
242 std::string PortName;
246 BaudRateType BaudRate;
247 CharacterSizeType CharacterSize;
248 ParityCheckingType ParityChecking;
249 StopBitsType StopBits;
250 FlowControlType FlowControl;
252 #if (CISST_OS == CISST_WINDOWS)
254 OVERLAPPED OverlappedStructureRead, OverlappedStructureWrite;
255 COMMTIMEOUTS TimeOuts;
266 #endif // _osaSerialPort_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
void SetStopBits(const StopBitsType &stopBits)
Definition: osaSerialPort.h:167
bool IsOpened(void) const
Definition: osaSerialPort.h:204
BaudRateType
Definition: osaSerialPort.h:62
Portability across compilers and operating systems tools.
ParityCheckingType
Definition: osaSerialPort.h:98
void SetCharacterSize(const CharacterSizeType &characterSize)
Definition: osaSerialPort.h:153
Base class for high level objects.
Definition: cmnGenericObject.h:51
std::string GetPortName(void) const
Definition: osaSerialPort.h:186
void SetBaudRate(const BaudRateType &baudRate)
Definition: osaSerialPort.h:146
void SetPortName(const std::string &portName)
Definition: osaSerialPort.h:181
FlowControlType
Definition: osaSerialPort.h:110
CharacterSizeType
Definition: osaSerialPort.h:83
osaSerialPort(void)
Definition: osaSerialPort.h:124
CMN_DECLARE_SERVICES_INSTANTIATION(osaSerialPort)
int Write(const std::string &data)
Definition: osaSerialPort.h:212
Defines cmnGenericObject.
Macros to export the symbols of cisstOSAbstraction (in a Dll).
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
StopBitsType
Definition: osaSerialPort.h:116
Definition: osaSerialPort.h:111
void SetFlowControl(const FlowControlType &flowControl)
Definition: osaSerialPort.h:174
#define CMN_LOG_CLASS_INIT_VERBOSE
Definition: cmnLogger.h:115
void SetParityChecking(const ParityCheckingType &parityChecking)
Definition: osaSerialPort.h:160
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
Serial port.
Definition: osaSerialPort.h:50
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76