SDHLibrary-CPP 0.0.2.10 C++ access library for SCHUNK Dextrous Hand SDH

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes

# SDH::cRS232 Class Reference

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

`#include <rs232-vcc.h>`

Inheritance diagram for SDH::cRS232:
[legend]
Collaboration diagram for SDH::cRS232:
[legend]

List of all members.

## Public Member Functions
| cRS232 (int _port, unsigned long _baudrate, double _timeout, char const *_device_format_string="/dev/ttyS%d")
void | Open (void) throw (cRS232Exception*)
bool | IsOpen (void) throw ()
| Return true if port to RS232 is open.
void | Close (void) throw (cRS232Exception*)
| Close the previously opened rs232 port.
int | write (char const *ptr, int len=0) throw (cRS232Exception*)
| Write data to a previously opened port.
ssize_t | Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data) throw (cRS232Exception*)
virtual bool | UseCRC16 ()
| overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication
| cRS232 (int _port, unsigned long _baudrate, double _timeout, char const *_device_format_string="")
| ~cRS232 (void)
void | Open (void) throw (cRS232Exception*)
| Open rs232 port port.
void | Close (void) throw (cRS232Exception*)
| Close the previously opened communication channel.
virtual void | SetTimeout (double _timeout) throw (cSerialBaseException*)
| set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
bool | IsOpen () throw ()
| Return true if communication channel is open.
int | write (char const *ptr, int len=0) throw (cRS232Exception*)
| Write data to a previously opened port.
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 bool | UseCRC16 ()
| overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communication
## 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
int | port
| the RS232 portnumber to use
std::string | device_format_string
| the sprintf format string to generate the device name from the port, see Constructor
unsigned long | baudrate
| the baudrate in bit/s
int | fd
| the file descriptor of the RS232 port
int | status
termios | io_set_old

## 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.

## 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

SDH::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 rs232 port.

Implements SDH::cSerialBase.

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

Close the previously opened communication channel.

Implements SDH::cSerialBase.

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

Return true if communication channel is open.

Implements SDH::cSerialBase.

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

Return true if port to RS232 is open.

Implements SDH::cSerialBase.

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

Open rs232 port port.

Open the device with the parameters provided in the constructor

Implements SDH::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:
  - Bug 1011: Bug: Binary communication does not work via RS232 on Linux
  - SDH_USE_BINARY_COMMUNICATION
    => Resolved in SDHLibrary 0.0.2.2

Implements SDH::cSerialBase.

ssize_t SDH::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 SDH::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 SDH::cSerialBase.

char * cRS232::readline | ( | char * | line,
|  | int | size,
|  | char * | eol,
|  | bool | return_on_less_data
| ) |  | throw (cRS232Exception*)

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 SDH::cSerialBase.

virtual bool SDH::cRS232::UseCRC16 | ( |  | ) | `[inline, virtual]`

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

Reimplemented from SDH::cSerialBase.

virtual bool SDH::cRS232::UseCRC16 | ( |  | ) | `[inline, virtual]`

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

Reimplemented from SDH::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

!! dwWritten is always 0! Damn bloody windows

Implements SDH::cSerialBase.

int SDH::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 SDH::cSerialBase.

## Member Data Documentation

unsigned long SDH::cRS232::baudrate`[protected]`

the baudrate in bit/s

std::string SDH::cRS232::device_format_string`[protected]`

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

int SDH::cRS232::fd`[protected]`

the file descriptor of the RS232 port

termios SDH::cRS232::io_set_old`[protected]`

int SDH::cRS232::port`[protected]`

the RS232 portnumber to use

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

int SDH::cRS232::status`[protected]`

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

- sdh/rs232-cygwin.h
- sdh/rs232-vcc.h
- sdh/rs232-cygwin.cpp
- sdh/rs232-vcc.cpp