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

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 CANlib SDK includes libraries, examples, support for virtual channels and TRX, an IDE for developing t programs.

SDK Contents

The software development kit includes everything you need including virtual hardware so you can get started right away.

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 SDK includes supplementary documentation, but copies are also available for download from our Downloads page including our guide to t programming.

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)

Support

Support cases are managed through the JIRA platform. Please check your Spam folder if you do not receive a JIRA email confirmation after submitting a support request.