SDHLibrary-CPP 0.0.2.10SCHUNK GmbH & Co. KG
C++ access library for SCHUNK Dextrous Hand SDH

SDH::cTCPSerial Class Reference

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

#include <tcpserial.h>

Inheritance diagram for SDH::cTCPSerial:
Collaboration diagram for SDH::cTCPSerial:

List of all members.

Public Member Functions

 cTCPSerial (char const *_tcp_adr, int _tcp_port, double _timeout) throw (cTCPSerialException*)
void Open (void) throw (cTCPSerialException*)
bool IsOpen (void) throw ()
 Return true if interface to CAN ESD is open.
void Close (void) throw (cTCPSerialException*)
 Close the previously opened CAN ESD interface port.
int write (char const *ptr, int len=0) throw (cTCPSerialException*)
 Write data to a previously opened port.
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data) throw (cTCPSerialException*)
void SetTimeout (double _timeout) throw (cSerialBaseException*)
 set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
virtual tErrorCode GetErrorNumber ()

Static Public Attributes

static double const TIMEOUT_WAIT_FOR_EVER_S = -1.0
static double const TIMEOUT_RETURN_IMMEDITELY_S = 0.0
static long const TIMEOUT_WAIT_FOR_EVER_US = -1
static long const TIMEOUT_RETURN_IMMEDITELY_US = 0

Protected Attributes

std::string tcp_adr
int tcp_port
 the TCP port to use
int fd
 the file descriptor of the socket

Static Protected Attributes

static const int INVALID_SOCKET = -1

Detailed Description

Low-level communication class to access a CAN port.


Constructor & Destructor Documentation

cTCPSerial::cTCPSerial ( char const *  _tcp_adr,
int  _tcp_port,
double  _timeout 
) throw (cTCPSerialException*)

Constructor: constructs an object to communicate with an SDH via TCP on _tcp_adr and _tcp_port.

Parameters:
_tcp_adr- a string describing the hostname or IP address of the SDH
_tcp_port- the port number on the SDH
_timeout- the timeout when receiving / sending data:

  • < 0.0 : no timeout = wait for ever
  • == 0.0 : zero timeout = return immediately
  • > 0.0 : timeout in seconds

Member Function Documentation

void cTCPSerial::Close ( void  ) throw (cTCPSerialException*) [virtual]

Close the previously opened CAN ESD interface port.

Implements SDH::cSerialBase.

virtual tErrorCode SDH::cTCPSerial::GetErrorNumber ( ) [inline, virtual]

Overloaded helper function that returns the last TCP error number.

Reimplemented from SDH::cSerialBase.

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

Return true if interface to CAN ESD is open.

Implements SDH::cSerialBase.

void cTCPSerial::Open ( void  ) throw (cTCPSerialException*) [virtual]

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

Implements SDH::cSerialBase.

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

void cTCPSerial::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.

int cTCPSerial::write ( char const *  ptr,
int  len = 0 
) throw (cTCPSerialException*) [virtual]

Write data to a previously opened port.

Write len bytes from *ptr to the CAN 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

int SDH::cTCPSerial::fd [protected]

the file descriptor of the socket

const int SDH::cTCPSerial::INVALID_SOCKET = -1 [static, protected]
std::string SDH::cTCPSerial::tcp_adr [protected]
int SDH::cTCPSerial::tcp_port [protected]

the TCP port to use

double const cTCPSerial::TIMEOUT_RETURN_IMMEDITELY_S = 0.0 [static]
double const cTCPSerial::TIMEOUT_WAIT_FOR_EVER_S = -1.0 [static]
long const cTCPSerial::TIMEOUT_WAIT_FOR_EVER_US = -1 [static]

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