Developers

  • CANking

    CanKing for Windows is a CAN bus monitor and general-purpose diagnostic tool.

    Read more
  • REST API

    The REST API defines the set of HTTP commands and responses that a Kvaser device will understand

    Read more
  • Linux Drivers and SDK

    This package contains our drivers and SDK for developing in a Linux environment. Everything you’ll need to get started is included in one place.

    Read more

Latest from
Developer's Blog

  • Build and install signed Kvaser driver modules

    This is the second post in a 2-part series about Secure Boot and signing modules on Linux: Secure Boot on Linux systems Build and install signed Kvaser driver modules The first part was an overview of what Secure Boot actually is and how it affects 3:rd party modules. In this part we take a look ... Read More

  • Secure Boot on Linux systems

    This is the first post in a 2-part series about Secure Boot and signing modules on Linux: Secure Boot on Linux systems Build and install signed Kvaser driver modules What is Secure Boot? "Secure Boot" is a UEFI feature that appeared in 2012, with Windows 8 preinstalled computers. All current Ubuntu 64-bit (not 32-bit) versions ... Read More

  • Special converter conditions

    This is the final post in a 3-part series about using the Converter Library (kvlclib) in CANlib SDK: Writer formats and properties (1 of 3) Converting to plain ASCII (2 of 3) Special converter conditions (3 of 3) In the second part of this blog series, we created a simple program to convert a kme50 ... Read More

What is CANIib

We make it easy with a free, open SDK and a universal, hardware, independent API.

Kvaser's products can be more than just a CAN interface. They can be used for embedded systems, can be relied upon for complex applications and come in many form factors. Our products are your building blocks, and we want to make it easy for you to construct what you need.

Download CANIib

Get the SDK package with API and examples.

Download
Features

The REST API defines the set of HTTP commands and responses that a Kvaser device will understand.

SDK Contents

The REST API defines the set of HTTP commands and responses that a Kvaser device will understand.

Linux Drivers

This package contains our drivers and SDK for developing in a Linux environment. Everything you’ll need to get started is included in one place.

Documentation

The REST API defines the set of HTTP commands and responses that a Kvaser device will understand.

Most downloaded developer software

Access Kvaser downloads, including Kvaser drivers, documentation, software, firmware, and setup tools.

View all downloads

Explore CANLIB

Save time using our CANIib API specification and find the right functions for anything you need.

Look for an specific reference:

This field is required.

Browse the
full API

Go the CANIib help

User's Guide

What is CANLIB?

Is a software product from KVASER that provides support for different CAN interface boards.

Read more

Hello, CAN!

Let's start with a simple example.

Read more

Programmer's Overview

The CANLIB API consists exclusively of functions. Most of the functions return a status code of ...

Read more

Library Initialization

Calling canInitializeLibrary() initializes the CANLIB library. It is sufficient to call this routine once.

Read more

Library Deinitialization and Cleanup

Strictly speaking it is not necessary to clean up anything before terminating the application.

Read more

Chips and Channels

A CAN interface card often have more than one CAN chip.

Read more

Bus On / Bus Off

When the CAN controller is on bus, it is receiving messages and is sending acknowledge bits in response to all correctly received messages.

Read more

Reading Messages

Incoming messages are placed in a queue in the driver.

Read more

Sending Messages

Outgoing CAN messages are buffered in a transmit queue and sent on a First-In First-Out basis.

Read more

Handling Bus Errors

When a CAN controller detects an error, it transmits an error frame.

Read more

SJA1000 Error Codes

Many of our CAN interface boards use the SJA1000 CAN controller.

Read more

Threaded Applications

CANLIB supports programs with multiple threads as long as one important condition is met: A handle to a CAN circuit should be used in only one thread.

Read more

Examples

Special converter conditions

This function converts a kme50 log file to plain text and also looks for special conditions that can arise when converting a log file, overrun, data truncation, and change in output filename.

