Version Checking

CANlib versions are denoted by two numbers, the "major version" and the "minor version". Usually the version is presented as these two numbers separated by a period. For example, CANlib 3.6 has major version 3 and minor version 6.

You may want to make your application determine which version of CANlib is installed on the computer it is running on. There are several ways of obtaining version information.

First, it is necessary to observe that CANlib consists of several files, each one with a version number. Your application must check all these version numbers to be certain that all files are of the correct version.

As a rule, files in CANlib has two version numbers:

  1. The file version number. This consists of a major version number, a minor version number, and a build number. The file version number uniquely identifies a particular file but doesn't say much about which version of CANlib is installed on the computer.
  2. The file product number. This number uniquely identifies the version of CANlib that the file belongs to.

Use canGetVersionEx() to get the version of the CANlib API DLL. This function allows you to get both the file and the product version number of the API DLL.

Example. Checking version with canGetVersionEx()

union {
uint16_t C;
struct {
unsigned char Minor;
unsigned char Major;
// Using the argument canVERSION_CANLIB32_PRODVER will return the product version.
printf("%s %d.%d\n", "Found CANLib version", Version.Major, Version.Minor);

Use canGetChannelData() to get the version numbers of the second-level DLL and the driver file. This information may vary from channel to channel.

You can also use canGetChannelData() to obtain information about the firmware revision for a particular channel.

When testing the version numbers, it is good practice to allow a later version to be installed. That is, don't check for equality with a specific version number. Instead, check that the major version number of the installed version is greater than or equal to the desired version, and if it is equal, check that the minor version number of the installed version is greater than or equal to the desired version.

To check whether you have a specific version of CANlib installed, you can use canProbeVersion(). This function will simply return TRUE or FALSE depending on whether the version you desire is installed or not.

Example. Checking version with canProbeVersion()

// Make a version check for channel 0.
hnd = canOpenChannel(0, 0);
if (canProbeVersion(hnd, 3, 6, 0, 0)) {
printf("This is either 3.6 or later, or a beta\n");
} else {
printf("This is 3.5 or earlier\n");
// Hmm.. that is not entirely true, because this program wouldn't
// run on 3.5 or earlier. canProbeVersion() wasn't implemented then..
printf("This is precisely 3.6, or a beta\n");
} else {
printf("This is not 3.6\n");
printf("This is precisely 3.6\n");
} else {
printf("This is not 3.6, or it is a beta\n");