Class SerialIO

Class Documentation

class SerialIO

Wrapper class for serial communication.

Public Types

enum HandshakeFlags

Constants for defining the handshake.

Values:

enumerator HS_NONE
enumerator HS_HARDWARE
enumerator HS_XONXOFF
enum ParityFlags

Constants for defining the parity bits.

Values:

enumerator PA_NONE
enumerator PA_EVEN
enumerator PA_ODD
enumerator PA_MARK
enumerator PA_SPACE
enum StopBits

Constants for defining the stop bits.

Values:

enumerator SB_ONE
enumerator SB_ONE_5
enumerator SB_TWO

Public Functions

SerialIO()

Default constructor.

virtual ~SerialIO()

Destructor.

inline void setDeviceName(const char *Name)

Sets the device name

Parameters:

Name – ‘COM1’, ‘COM2’, …

inline void setBaudRate(int BaudRate)

Sets the baudrate.

Parameters:

BaudRate – baudrate.

void changeBaudRate(int BaudRate)

Changes the baudrate. The serial port is allready open.

Parameters:

BaudRate – new baudrate.

inline void setMultiplier(double Multiplier = 1)

Sets a multiplier for the baudrate. Some serial cards need a specific multiplier for the baudrate.

Parameters:

Multiplier – default is one.

inline void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)

Sets the message format.

inline void setHandshake(HandshakeFlags Handshake)

Defines the handshake type.

inline void setBufferSize(int ReadBufSize, int WriteBufSize)

Sets the buffer sizes.

Parameters:
  • ReadBufSize – number of bytes of the read buffer.

  • WriteBufSize – number of bytes of the write buffer.

void setTimeout(double Timeout)

Sets the timeout.

Parameters:

Timeout – in seconds

void setBytePeriod(double Period)

Sets the byte period for transmitting bytes. If the period is not equal to 0, the transmit will be repeated with the given period until all bytes are transmitted.

Parameters:

default – is 0.

int openIO()

Opens serial port. The port has to be configured before.

void closeIO()

Closes the serial port.

int readBlocking(char *Buffer, int Length)

Reads the serial port blocking. The function blocks until the requested number of bytes have been read or the timeout occurs.

Parameters:
  • Buffer – pointer to the buffer.

  • Length – number of bytes to read

int readNonBlocking(char *Buffer, int Length)

Reads the serial port non blocking. The function returns all avaiable bytes but not more than requested.

Parameters:
  • Buffer – pointer to the buffer.

  • Length – number of bytes to read

int writeIO(const char *Buffer, int Length)

Writes bytes to the serial port.

Parameters:
  • Buffer – buffer of the message

  • Length – number of bytes to send

int getSizeRXQueue()

Returns the number of bytes available in the read buffer.

inline void purge()

Clears the read and transmit buffer.

inline void purgeRx()

Clears the read buffer.

inline void purgeTx()

Clears the transmit buffer. The content of the buffer will not be transmitted.

inline void flushTx()

Sends the transmit buffer. All bytes of the transmit buffer will be sent.

Protected Attributes

::termios m_tio
std::string m_DeviceName
int m_Device
int m_BaudRate
double m_Multiplier
int m_ByteSize
int m_StopBits
ParityFlags m_Parity
HandshakeFlags m_Handshake
int m_ReadBufSize
int m_WriteBufSize
double m_Timeout
::timeval m_BytePeriod
bool m_ShortBytePeriod