Low-level communication class to access a serial port. More...
#include <serialbase.h>
Classes | |
class | cSetTimeoutTemporarily |
helper class to set timeout of _serial_base on construction and reset to previous value on destruction. (RAII-idiom) More... | |
Public Types | |
typedef int | tErrorCode |
type of the error code, DWORD on windows and int on Linux/cygwin More... | |
Public Member Functions | |
virtual void | Close (void)=0 |
Close the previously opened communication channel. More... | |
cSerialBase () | |
ctor More... | |
virtual char const * | GetErrorMessage (tErrorCode dw) |
virtual tErrorCode | GetErrorNumber () |
char const * | GetLastErrorMessage (void) |
return the last error message as string. The string returned will be overwritten by the next call to the function More... | |
virtual double | GetTimeout () |
get the timeout for next readline() calls (negative value means: no timeout, wait for ever) More... | |
virtual bool | IsOpen (void)=0 throw () |
Return true if communication channel is open. More... | |
virtual void | Open (void)=0 |
Open rs232 port port. More... | |
virtual ssize_t | Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0 |
virtual char * | readline (char *line, int size, char const *eol="\, bool return_on_less_data=false) |
Read a line from the device. More... | |
virtual void | SetTimeout (double _timeout) |
set the timeout for next readline() calls (negative value means: no timeout, wait for ever) More... | |
virtual bool | UseCRC16 () |
virtual int | write (char const *ptr, int len=0)=0 |
Write data to a previously opened port. More... | |
virtual | ~cSerialBase (void) |
dtor More... | |
Public Attributes | |
cDBG | dbg |
A stream object to print colored debug messages. More... | |
Protected Attributes | |
double | timeout |
timeout in seconds More... | |
char | ungetch |
an already read data byte of the next line More... | |
bool | ungetch_valid |
Flag, true if ungetch is valid. More... | |
Low-level communication class to access a serial port.
(This is an abstract base class with pure virtual functions)
Definition at line 105 of file serialbase.h.
typedef int cSerialBase::tErrorCode |
type of the error code, DWORD on windows and int on Linux/cygwin
Definition at line 233 of file serialbase.h.
|
inline |
ctor
Definition at line 120 of file serialbase.h.
|
inlinevirtual |
dtor
Definition at line 132 of file serialbase.h.
|
pure virtual |
Close the previously opened communication channel.
Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.
|
virtual |
Helper function that returns an error message for error code dw.
Reimplemented in cCANSerial_ESD, and cCANSerial_PEAK.
Definition at line 127 of file serialbase.cpp.
|
inlinevirtual |
Helper function that returns the last error number.
Reimplemented in cCANSerial_ESD, cCANSerial_PEAK, and cTCPSerial.
Definition at line 241 of file serialbase.h.
|
inline |
return the last error message as string. The string returned will be overwritten by the next call to the function
Definition at line 260 of file serialbase.h.
|
inlinevirtual |
get the timeout for next readline() calls (negative value means: no timeout, wait for ever)
Definition at line 157 of file serialbase.h.
|
pure virtual |
Return true if communication channel is open.
Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.
|
pure virtual |
Open rs232 port port.
Open the device with the parameters provided in the constructor
Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.
|
pure virtual |
Read data from device. This function waits until max_time_us us passed or the expected number of bytes are received via serial line. if (return_on_less_data is true (default value), the number of bytes that have been received are returned and the data is stored in data If the return_on_less_data is false, data is only read from serial line, if at least size bytes are available.
Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.
|
virtual |
Read a line from the device.
A line is terminated with one of the end-of-line (eol) characters ('
' by default) or until timeout. Up to size-1 bytes are read and a '\0' char is appended.
line | - ptr to where to store the read line |
size | - space available in line (bytes) |
eol | - a string containing all the chars that mark an end of line |
return_on_less_data | - if (return_on_less_data is true (default value), the number of bytes that have been received are returned and the data is stored in data If the return_on_less_data is false, data is only read from serial line, if at least size bytes are available. |
A pointer to the line read is returned.
Definition at line 76 of file serialbase.cpp.
|
inlinevirtual |
set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
Reimplemented in cCANSerial_ESD, cCANSerial_PEAK, cTCPSerial, and cRS232.
Definition at line 151 of file serialbase.h.
|
inlinevirtual |
function that returns true if a CRC16 is used to protect binary communication.
The default is false since only RS232 communication needs this.
Reimplemented in cRS232, and cRS232.
Definition at line 270 of file serialbase.h.
|
pure virtual |
Write data to a previously opened port.
Write len bytes from *ptr to the rs232 device
ptr | - pointer the byte array to send in memory |
len | - number of bytes to send |
Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.
cDBG cSerialBase::dbg |
A stream object to print colored debug messages.
Definition at line 227 of file serialbase.h.
|
protected |
timeout in seconds
Definition at line 116 of file serialbase.h.
|
protected |
an already read data byte of the next line
Definition at line 110 of file serialbase.h.
|
protected |
Flag, true if ungetch is valid.
Definition at line 113 of file serialbase.h.