Classes | Public Types | Public Member Functions | Public Attributes | Protected Attributes
cSerialBase Class Reference

Low-level communication class to access a serial port. More...

#include <serialbase.h>

Inheritance diagram for cSerialBase:
Inheritance graph
[legend]

List of all members.

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

Public Member Functions

virtual void Close (void)=0 throw (cSerialBaseException*)
 Close the previously opened communication channel.
 cSerialBase ()
 ctor
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
virtual double GetTimeout ()
 get the timeout for next readline() calls (negative value means: no timeout, wait for ever)
virtual bool IsOpen (void)=0 throw ()
 Return true if communication channel is open.
virtual void Open (void)=0 throw (cSerialBaseException*)
 Open rs232 port port.
virtual ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0 throw (cSerialBaseException*)
virtual char * readline (char *line, int size, char const *eol="\n", bool return_on_less_data=false) throw (cSerialBaseException*)
 Read a line from the device.
virtual void SetTimeout (double _timeout) throw (cSerialBaseException*)
 set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
virtual bool UseCRC16 ()
virtual int write (char const *ptr, int len=0)=0 throw (cSerialBaseException*)
 Write data to a previously opened port.
virtual ~cSerialBase (void)
 dtor

Public Attributes

cDBG dbg
 A stream object to print colored debug messages.

Protected Attributes

double timeout
 timeout in seconds
char ungetch
 an already read data byte of the next line
bool ungetch_valid
 Flag, true if ungetch is valid.

Detailed Description

Low-level communication class to access a serial port.

(This is an abstract base class with pure virtual functions)

Definition at line 122 of file serialbase.h.


Member Typedef Documentation

type of the error code, DWORD on windows and int on Linux/cygwin

Definition at line 255 of file serialbase.h.


Constructor & Destructor Documentation

ctor

Definition at line 137 of file serialbase.h.

virtual cSerialBase::~cSerialBase ( void  ) [inline, virtual]

dtor

Definition at line 148 of file serialbase.h.


Member Function Documentation

virtual void cSerialBase::Close ( void  ) throw (cSerialBaseException*) [pure virtual]

Close the previously opened communication channel.

Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.

virtual char const* cSerialBase::GetErrorMessage ( tErrorCode  dw) [virtual]

Helper function that returns an error message for error code dw.

  • On windows FormatMessageA() is used
  • On cygwin/linux this uses errno
Remarks:
The string returned will be overwritten by the next call to the function

Reimplemented in cCANSerial_ESD, and cCANSerial_PEAK.

virtual tErrorCode cSerialBase::GetErrorNumber ( ) [inline, virtual]

Helper function that returns the last error number.

  • On windows GetLastError() is used
  • On cygwin/linux this uses errno

Reimplemented in cCANSerial_ESD, cCANSerial_PEAK, and cTCPSerial.

Definition at line 263 of file serialbase.h.

char const* cSerialBase::GetLastErrorMessage ( void  ) [inline]

return the last error message as string. The string returned will be overwritten by the next call to the function

Definition at line 282 of file serialbase.h.

virtual double cSerialBase::GetTimeout ( ) [inline, virtual]

get the timeout for next readline() calls (negative value means: no timeout, wait for ever)

Definition at line 176 of file serialbase.h.

virtual bool cSerialBase::IsOpen ( void  ) throw () [pure virtual]

Return true if communication channel is open.

Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.

virtual void cSerialBase::Open ( void  ) throw (cSerialBaseException*) [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.

virtual ssize_t cSerialBase::Read ( void *  data,
ssize_t  size,
long  timeout_us,
bool  return_on_less_data 
) throw (cSerialBaseException*) [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 char* cSerialBase::readline ( char *  line,
int  size,
char const *  eol = "\n",
bool  return_on_less_data = false 
) throw (cSerialBaseException*) [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.

Parameters:
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.

virtual void cSerialBase::SetTimeout ( double  _timeout) throw (cSerialBaseException*) [inline, virtual]

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 169 of file serialbase.h.

virtual bool cSerialBase::UseCRC16 ( ) [inline, virtual]

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 292 of file serialbase.h.

virtual int cSerialBase::write ( char const *  ptr,
int  len = 0 
) throw (cSerialBaseException*) [pure virtual]

Write data to a previously opened port.

Write len bytes from *ptr to the rs232 device

Parameters:
ptr- pointer the byte array to send in memory
len- number of bytes to send
Returns:
the number of bytes actually written

Implemented in cCANSerial_ESD, cCANSerial_PEAK, cRS232, cTCPSerial, and cRS232.


Member Data Documentation

A stream object to print colored debug messages.

Definition at line 249 of file serialbase.h.

double cSerialBase::timeout [protected]

timeout in seconds

Definition at line 133 of file serialbase.h.

char cSerialBase::ungetch [protected]

an already read data byte of the next line

Definition at line 127 of file serialbase.h.

bool cSerialBase::ungetch_valid [protected]

Flag, true if ungetch is valid.

Definition at line 130 of file serialbase.h.


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


schunk_sdh
Author(s): Mathias Luedtke , Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:21