Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
cRS232 Class Reference

Low-level communication class to access a serial port on Cygwin and Linux. More...

#include <rs232-cygwin.h>

Inheritance diagram for cRS232:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void Close (void) throw (cRS232Exception*)
 Close the previously opened communication channel.
void Close (void) throw (cRS232Exception*)
 Close the previously opened rs232 port.
 cRS232 (int _port, unsigned long _baudrate, double _timeout, char const *_device_format_string="")
 cRS232 (int _port, unsigned long _baudrate, double _timeout, char const *_device_format_string="/dev/ttyS%d")
bool IsOpen () throw ()
 Return true if communication channel is open.
bool IsOpen (void) throw ()
 Return true if port to RS232 is open.
void Open (void) throw (cRS232Exception*)
 Open rs232 port port.
void Open (void) throw (cRS232Exception*)
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data) throw (cRS232Exception*)
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data) throw (cRS232Exception*)
char * readline (char *line, int size, char *eol, bool return_on_less_data) throw (cRS232Exception*)
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 ()
 overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication
virtual bool UseCRC16 ()
 overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication
int write (char const *ptr, int len=0) throw (cRS232Exception*)
 Write data to a previously opened port.
int write (char const *ptr, int len=0) throw (cRS232Exception*)
 Write data to a previously opened port.
 ~cRS232 (void)

Protected Member Functions

tcflag_t BaudrateToBaudrateCode (unsigned long baudrate) throw (cRS232Exception*)
 Translate a baudrate given as unsigned long into a baudrate code for struct termios.

Protected Attributes

unsigned long baudrate
 the baudrate in bit/s
std::string device_format_string
 the sprintf format string to generate the device name from the port, see Constructor
int fd
 the file descriptor of the RS232 port
termios io_set_old
int port
 the RS232 portnumber to use
int status

Private Attributes

HANDLE _hCOM
COMMTIMEOUTS comm_timeouts
long read_timeout_us

Detailed Description

Low-level communication class to access a serial port on Cygwin and Linux.

Low-level communication class to access a serial port on VCC Windows.

Definition at line 84 of file rs232-cygwin.h.


Constructor & Destructor Documentation

cRS232::cRS232 ( int  _port,
unsigned long  _baudrate,
double  _timeout,
char const *  _device_format_string = "/dev/ttyS%d" 
)

Constructor: constructs an object to communicate with an SDH via RS232

Parameters:
_port- rs232 device number: 0='COM1'='/dev/ttyS0', 1='COM2'='/dev/ttyS1', ...
_baudrate- the baudrate in bit/s
_timeout- the timeout in seconds
_device_format_string- a format string (C string) for generating the device name, like "/dev/ttyS%d" (default) or "/dev/ttyUSB%d". Must contain a d where the port number should be inserted. This char array is duplicated on construction
cRS232::cRS232 ( int  _port,
unsigned long  _baudrate,
double  _timeout,
char const *  _device_format_string = "" 
)

Constructor: constructs an object to communicate with an SDH via RS232

Parameters:
_port- rs232 device number: 0='COM1'='/dev/ttyS0', 1='COM2'='/dev/ttyS1', ...
_baudrate- the baudrate in bit/s
_timeout- the timeout in seconds
_device_format_string- ignored for this VCC version
cRS232::~cRS232 ( void  )

Member Function Documentation

tcflag_t cRS232::BaudrateToBaudrateCode ( unsigned long  baudrate) throw (cRS232Exception*) [protected]

Translate a baudrate given as unsigned long into a baudrate code for struct termios.

void cRS232::Close ( void  ) throw (cRS232Exception*) [virtual]

Close the previously opened communication channel.

Implements cSerialBase.

void cRS232::Close ( void  ) throw (cRS232Exception*) [virtual]

Close the previously opened rs232 port.

Implements cSerialBase.

bool cRS232::IsOpen ( ) throw () [inline, virtual]

Return true if communication channel is open.

Implements cSerialBase.

Definition at line 112 of file rs232-vcc.h.

bool cRS232::IsOpen ( void  ) throw () [virtual]

Return true if port to RS232 is open.

Implements cSerialBase.

void cRS232::Open ( void  ) throw (cRS232Exception*) [virtual]

Open rs232 port port.

Open the device with the parameters provided in the constructor

Implements cSerialBase.

void cRS232::Open ( void  ) throw (cRS232Exception*) [virtual]

Open the device as configured by the parameters given to the constructor

Bug:
The binary communication introduced in firmware 0.0.2.15 and SDHLibrary-C++ 0.0.2.0 did not work properly on Linux when RS232 was used for communication.
See also:

Implements cSerialBase.

ssize_t cRS232::Read ( void *  data,
ssize_t  size,
long  timeout_us,
bool  return_on_less_data 
) throw (cRS232Exception*) [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.

Implements cSerialBase.

ssize_t cRS232::Read ( void *  data,
ssize_t  size,
long  timeout_us,
bool  return_on_less_data 
) throw (cRS232Exception*) [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.

Implements cSerialBase.

char* cRS232::readline ( char *  line,
int  size,
char *  eol,
bool  return_on_less_data 
) throw (cRS232Exception*)
virtual void cRS232::SetTimeout ( double  _timeout) throw (cSerialBaseException*) [virtual]

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

Reimplemented from cSerialBase.

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

overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication

Reimplemented from cSerialBase.

Definition at line 136 of file rs232-vcc.h.

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

overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication

Reimplemented from cSerialBase.

Definition at line 168 of file rs232-cygwin.h.

int cRS232::write ( char const *  ptr,
int  len = 0 
) throw (cRS232Exception*) [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

Implements cSerialBase.

int cRS232::write ( char const *  ptr,
int  len = 0 
) throw (cRS232Exception*) [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

Implements cSerialBase.


Member Data Documentation

HANDLE cRS232::_hCOM [private]

Definition at line 75 of file rs232-vcc.h.

unsigned long cRS232::baudrate [protected]

the baudrate in bit/s

Definition at line 95 of file rs232-cygwin.h.

COMMTIMEOUTS cRS232::comm_timeouts [private]

Definition at line 80 of file rs232-vcc.h.

std::string cRS232::device_format_string [protected]

the sprintf format string to generate the device name from the port, see Constructor

Definition at line 92 of file rs232-cygwin.h.

int cRS232::fd [protected]

the file descriptor of the RS232 port

Definition at line 98 of file rs232-cygwin.h.

termios cRS232::io_set_old [protected]

Definition at line 106 of file rs232-cygwin.h.

int cRS232::port [protected]

the RS232 portnumber to use

the RS232 port number to use (port 0 is COM1)

Definition at line 89 of file rs232-cygwin.h.

long cRS232::read_timeout_us [private]

Definition at line 81 of file rs232-vcc.h.

int cRS232::status [protected]

Definition at line 104 of file rs232-cygwin.h.


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


schunk_sdh
Author(s): Florian Weisshardt
autogenerated on Mon Oct 6 2014 07:29:15