Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
cCANSerial_PEAK Class Reference

Low-level communication class to access a CAN port from company PEAK (http://www.peak-system.com) More...

#include <canserial-peak.h>

Inheritance diagram for cCANSerial_PEAK:
Inheritance graph
[legend]

Public Member Functions

 cCANSerial_PEAK (unsigned long _baudrate, double _timeout, int _id_read, int _id_write, const char *device="/dev/pcanusb0")
 
 cCANSerial_PEAK (tDeviceHandle _peak_handle, double _timeout, int _id_read, int _id_write)
 
void Close (void)
 Close the previously opened CAN PEAK interface port. More...
 
virtual char const * GetErrorMessage (tErrorCode dw)
 
virtual tErrorCode GetErrorNumber ()
 
tDeviceHandle GetHandle ()
 
bool IsOpen (void) throw ()
 Return true if interface to CAN PEAK is open. More...
 
void Open (void)
 
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data)
 
void SetTimeout (double _timeout)
 set the timeout for next readline() calls (negative value means: no timeout, wait for ever) More...
 
int write (char const *ptr, int len=0)
 Write data to a previously opened port. More...
 
 ~cCANSerial_PEAK ()
 destructor: clean up More...
 
- Public Member Functions inherited from cSerialBase
 cSerialBase ()
 ctor More...
 
char const * GetLastErrorMessage (void)
 return the last error message as string. The string returned will be overwritten by the next call to the function More...
 
virtual double GetTimeout ()
 get the timeout for next readline() calls (negative value means: no timeout, wait for ever) More...
 
virtual char * readline (char *line, int size, char const *eol="\, bool return_on_less_data=false)
 Read a line from the device. More...
 
virtual bool UseCRC16 ()
 
virtual ~cSerialBase (void)
 dtor More...
 

Protected Member Functions

int BaudrateToBaudrateCode (unsigned long baudrate)
 Translate a baudrate given as unsigned long into a baudrate code for struct termios. More...
 

Protected Attributes

unsigned long baudrate
 the baudrate to use in bit/s More...
 
int id_read
 the CAN ID used for reading More...
 
int id_write
 the CAN ID used for writing More...
 
char m_device [64]
 
- Protected Attributes inherited from cSerialBase
double timeout
 timeout in seconds More...
 
char ungetch
 an already read data byte of the next line More...
 
bool ungetch_valid
 Flag, true if ungetch is valid. More...
 

Private Member Functions

 cCANSerial_PEAK (cCANSerial_PEAK const &other)
 private copy constructor without implementation, since copying of cCANSerial_PEAK objects makes no sense More...
 
cCANSerial_PEAKoperator= (cCANSerial_PEAK const &rhs)
 private copy assignment operator without implementation, since copying of cCANSerial_PEAK objects makes no sense More...
 

Private Attributes

cCANSerial_PEAK_Internalpimpl
 ptr to private, implementation specific members (using the 'Pimpl' (pointer to implementatino) design pattern) More...
 

Additional Inherited Members

- Public Types inherited from cSerialBase
typedef int tErrorCode
 type of the error code, DWORD on windows and int on Linux/cygwin More...
 
- Public Attributes inherited from cSerialBase
cDBG dbg
 A stream object to print colored debug messages. More...
 

Detailed Description

Low-level communication class to access a CAN port from company PEAK (http://www.peak-system.com)

Since SDHLibrary-C++ release 0.0.2.0 implementation specific parts of the access to PEAK CAN devices have been removed from the header file here in order to get rid of dependencies from the Pcan_usb.h. Specifically the peak_handle of type PEAK_HANDLE member was removed. You can still provide an existing handle for reuse on construction, but you must cast your HANDLE to a tDeviceHandle. You can get the internally used PEAK_HANDLE cast to a tDeviceHandle with GetHandle().

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

Constructor & Destructor Documentation

◆ cCANSerial_PEAK() [1/3]

cCANSerial_PEAK::cCANSerial_PEAK ( cCANSerial_PEAK const &  other)
private

private copy constructor without implementation, since copying of cCANSerial_PEAK objects makes no sense

◆ cCANSerial_PEAK() [2/3]

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

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!)

Definition at line 160 of file canserial-peak.cpp.

◆ cCANSerial_PEAK() [3/3]

cCANSerial_PEAK::cCANSerial_PEAK ( tDeviceHandle  _peak_handle,
double  _timeout,
int  _id_read,
int  _id_write 
)

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
_peak_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)

◆ ~cCANSerial_PEAK()

cCANSerial_PEAK::~cCANSerial_PEAK ( )

destructor: clean up

Definition at line 202 of file canserial-peak.cpp.

Member Function Documentation

◆ BaudrateToBaudrateCode()

int cCANSerial_PEAK::BaudrateToBaudrateCode ( unsigned long  baudrate)
protected

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

Definition at line 309 of file canserial-peak.cpp.

◆ Close()

void cCANSerial_PEAK::Close ( void  )
virtual

Close the previously opened CAN PEAK interface port.

Implements cSerialBase.

Definition at line 299 of file canserial-peak.cpp.

◆ GetErrorMessage()

char const * cCANSerial_PEAK::GetErrorMessage ( tErrorCode  dw)
virtual

Overloaded helper function that returns a PEAK error message for error code dw.

Remarks
The string returned will be overwritten by the next call to the function

Reimplemented from cSerialBase.

Definition at line 517 of file canserial-peak.cpp.

◆ GetErrorNumber()

cSerialBase::tErrorCode cCANSerial_PEAK::GetErrorNumber ( )
virtual

Overloaded helper function that returns the last Peak error number.

Reimplemented from cSerialBase.

Definition at line 526 of file canserial-peak.cpp.

◆ GetHandle()

tDeviceHandle cCANSerial_PEAK::GetHandle ( )

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 532 of file canserial-peak.cpp.

◆ IsOpen()

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

Return true if interface to CAN PEAK is open.

Implements cSerialBase.

Definition at line 291 of file canserial-peak.cpp.

◆ Open()

void cCANSerial_PEAK::Open ( void  )
virtual

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

Implements cSerialBase.

Definition at line 234 of file canserial-peak.cpp.

◆ operator=()

cCANSerial_PEAK& cCANSerial_PEAK::operator= ( cCANSerial_PEAK const &  rhs)
private

private copy assignment operator without implementation, since copying of cCANSerial_PEAK objects makes no sense

◆ Read()

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

Definition at line 375 of file canserial-peak.cpp.

◆ SetTimeout()

void cCANSerial_PEAK::SetTimeout ( double  _timeout)
virtual

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

Reimplemented from cSerialBase.

Definition at line 507 of file canserial-peak.cpp.

◆ write()

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

Definition at line 329 of file canserial-peak.cpp.

Member Data Documentation

◆ baudrate

unsigned long cCANSerial_PEAK::baudrate
protected

the baudrate to use in bit/s

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

◆ id_read

int cCANSerial_PEAK::id_read
protected

the CAN ID used for reading

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

◆ id_write

int cCANSerial_PEAK::id_write
protected

the CAN ID used for writing

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

◆ m_device

char cCANSerial_PEAK::m_device[64]
protected

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

◆ pimpl

cCANSerial_PEAK_Internal* cCANSerial_PEAK::pimpl
private

ptr to private, implementation specific members (using the 'Pimpl' (pointer to implementatino) design pattern)

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


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


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Mon Feb 28 2022 23:41:52