Kvaser Linux CANLIB

Programmer's Overview

The CANLIB API consists exclusively of functions. Most of the functions return a status code of type canStatus, which is a negative number if the call failed and canOK (zero) if the call succeeded.

Several functions accept pointer arguments. In most cases where an argument is a pointer, NULL can be passed.

The first call to the library must be a call to canInitializeLibrary(). This function will initialize the library.

The next call is likely to be a call to canOpenChannel(), which returns a handle to a specific CAN circuit. This handle is then used to all subsequent calls to the library.

canOpenChannel() may return several different error codes, one of which is canERR_NOTFOUND. This means that the channel specified in the first parameter was not found. This is usually caused by a hardware or setup problem. Please refer to the troubleshooting guide if this occurs.

Next, suitable bus parameters should be set. This is done by a call to canSetBusParams(). CANLIB provides several default parameter settings for the most common bus speeds (for example, 1M, 500k, 250k and 125k).

When this is done, we can safely go on-bus by calling canBusOn().

You transmit messages by calling canWrite(). Received messages are buffered by CANLIB and can be read by calling canRead() or any of its relatives. Windows programmers may want to have a notification when a CAN message arrives; this is done by calling canSetNotify.

You can temporarily take the circuit off-bus by calling canBusOff(). Final circuit cleanup is done by calling canClose().