Developer Blog

06/05/2015 by Magnus Carlsson

Was that the CANlib channel number or Card Number?

When interacting with CANlib, many functions need a handle to a channel. This channel is often referred to as the “CANlib Channel” because this is how it is labeled in Kvaser Hardware.

CANlib SDK

If we want to send CAN messages from the first channel on the Eagle device, we should open CANlib channel three canopenChannel(3, canOPEN_EXCLUSIVE). Some functions in CANlib are independent of the actual channel on the device and therefore you could use any device channel with equal success. For example, to turn the device LEDs on or off you call kvFlashLeds(hnd, kvLED_ACTION_ALL_LEDS_ON) where hnd could be a handle for CANlib channel three or four. So why the need for a Card Number? Well, historically, all interaction with Kvaser devices that did not go through the Kvaser CANlib was directed to the driver directly. In this case the CANlib channel number could not be used an thus a new number was needed to indicate e.g. “the second device” using the driver kcany. This new number was called the “Card Number” and is shown in Kvaser Hardware when a device channel is selected.

CANlib SDK

In the figure above, we can see that the Kvaser Memorator Pro 5xHS, which is a five channel device, is connected to CANlib channel six and Card Number two. Both the CANlib channel and Card Number is starting from zero (as programmers usually do), but through some random act of fate, the Card Number is presented in Kvaser Hardware (and in Kvaser Hardware only) as if it was started from one. So our device is actually connected to CANlib channel six but Card Number one which means that we need to issue the command hydra_flash.exe -C1 imagefile.img in order to upgrade the firmware of this device. Nowadays, this is little more than a historical anecdote since we get the zero indexed Card Number by calling CANlib (canGetChannelData(channel, canCHANNELDATA_CARD_NUMBER, buffer, bufsize)). This is also how the Python module kvDevice does it in order to assist you when interfacing other libraries (such as kvmlib) that uses the Card Number. Still, it is fun to know how stuff works…

Comments?  Contact us directly at support@kvaser.com.

Author Image

Magnus Carlsson

Magnus Carlsson is a Software Developer for Kvaser AB and has developed firmware and software for Kvaser products since 2007. He has also written a number of articles for Kvaser’s Developer Blog dealing with the popular Python language.