cCANSerial_PEAK Class Reference

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

#include <canserial-peak.h>

Inheritance diagram for cCANSerial_PEAK:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 cCANSerial_PEAK (PCAN_HANDLE _handle, double _timeout, Int32 _id_read, Int32 _id_write) throw (cCANSerial_PEAKException*)
 cCANSerial_PEAK (unsigned long _baudrate, double _timeout, Int32 _id_read, Int32 _id_write, const char *device="/dev/pcanusb0") throw (cCANSerial_PEAKException*)
void Close (void) throw (cCANSerial_PEAKException*)
 Close the previously opened CAN PEAK interface port.
PCAN_HANDLE GetHandle ()
bool IsOpen (void) throw ()
 Return true if interface to CAN PEAK is open.
void Open (void) throw (cCANSerial_PEAKException*)
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data) throw (cCANSerial_PEAKException*)
void SetTimeout (double _timeout) throw (cSerialBaseException*)
 set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
int write (char const *ptr, int len=0) throw (cCANSerial_PEAKException*)
 Write data to a previously opened port.

Protected Member Functions

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

Protected Attributes

unsigned long baudrate
 the baudrate to use in bit/s
PCAN_HANDLE handle
 the handle to the driver
DWORD id_read
 the CAN ID used for reading
DWORD id_write
 the CAN ID used for writing
char m_device [64]

Private Attributes

TPCANMsg m_cmsg
int m_cmsg_next
 index of next received data byte to return to user in m_cmsg

Detailed Description

Low-level communication class to access a CAN port.

Definition at line 93 of file canserial-peak.h.


Constructor & Destructor Documentation

cCANSerial_PEAK::cCANSerial_PEAK ( unsigned long  _baudrate,
double  _timeout,
Int32  _id_read,
Int32  _id_write,
const char *  device = "/dev/pcanusb0" 
) throw (cCANSerial_PEAKException*)

Constructor: constructs an object to communicate with an SDH via CAN bus using a PEAK CAN card.

Parameters:
_baudrate - the baudrate in bit/s. Only some bitrates are valid: (1000000,800000,500000,250000,125000,100000,50000,20000,10000)
_timeout - the timeout in seconds (0 for no timeout = wait for ever)
_id_read - the CAN ID to use for reading (The SDH sends data on this ID)
_id_write - the CAN ID to use for writing (The SDH receives data on this ID)
device - the name of the char device to communicate with the PEAD driver (Needed on Linux only!)
cCANSerial_PEAK::cCANSerial_PEAK ( PCAN_HANDLE  _handle,
double  _timeout,
Int32  _id_read,
Int32  _id_write 
) throw (cCANSerial_PEAKException*)

Constructor: constructs an object to communicate with an SDH via CAN bus using a PEAK CAN card by reusing an already existing handle (will work in Linux only).

Parameters:
_handle - the PEAK CAN handle to reuse (Works on Linux only!)
_timeout - the timeout in seconds (0 for no timeout = wait for ever)
_id_read - the CAN ID to use for reading (The SDH sends data on this ID)
_id_write - the CAN ID to use for writing (The SDH receives data on this ID)

Member Function Documentation

WORD cCANSerial_PEAK::BaudrateToBaudrateCode ( unsigned long  baudrate  )  throw (cCANSerial_PEAKException*) [protected]

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

void cCANSerial_PEAK::Close ( void   )  throw (cCANSerial_PEAKException*) [virtual]

Close the previously opened CAN PEAK interface port.

Implements cSerialBase.

PCAN_HANDLE cCANSerial_PEAK::GetHandle (  )  [inline]

Return the value of the HANDLe to the actual CAN device. Works on Linux only! Only returns a valid handle after a call to Open()!

Remarks:
The returned handle can be used to open a connection to a second SDH on the same CAN bus
Returns:
the handle to the actual CAN device

Definition at line 173 of file canserial-peak.h.

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

Return true if interface to CAN PEAK is open.

Implements cSerialBase.

void cCANSerial_PEAK::Open ( void   )  throw (cCANSerial_PEAKException*) [virtual]

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

Implements cSerialBase.

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

void cCANSerial_PEAK::SetTimeout ( double  _timeout  )  throw (cSerialBaseException*) [virtual]

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

Reimplemented from cSerialBase.

int cCANSerial_PEAK::write ( char const *  ptr,
int  len = 0 
) throw (cCANSerial_PEAKException*) [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 cSerialBase.


Member Data Documentation

unsigned long cCANSerial_PEAK::baudrate [protected]

the baudrate to use in bit/s

Definition at line 99 of file canserial-peak.h.

the handle to the driver

Definition at line 108 of file canserial-peak.h.

DWORD cCANSerial_PEAK::id_read [protected]

the CAN ID used for reading

Definition at line 102 of file canserial-peak.h.

DWORD cCANSerial_PEAK::id_write [protected]

the CAN ID used for writing

Definition at line 105 of file canserial-peak.h.

TPCANMsg cCANSerial_PEAK::m_cmsg [private]

received messages might be split over several CAN messages it might therefore happen that more data is received than can be returned to the user. To not loose that data it is kept here to be be returned in a later call

Definition at line 134 of file canserial-peak.h.

index of next received data byte to return to user in m_cmsg

Definition at line 138 of file canserial-peak.h.

char cCANSerial_PEAK::m_device[64] [protected]

Definition at line 114 of file canserial-peak.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


cob_sdh
Author(s): Florian Weisshardt
autogenerated on Fri Jan 11 10:03:55 2013