Kvaser Linux CANLIB

Chips and Channels

A CAN interface card often have more than one CAN chip. You allocate a handle to a certain CAN chip by calling canOpenChannel(). This routine takes two arguments, the first of which is the number of the desired channel. The channel numbering is dependent on the hardware you are using.

Note:
If you have e.g. a LAPcan, the channels are numbered 0 and 1. If you have a USBcan Professional, the channels are numbered 0 and 1 according to the markings on the cables. Please refer to the hardware documentation.

You can enumerate the CAN channels in the system using canGetChannelData(). First call canGetNumberOfChannels() to get the number of channels in the system. Then call canGetChannelData() for channel numbers 0, 1, 2,…, n-1 where n is the number returned by canGetNumberOfChannels().

Two or more applications can share the same CAN controller. You can, for example, have one application send messages on the bus and another application that just monitors the bus. If this is not desired (for performance or other reasons) you can open an exclusive handle to a chip. This means that no other application can open a handle to the same chip. Do this by passing the canOPEN_EXCLUSIVE flag in the flags argument to canOpenChannel().

Note:
Never try to use a handle where a channel number is required, or vice versa. It might or might not succeed (because both handles and channel numbers are integers) but the result is not relibable and the code might break with a future release of the drivers.