![]() |
Kvaser Linux CANLIB: Welcome to Kvaser CANLIB!
|
Functions | |
void | canInitializeLibrary (void) |
canStatus | canGetErrorText (canStatus err, char *buf, unsigned int bufsiz) |
unsigned short | canGetVersion (void) |
canStatus | canIoCtl (const CanHandle hnd, unsigned int func, void *buf, unsigned int buflen) |
canStatus | canGetNumberOfChannels (int *channelCount) |
canStatus | canGetChannelData (int channel, int item, void *buffer, size_t bufsize) |
canStatus | canUnloadLibrary (void) |
canStatus | kvFlashLeds (const CanHandle hnd, int action, int timeout) |
kvStatus | kvSetNotifyCallback (const CanHandle hnd, kvCallback_t callback, void *context, unsigned int notifyFlags) |
kvStatus | kvReadDeviceCustomerData (const CanHandle hnd, int userNumber, int itemNumber, void *data, size_t bufsiz) |
kvStatus | kvDeviceSetMode (const CanHandle hnd, int mode) |
kvStatus | kvDeviceGetMode (const CanHandle hnd, int *result) |
kvStatus | kvReadTimer (const CanHandle hnd, unsigned int *time) |
kvStatus | kvReadTimer64 (const CanHandle hnd, uint64_t *time) |
void canInitializeLibrary | ( | void | ) |
This function must be called before any other functions is used. It will initialize the driver.
You may call canInitializeLibrary() more than once. The actual initialization will take place only once.
Any errors encountered during library initialization will be "silent" and an appropriate canERR_xxx error code will be returned later on when canOpenChannel() (or any other API call that requires initialization) is called.
This function translates an error code (canERR_xxx) to a human-readable, English text.
[in] | err | The error code. |
[out] | buf | The buffer which is to receive the text, which is a zero-terminated string (provided the buffer is large enough.) |
[in] | bufsiz | The length of the input buffer. |
unsigned short canGetVersion | ( | void | ) |
This API call returns the version of the CANLIB API library (libcanlib.so.x.y). The most significant byte is the major version number and the least significant byte is the minor version number.
This API call performs several different functions; these are described below. The functions are handle-specific unless otherwise noted; this means that they affect only the handle you pass to canIoCtl(), whereas other open handles will remain unaffected. The contents of buf after the call is dependent on the function code you specified.
[in] | hnd | A handle to an open circuit. |
[in] | func | A canIOCTL_xxx function code |
[in,out] | buf | Pointer to a buffer containing function-dependent data; or a NULL pointer for certain function codes. The buffer can be used for both input and output depending on the function code. See canIOCTL_xxx. |
[in] | buflen | The length of the buffer. |
canStatus canGetNumberOfChannels | ( | int * | channelCount | ) |
This function returns the number of available CAN channels in the computer. The virtual channels are included in this number.
[out] | channelCount | A pointer to a DWORD which will receive the current number of channels. |
canStatus canGetChannelData | ( | int | channel, |
int | item, | ||
void * | buffer, | ||
size_t | bufsize | ||
) |
This function can be used to retrieve certain pieces of information about a channel.
[in] | channel | The number of the channel you are interested in. Channel numbers are integers in the interval beginning at 0 (zero) and ending at the value returned by canGetNumberOfChannels() minus 1. |
[in] | item | This parameter specifies what data to obtain for the specified channel. The value is one of the constants canCHANNELDATA_xxx. |
[out] | buffer | The address of a buffer which is to receive the data. |
[in] | bufsize | The size of the buffer to which the buffer parameter points. |
canStatus canUnloadLibrary | ( | void | ) |
canUnloadLibrary() will close all open handles and free allocated memory.
The kvFlashLeds function will turn the LEDs on the device on or off.
[in] | hnd | |
[in] | action | One of the kvLED_ACTION_xxx constants, defining which LED to turn on or off. |
[in] | timeout | Specifies the time, in milliseconds, during which the action is to be carried out. When the timeout expires, the LED(s) will return to its ordinary function. |
kvStatus kvSetNotifyCallback | ( | const CanHandle | hnd, |
kvCallback_t | callback, | ||
void * | context, | ||
unsigned int | notifyFlags | ||
) |
The kvSetNotifyCallback() function registers a callback function which is called when certain events occur.
You can register at most one callback function per handle at any time.
To remove the callback, call kvSetNotifyCallback() with a NULL
pointer in the callback argument.
[in] | hnd | An open handle to a CAN channel. |
[in] | callback | A pointer to a callback function of type kvCallback_t |
[in] | context | A pointer to arbitrary user-defined context data which is passed to the callback function. |
[in] | notifyFlags | One or more of the canNOTIFY_xxx flags. |
kvStatus kvReadDeviceCustomerData | ( | const CanHandle | hnd, |
int | userNumber, | ||
int | itemNumber, | ||
void * | data, | ||
size_t | bufsiz | ||
) |
Reading customer data works with Kvaser Leaf (of all types), Kvaser USBcan Professional, Kvaser Memorator Professional, Kvaser Eagle and Kvaser Memorator Light. To write customer data use external tools.
[in] | hnd | An open handle to a CAN channel. |
[in] | userNumber | Assigned by Kvaser. |
[in] | itemNumber | Must be zero (reserved) |
[out] | data | A pointer to a buffer of up to 8 bytes where the result will be placed. |
[in] | bufsiz | The size of the buffer that data points at. |
The kvDeviceSetMode() sets the mode.
[in] | hnd | An open handle to a CAN channel. |
[in] | mode | One of the kvDEVICE_MODE_xxx constants, defining which mode to use. |
The kvDeviceGetMode() reads the current device's specific mode.
[in] | hnd | An open handle to a CAN channel. |
[out] | result | A pointer to a 32-bit integer that will receive the kvDEVICE_MODE_xxx value. |
The kvReadTimer reads the hardware clock on the specified device and returns the value.
When the call to kvReadTimer() returns, the time value is already obsolete. The time required for the device firmware, any intermediary buses (like USB,) and the operating system to return the time value is not defined.
This call should be used instead of canReadTimer() because it can return an error code if it fails.
[in] | hnd | An open handle to a CAN channel. |
[out] | time | A pointer to a 32-bit unsigned integer that will receive the time value. |
The kvReadTimer64 reads the hardware clock on the specified device and returns the value.
When the call to kvReadTimer64() returns, the time value is already obsolete. The time required for the device firmware, any intermediary buses (like USB,) and the operating system to return the time value is not defined.
This call should be used instead of canReadTimer() because it can return an error code if it fails.
[in] | hnd | An open handle to a CAN channel. |
[out] | time | A pointer to a 64-bit unsigned integer that will receive the time value. |