This is the last post in a 3-part series about using Python with Kvaser products:
- Accessing Kvaser CANlib from Python
- Using Python to connect to your remote device
- A more object oriented approach on accessing your Kvaser device from Python
Earlier we have seen how to use the canlib.py and kvrlib.py wrappers in Python (currently for v2.7). However, those are primarily just “wrappers” and do not take into account the flexibility we get with an object oriented language as Python (this is equally true for other wrappers like C#).
During testing, the focus is often on a specific device instead of the channel centered CANlib. This is especially true when you are dealing with remote devices such as Kvaser BlackBird v2 and Ethercan that tend to turn up on new CANlib channels when connected remotely. This is now taken care of via the new Python module kvDevice.
To open a specific device, supply the EAN and serial number as shown below.
If we have a device with EAN and serial number that matches we get the following output:
If we do not specify the serial number, we get the first device that matches the EAN. It is also possible to specify a CANlib channel directly.
As a final example, if the specified device is not found, we still get a device returned but we do not get any information about it.
If you take a look inside the module kvDevice.py
, you’ll notice that most of the attributes are stored in names starting with an underscore (_driver
, _channel
and so on). This tries to denote that these values are the last known values. (In Python, a leading underscore is normally a weak “internal use” indicator.) That is, the device could now have been removed and perhaps also reinserted and thus got renumbered, but the last time the device was opened via kvDevice.py
, it was found using those values. (The device was found on CANlib channel _channel
using the driver name _driver
.)
Hopefully, this overview of how Python can be used to help manage Kvaser devices will help you to be even more productive in your role as a developer.
EDIT 2015-05-22: Stated that the current wrappers are written for Python v2.7.
Comments? Â Contact us directly at support@kvaser.com.