Overview

Common labCAN bus device handling and management This group defines all common functions for handling of devices attached to labCAN bus.

+ Collaboration diagram for Device Management:

Enumerations

enum  LCB_CommState { LCB_COMM_STOPPED = 0x02, LCB_COMM_CONFIGURABLE = 0x80, LCB_COMM_OPERATIONAL = 0x01 }
 Communication state identifiers for LCB_SetCommState() More...
 

Functions

long LCB_GetDevErrMsg (dev_hdl DeviceHandle, unsigned long DevErr, char *pMsgBuf, int MsgBufSize)
 Get the error string for a certain device error message. More...
 
long LCB_GetDeviceProperty (dev_hdl DeviceHandle, int PropertyId, double *Value)
 Function for reading a device specific property. More...
 
long LCB_GetDevName (dev_hdl DeviceHandle, char *pNameStringBuf, int StringBufSize)
 Query name of specific device. More...
 
long LCB_GetNodeId (dev_hdl DeviceHandle)
 Query node identifier of specific device Each CANopen device has a unique node identifier that identifies the device on a CAN bus. More...
 
long LCB_IsSimulated (dev_hdl DeviceHandle)
 Checks if the given DeviceHandle is a simulated device. More...
 
long LCB_ReadDevParam (dev_hdl DeviceHandle, unsigned long DevParamId, void *pReadBuf, unsigned long BufSize, unsigned char AdjustEndian)
 Read certain parameter from device. More...
 
long LCB_ReadLastDevErr (dev_hdl DeviceHandle, unsigned long *pDevErr)
 Read last device error from a specific device. More...
 
long LCB_SetCommState (dev_hdl DeviceHandle, unsigned char CommState)
 Set device in a configurable state. More...
 
long LCB_SetDeviceProperty (dev_hdl DeviceHandle, int PropertyId, double Value)
 Function for setting a device specific property. More...
 
long LCB_WriteDevParam (dev_hdl DeviceHandle, unsigned long DevParamId, void *pWriteBuf, unsigned long BufSize, unsigned char AdjustEndian)
 Write certain parameter to device. More...
 

Enumeration Type Documentation

Communication state identifiers for LCB_SetCommState()

Enumerator
LCB_COMM_STOPPED 

no process data communication

LCB_COMM_CONFIGURABLE 

for configuration purposes - preoperational

LCB_COMM_OPERATIONAL 

full communication - some parameters are not writable in this state

Function Documentation

long LCB_GetDevErrMsg ( dev_hdl  DeviceHandle,
unsigned long  DevErr,
char *  pMsgBuf,
int  MsgBufSize 
)

Get the error string for a certain device error message.

This function decodes the error code obtained by a call to LCB_ReadLastDevErr().

Parameters
[in]DeviceHandleValid bus handle
[in]DevErrDevice erorr code returned by readLastDevErr()
[out]pMsgBufMessage buffer for storage of error message string
[in]MsgBufSizeSize of message buffer pMsgBuf in bytes
Return values
ERR_NOTSUPThe erro code is unknown - no message was found
ERR_PARAM_INVALIDInvalid device handle
ERR_NOERRError message was found
Examples:
capi_event_queue_test.cpp.
long LCB_GetDeviceProperty ( dev_hdl  DeviceHandle,
int  PropertyId,
double *  Value 
)

Function for reading a device specific property.

See also
LCB_SetDeviceProperty
Parameters
[in]DeviceHandleValid device handle
[in]PropertyIdDevice specific device property identifier
[out]ValueReturns the current value of the given device property.
Return values
ERR_NOERRSuccess
-ERR_NOTSUPThe given device property is not supported for the device given in DeviceHandle
<0 Error code
Examples:
capi_contiflow_test.cpp, and capi_rotaxys_test.cpp.
long LCB_GetDevName ( dev_hdl  DeviceHandle,
char *  pNameStringBuf,
int  StringBufSize 
)

Query name of specific device.

Normally all devices are named. That means each device carries a unique name

Parameters
[in]DeviceHandleValid device handle
[out]pNameStringBufMessage buffer for storage of error message string
[in]StringBufSizeSize of message buffer pMsgBuf in bytes
Returns
Error code - ERR_NOERR indicates success
Examples:
capi_event_queue_test.cpp, capi_nemaxys_test.cpp, and capi_nemesys_valve_test.cpp.
long LCB_GetNodeId ( dev_hdl  DeviceHandle)