def convertEvents(kc):
    # Get estimated number of remaining events in the input file. This can be
    # useful for displaying progress during conversion.
    total = kc.eventCount()
    print("Converting about %d events..." % total)
    while True:
        try:
            # Convert events from input file one by one until EOF is reached
            kc.convertEvent()
            if kc.IsOutputFilenameNew():
                print("New output filename: %s" % kc.getOutputFilename())
                print("About %d events left to convert..." % kc.eventCount())
        except kvlc.KvlcEndOfFile:
            if kc.IsOverrunActive():
                print("NOTE! The extracted data contained overrun.")
                kc.resetOverrunActive()
            if kc.IsDataTruncated():
                print("NOTE! The extracted data was truncated.")
                kc.resetStatusTruncated()
            break

Using Python and environment variables

The downloaded Python sample directory now includes wrappers for both CANIib and kvrlib. To get an idea of how to use them, see the bottom of each wrapper file. E.g. the canlib.py can be used as seen below.

import time
import kvDevice

# Define some values and messages to send to our device
# In order to hide these secret messages, we write them encoded 😉
messages = [(1, "-Jung unccraf gb n sebt'f pne jura vg oernxf qbja?"),
            (2, "-Vg trgf gbnq njnl."),
            (3, "-Jul jnf fvk fpnerq bs frira?"),
            (4, "-Orpnhfr frira 'ngr' avar."),
            (5, "-Jung vf gur qvssrerapr orgjrra fabjzra naq fabjjbzra?"),
            (6, "-Fabjonyyf."),
            (7, "-Jurer qvq lbh svaq gurfr?"),
            (8, "-uggc://jjj.ynhtusnpgbel.pbz/wbxrf/jbeq-cynl-wbxrf")]


# We will be using the first Eagle device found connected to the PC
# For an introduction to the kvDevice object, see
# http://www.kvaser.com/developer-blog/object-oriented-approach-accessing-kvaser-device-python-3-3/
eagle_ean = "73-30130-00567-9"
dev = kvDevice.kvDevice(ean=eagle_ean)

# Open a handle to the device
dev.open()

# Load the t program into slot 0
dev.channel.scriptLoadFile(0, "envvar.txe")

# Start the program in slot 0
dev.channel.scriptStart(0)

# Our protocol states that we should wait until HostIdConnected is zero before trying to connect
print "Waiting for device to be free..."
# All calls to the kvScriptEnvarOpen() and kvScriptEnvvarGetXXX() functions are hidden in the
# envvar class inside canlib.py. Here we can access it directly with dev.channel.envvar.YYY
while dev.channel.envvar.HostIdConnected != 0:
    time.sleep(0.2)

# Now we try to connect by writing our unique id into the environment variable HostIdRequest.
# We wait until our connection was accepted, i.e. HostIdConnected contains our id.
print "Requesting connection..."
myHostId = 42
print "Waiting for device to connect..."
while dev.channel.envvar.HostIdConnected != myHostId:
    if dev.channel.envvar.HostIdConnected == 0:
        print "Requesting connection..."
        if dev.channel.envvar.HostIdRequest != myHostId:
            dev.channel.envvar.HostIdRequest = myHostId
        time.sleep(0.2)
print "Connected!"

# Start sending our messages to the device
for (severity, message) in messages:
    print "Sending message %d" % severity
    dev.channel.envvar.Severity = severity
    dev.channel.envvar.Message = message.encode('rot13')
    time.sleep(4)

print "Disconnect..."
dev.channel.envvar.HostIdRequest = 0

# Stop the script in slot 0
dev.channel.scriptStop(0)

Ask the Developers

Latest questions

{{dev_que.post_excerpt}}

  • {{dev_que.comments_count}}answers
  • {{dev_que.post_views}}views
  • {{dev_que.post_time[0]}}{{dev_que.post_time[1]}} ago by
  • {{dev_que.post_author}}
No Questions found.

Loading Questions...

Have something to ask?

Ask a question