How to Setup Kvaser on Linux [Ubuntu]

Method 1: Set up to use CANLIB (library from Kvaser, if you want to use socketcan, skip to method 2)

  1. The download page for all necessary files can be accessed here: https://www.kvaser.com/downloads-kvaser/
  2. Install drivers according to this tutorial after download the Kvaser LINUX Driver and SDK file. I tested it on Ubuntu 16.04, and it’s still working.

 

3. To use Kavaser with Python, you need canlib library. To install canlib for python on linux, follow the instruction here after download the latest Python Module from the Download page.

4. More detail on canlib codes: https://github.com/Kvaser/canlib-samples

Method 2: Setup to use with Socketcan

This method is a lot more simple, there is no need for any driver set up. 

  1. Install can-ultils (for socketcan): sudo apt-get install can-utils
  2. Connect Kvaser to PC
  3. Enable CAN, in this example, I use 500000. Change this bitrate to your required speed:
    sudo modprobe can
    sudo modprobe can_raw
    sudo ip link set can0 type can bitrate 5000000
    sudo ip link set up can0
  4. Your Kvaser can port is enable with name can0, run ifconfig -a and can0 should show up. Connect Kvaser to another CAN device that is sending out data, then on terminal enter candump can0
    Note: After PC restarts, you will have to re-run these commands if you want to enable Socketcan for Kvaser device again. To save time, you can save these in a bash script and load from the bash script. 
  5. To use Socketcan in Python codes, check out Python-can

Refer to the resource below to use can-ultils on termial to test send and receive can messages on terminal. If you don’t have another CAN device to test send and receive, you can also create virtual can channel to do the work.

https://elinux.org/Bringing_CAN_interface_up

https://sgframework.readthedocs.io/en/latest/cantutorial.html

https://stackoverflow.com/questions/33574256/socket-can-virtual-bus

 

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s