Query node identifier of specific device Each CANopen device has a unique node identifier that identifies the device on a CAN bus.

Parameters
[in]DeviceHandleValid device handle
Return values
>=0 Node ID
<0 Error code
long LCB_IsSimulated ( dev_hdl  DeviceHandle)

Checks if the given DeviceHandle is a simulated device.

Parameters
[in]DeviceHandleValid device handle
Return values
0It is a real device
1It is a simulated device
<0 Error code
Examples:
capi_rotaxys_test.cpp.
long LCB_ReadDevParam ( dev_hdl  DeviceHandle,
unsigned long  DevParamId,
void *  pReadBuf,
unsigned long  BufSize,
unsigned char  AdjustEndian 
)

Read certain parameter from device.

Each device may contain a number of parameters to read or write. These parameters are device specific and you need a good knowledge or a good documentation of the device parameters.

Parameters
[in]DeviceHandleValid device handle
[in]DevParamIdDevice parameter identifier
[out]pReadBufStores the data read from device
[in]BufSizeContains the size of the buffer
[in]AdjustEndianThis parameter indicates if the function should adjust the endianess of the data read from device If the device bus transports the data in a different endian format like the host machine, then the endianess will be adjusted if this parameter is true. Normally this parameter should be set to true for numbers (integers, bytes...) and to false for string or other data.
Returns
Error code - ERR_NOERR indicates success
See also
LCB_WriteDevParam()
long LCB_ReadLastDevErr ( dev_hdl  DeviceHandle,
unsigned long *  pDevErr 
)

Read last device error from a specific device.

If an error occured then the device stores the last error so that it is accessible later at any time. This function reads the last error code from the device. Call LCB_GetDevErrMsg() to get a more descriptive error message for a certain device error code.

Parameters
[in]DeviceHandleValid device handle
[out]pDevErrReturns last device error
Returns
Error code - ERR_NOERR indicates success
long LCB_SetCommState ( dev_hdl  DeviceHandle,
unsigned char  CommState 
)

Set device in a configurable state.

Some device parameters are only writeable if the device is not operational but in a configurable state. The function LCB_WriteDevParam() might require to set the device into an configurable state. To set the device into a configurable state, this function should be called with the parameter LCB_COMM_CONFIGURABLE. If the configuration is finished, the device should be set operational again by calling this function with the parameter LCB_COMM_OPERATIONAL.

Parameters
[in]DeviceHandleValid device handle
[in]CommStateThe communication state to set this device to
Returns
Error code - ERR_NOERR indicates success
See also
LCB_CommState
long LCB_SetDeviceProperty ( dev_hdl  DeviceHandle,
int  PropertyId,
double  Value 
)

Function for setting a device specific property.

Devices may support special device properties that are not accessible via the common device specific API. Use this function to set the value of a certain property by providing a property ID and a value.

See also
LCB_GetDeviceProperty
Parameters
[in]DeviceHandleValid device handle
[in]PropertyIdDevice specific device property identifier
[in]ValueValue to set for the given device property
Return values
ERR_NOERRSuccess
-ERR_NOTSUPThe given device property is not supported for the device given in DeviceHandle
<0 Error code
Examples:
capi_contiflow_test.cpp, and capi_rotaxys_test.cpp.
long LCB_WriteDevParam ( dev_hdl  DeviceHandle,
unsigned long  DevParamId,
void *  pWriteBuf,
unsigned long  BufSize,
unsigned char  AdjustEndian 
)

Write certain parameter to device.

See readDevParam for a detailed description

Parameters
[in]DeviceHandleValid device handle
[in]DevParamIdDevice parameter identifier
[out]pWriteBufStores the data read from device
[in]BufSizeContains the size of the buffer and returns the numer of bytes read from device
[in]AdjustEndianThis parameter indicates if the function should adjust the endianess of the data before writing to device
Returns
Error code - ERR_NOERR indicates success
See also
LCB_ReadDevParam()
Note
For some parameters it might be necessary to set the device communication state machine into a configurable state.