![]() |
Once we have called canInitializeLibrary() to enumerate the connected Kvaser CAN devices, we can call canGetNumberOfChannels() to get the number of enumerated channels in our system.
We can then call canGetChannelData() for the CANlib channel numbers 0, 1, 2,…, n-1 (where n is the number returned by canGetNumberOfChannels()) to get information about that specific channel.
Example. This code snippet prints the number of enumerated channels found in the PC.
Use canGetChannelData() to obtain data for a specific channel, for example, the hardware type of the CAN interface.
To uniquely identify a device, we need to look at both the canCHANNELDATA_CARD_UPC_NO and canCHANNELDATA_CARD_SERIAL_NO.
Use canIoCtl() to obtain various pieces of information for a specific handle, or to perform special operations.
Example. This code snippet loops through all known channels and prints the type of the CAN card they're on.
See how-to/c/listChannels.c for code sample.
It is possible to set the customized name returned by canCHANNELDATA_CUST_CHANNEL_NAME on the device using Kvaser Device Guide by right clicking on the device channel and selecting "Edit Channel Name"
Note that if no channel name is set, canERR_NOT_IMPLEMENTED will be returned by canGetChannelData() when accessing canCHANNELDATA_CUST_CHANNEL_NAME.
CANlib supports virtual channels that you can use for development, test or demonstration purposes when you don't have any hardware installed.
To open a virtual channel, call canOpenChannel() with the appropriate channel number, and specify canOPEN_ACCEPT_VIRTUAL in the flags argument to canOpenChannel().