canlib.kvrlib

Wrapper for the Kvaser kvrlib library

Some Kvaser devices, known as remote devices, can be connected via Ethernet (E.g. Kvaser Ethercan Light HS and Kvaser BlackBird v2) and you need to configure those devices before they are connected to your computer. This is where kvrlib comes into play with functions to discover and connect to a Kvaser Device on the network, making it accessible for the CANlib functions. The kvrlib also has functions to configure how the remote device connects to the network (e.g. dynamic/static IP). It also contains extra functions for wireless setup, such as scanning and getting connection status.

class canlib.kvrlib.Accessibility[source]

Bases: canlib.cenum.CEnum

kvrAccessibility_xxx

Remote device accessability status.

PRIVATE = 3
PROTECTED = 2
PUBLIC = 1
UNKNOWN = 0
class canlib.kvrlib.Address[source]

Bases: canlib.kvrlib.address._Address

An IP or MAC address

Variables:
classmethod from_c(c_addr)[source]

Create an Address object from a canlib.kvrlib.kvrAddress object

to_c()[source]

Create a canlib.kvrlib.kvrAddress from this object

class canlib.kvrlib.AddressInfo(adress1, address2, netmask, gateway, is_dhcp)

Bases: tuple

address2

Alias for field number 1

adress1

Alias for field number 0

gateway

Alias for field number 3

is_dhcp

Alias for field number 4

netmask

Alias for field number 2

class canlib.kvrlib.AddressType[source]

Bases: canlib.cenum.CEnum

kvrAddressType_xxx

Type of device address.

Note

Ports are currently not used.

IPV4 = 1
IPV4_PORT = 3
IPV6 = 2
MAC = 4
UNKNOWN = 0
class canlib.kvrlib.AddressTypeFlag(*args, **kwds)[source]

Bases: canlib.cenum.CFlag

kvrAddressTypeFlag_xxx

Flags for setting what addresses that should be returned by kvrDiscoveryGetDefaultAddresses().

ALL = <AddressTypeFlag.ALL: 255>
BROADCAST = <AddressTypeFlag.BROADCAST: 1>
STORED = <AddressTypeFlag.STORED: 2>
class canlib.kvrlib.Availability(*args, **kwds)[source]

Bases: canlib.cenum.CFlag

kvrAvailability_xxx

Device avalability flags.

FOUND_BY_SCAN = <Availability.FOUND_BY_SCAN: 1>
NONE = <Availability.NONE: 0>
STORED = <Availability.STORED: 2>
class canlib.kvrlib.BasicServiceSet[source]

Bases: canlib.cenum.CEnum

kvrBss_xxx

Basic Service Set.

ANY = 2
INDEPENDENT = 1
INFRASTRUCTURE = 0
class canlib.kvrlib.ConfigMode[source]

Bases: canlib.cenum.CEnum

kvrConfigMode_xxx

Configuration mode.

ERASE = 2
R = 0
RW = 1
class canlib.kvrlib.ConfigProfile(device, profile_number)[source]

Bases: object

A configuration profile of a remote-capable device

The active profile for a canlib.kvrlib.RemoteDevice, rdev, is accessed with:

profile = rdev.active_profile

Other profiles are accessed with profiles:

first = rdev.profiles[0]

See the documentation for canlib.kvrlib.RemoteDevice for more information on how to get ConfigProfile objects.

The specific configuration of a profile can be read:

xml_string = profile.read()

And it can also be written back:

profile.write(xml_string)

The password used by this object is taken from its parent RemoteDevice object. See that documentation for how to set the password.

XML_BUFFER_SIZE = 2046
channel_number

The CANlib channel number used to communicate with the device

Type:int
clear()[source]

Clear the configuration

This will also clear any previously set device password.

Note

This method requires the parent RemoteDevice to have the correct password.

info

A simplified version of the configuration

It is not necessary to know the configuration password to access this information. Note that the partial XML data returned is not enough to reconfigure a device.

Type:str
password

The password used to communicate with the device

Type:str
read()[source]

Read the configuration

Returns either an XML string, or None if there is no configuration.

Note that ConfigProfile.write can handle None; in other words:

xml = profile.read()

# Do anything, including writing new configurations
...

profile.write(xml)

Will always work even if xml is None. This would mean that the profile originally had an empty configuration, and it will once again have an empty configuration at the end.

Note

This method requires the parent RemoteDevice to have the correct password.

write(xml)[source]

Write the configuration area

This function takes as its single argument either an xml string that will be written to this profile, or None in which case the configuration will be cleared.

Note

This method requires the parent RemoteDevice to have the correct password.

class canlib.kvrlib.ConnectionStatus(state, tx_rate, rx_rate, channel_number, rssi, tx_power)

Bases: tuple

channel_number

Alias for field number 3

rssi

Alias for field number 4

rx_rate

Alias for field number 2

state

Alias for field number 0

tx_power

Alias for field number 5

tx_rate

Alias for field number 1

class canlib.kvrlib.ConnectionTest(config_handle)[source]

Bases: object

A connection test for a specific device

A connection test for a RemoteDevice, rdev, is created by:

test = rdev.connection_test()

While a connection test is running, the device will connect and start pinging itself to measure round-trip time (RTT) and Receive Signal Strength Indicator (RSSI).

A ConnectionTest is started with ConnectionTest.start and stopped with ConnectionTest.stop, after which its results are retrieved by ConnectionTest.results. If it is acceptable to block while the test is running, these three calls can be combined into ConnectionTest.run:

results = test.run(duration=10)
print(results)

Connection tests are automatically closed when garbage-collected, but they can also be closed manually with ConnectionTest.close.

close()[source]

Close the internal handle

results(maxresults=20)[source]

Get the results from a connection test

The test must have been running for any results to be available.

This function returns a ConnectionTestResult, which is a namedtuple of (rssi, rtt). Both rssi and rtt are tuples containing a number of individual results for RSSI and RTT.

Parameters:maxresults (int) – The maximum number of rssi and rtt numbers to return. The returned rssi and rtt will be tuples with this long or the number of results available long, whichever is shortest.
run(duration, maxresults=20)[source]

Run a connection test and return its results.

This function calls ConnectionTest.start, then blocks for duration seconds, then calls ConnectionTest.stop before finally returning the ConnectionTestResult from ConnectionTest.results.

Parameters:
  • duration (int) – Seconds to run the test for.
  • maxresults (int) – Passed to ConnectionTest.results as maxlen.
start()[source]

Start the connection test

stop()[source]

Stop the connection test

class canlib.kvrlib.ConnectionTestResult(rssi, rtt)

Bases: tuple

rssi

Alias for field number 0

rtt

Alias for field number 1

class canlib.kvrlib.DeviceInfo(device_info=None)[source]

Bases: object

Information about a device that can be written to the registry

See canlib.kvrlib.DeviceInfoSet for information about how to get DeviceInfo objects, process them, and then write them to the registry.

accessibility

The accessibility of this device

Type:canlib.kvrlib.Accessibility
availability

The availability of this device

Type:canlib.kvrlib.Availability
base_station_id

Address of the base station

Type:canlib.kvrlib.Address
client_address

Address of connected client

Type:canlib.kvrlib.Address
connect

Whether the service should connect to this device

Type:bool
device_address

Address of remote device

Type:canlib.kvrlib.Address
ean

EAN of device

Type:canlib.ean.EAN
encryption_key

The encryption key to use when encrypting communication

Note

This attribute is write-only.

Type:bytes
firmware_version

Firmware version

Type:canlib.versionnumber.VersionNumber
hostname

DNS hostname if available, otherwise an empty string

Type:str
info()[source]

Create a string with information about the DeviceInfo

To be used when the str() representation is not detailed enough.

name

User-defined name of device

Type:str
password

The accessibility password to use when connecting to a device

Note

This attribute is write-only.

Type:str
serial

The serial number of the device

Type:int
service_status

A tuple with the service status of the device

The returned tuple has the format (state, start_info, text), where state is a canlib.kvrlib.ServiceState, start_info is a canlib.kvrlib.StartInfo, and text is a str with local connection status.

Type:canlib.kvrlib.ServiceStatus
stored

Whether this DeviceInfo was read from the registry

Type:bool
update(other)[source]

Update the attributes of this instance

This function takes a dict, and will set the attributes given by the keys to the corresponding value (on this object).

usage

Usage status (Free/Remote/USB/Config)

Type:canlib.kvrlib.DeviceUsage
class canlib.kvrlib.DeviceInfoSet(iterable=None)[source]

Bases: _abcoll.MutableSet

A mutable set of DeviceInfo objects that can be written to the registry

There are three different functions for creating DeviceInfoSet objects:

empty_info_set
Creates an empty set.
stored_info_set
Creates a set from the device information stored in the registry.
discover_info_set
Create a set from the results of a canlib.kvrlib.Discovery.

Once a DeviceInfoSet has been created it can be modified as a normal set, and the DeviceInfo elements can also be modified. Once all modification is done, the set can be written to the registry with DeviceInfoSet.store.

The main difference between DeviceInfoSet and normal sets is that it can only contain one DeviceInfo with a specific combination of EAN and serial number, even if they otherwise are not equal. This means that even if info in infoset evaluates to true, that exact object may not be in the set, and modifying it may not change the set.

To retrieve a specific DeviceInfo from the set use DeviceInfoSet.find:

info = infoset.find(ean='01234-5', serial=42)

Modifying the resulting DeviceInfo will then change the contents of the set.

Instances of this class can also be used as context managers, in which case they will write their content to the registry when the context exists.

add(info)[source]

Add a DeviceInfo to this DeviceInfoSet

Parameters:info (DeviceInfo) – The element to add to this set

If the set already contains a DeviceInfo with the same EAN and serial number as info, the previous DeviceInfo will be discarded and replaced by info.

discard(info)[source]

Remove an element. Do not raise an exception if absent.

find(ean, serial)[source]

Find and return a specific DeviceInfo in this set

Parameters:
  • ean (canlib.ean.EAN) – The EAN to search for
  • serial (int) – The serial number to search for

If no DeviceInfo with the EAN and serial number is found in this set, canlib.kvrlib.DeviceNotInSetError is raised.

Note that there can never be more than one DeviceInfo with the same EAN and serial number in a DeviceInfoSet.

find_remove(ean, serial)[source]

Find a specific DeviceInfo and remove it from this set

Like DeviceInfoSet.find but immediately removes the DeviceInfo found from the set.

Parameters:
  • ean (canlib.ean.EAN) – The EAN to search for
  • serial (int) – The serial number to search for
has(ean, serial)[source]

Check whether the set contains a specific DeviceInfo

Similar to DeviceInfoSet.find but instead of returning a DeviceInfo or raising an exception, this function returns True or False.

Parameters:
  • ean (canlib.ean.EAN) – The EAN to search for
  • serial (int) – The serial number to search for
new_info(ean, serial, **attrs)[source]

Create and return new DeviceInfo in this set

Any attribute of the DeviceInfo that should have a specific value can be passed as keyword arguments to this function.

The EAN and serial number must be provided.

Parameters:

If the set already contains a DeviceInfo with the EAN ean and serial number serial, the previous DeviceInfo will be discarded and replaced by the new DeviceInfo created by this function.

store()[source]

Store this set’s DeviceInfo objects in the registry

update(*others)[source]

Update the set, adding elements from all others

All others must contain nothing but DeviceInfo objects, or this function will raise TypeError without modifying this DeviceInfoSet.

exception canlib.kvrlib.DeviceNotInSetError[source]

Bases: exceptions.KeyError, canlib.exceptions.CanlibException

class canlib.kvrlib.DeviceUsage[source]

Bases: canlib.cenum.CEnum

kvrDeviceUsage_xxx

Remote device usage status.

CONFIG = 4
FREE = 1
REMOTE = 2
UNKNOWN = 0
USB = 3
class canlib.kvrlib.Discovery(handle)[source]

Bases: object

A kvrlib “Discovery” process

Most of the time the discovery process can be handled by canlib.kvrlib.discover_info_set, which returns the results of the discovery as a canlib.kvrlib.DeviceInfoSet.

Even when interacted with directly, instnances of this class are normally not instantiated directly, but created using canlib.kvrlib.start_discovery, or sometimes using canlib.kvrlib.openDiscovery.

Instances of this class can be used as context handlers, in which case the discovery will be closed when the context is exited. The discovery will also be closed when the instance is garbage collected, if it hasn’t already.

addresses

The list of addresses to use for discovery

Note

This attribute is write-only.

This attribute should be a list of canlib.kvrlib.Address objects.

If the Discovery object was created by canlib.kvrlib.start_discovery, the addresses are automatically set. Otherwise, they must be assigned before Discovery.start can be called.

close()[source]

Close the discovery process

This function is called when the Discovery object is garbage-collected.

If the Discovery object is used as a context handler, this function will be called when the context exits.

results()[source]

Return an iterator of the result from the discovery

The results are yielded as DeviceInfo objects.

start(delay, timeout, report_stored=True)[source]

Run the discovery

If the Discovery object was created by canlib.kvrlib.start_discovery, the discovery has already been run, and this function does not need to be called.

After the discovery has been run, its results can be retrieved using Discovery.results.

Parameters:
  • delay (int) – The millisecond delay between sending discovery messages to addresses in the address list.
  • timeout (int) – The millisecond timeout after all discovery messages have been sent, before returning.
  • report_stored (bool) – if True (the default), stored devices will be discovered.
class canlib.kvrlib.Error[source]

Bases: canlib.cenum.CEnum

BLANK = -6
BUFFER_TOO_SMALL = -15
CHECKSUM = -3
DUPLICATED_DEVICE = -13
GENERIC = -2
NOT_IMPLEMENTED = -9
NOT_INITIALIZED = -1
NO_ANSWER = -8
NO_DEVICE = -7
NO_SERVICE = -12
OUT_OF_SPACE = -11
PARAMETER = -4
PASSWORD = -5
PERMISSION_DENIED = -10
XML_VALIDATION = -14
exception canlib.kvrlib.KvrBlank[source]

Bases: canlib.kvrlib.exceptions.KvrError

status = -6
exception canlib.kvrlib.KvrError[source]

Bases: canlib.exceptions.DllException

class canlib.kvrlib.KvrLib(debug=None)[source]

Bases: object

Deprecated wrapper class for the Kvaser kvrlib.

Deprecated since version 1.5.

All functionality of this class has been moved to the kvrlib module itself:

# deprecated
from canlib import kvrlib
cl = kvrlib.KvrLib()  # or kvrlib.Kvrlib()
cl.functionName()

# use this instead
from canlib import kvrlib
kvrlib.functionName()
dll = <canlib.kvrlib.dll.KvrlibDll object>
ean2ean_hi[source]

Using KvrLib static functions is deprecated, all functionality has been moved to the kvrlib module itself.

ean2ean_lo[source]

Using KvrLib static functions is deprecated, all functionality has been moved to the kvrlib module itself.

ean_hi_lo2ean[source]

Using KvrLib static functions is deprecated, all functionality has been moved to the kvrlib module itself.

class canlib.kvrlib.NetworkState[source]

Bases: canlib.cenum.CEnum

kvrNetworkState_xxx

States for network connection.

AUTHENTICATING = 8
AUTHENTICATION_FAILED = 9
CONNECTED = 7
CONNECTING = 6
CONNECTION_DELAY = 5
FAILED_MIC = 11
INITIALIZING = 3
INVALID = 1
NOT_CONNECTED = 4
ONLINE = 10
STARTUP = 2
UNKNOWN = 0
class canlib.kvrlib.RegulatoryDomain[source]

Bases: canlib.cenum.CEnum

kvrRegulatoryDomain_xxx

Regulatory domain.

CHINA_MII = 4
EUROPE_ETSI = 1
JAPAN_TELEC = 0
NORTH_AMERICA_FCC = 2
WORLD = 3
class canlib.kvrlib.RemoteDevice(channel_number, password)[source]

Bases: object

A remote-capable Kvaser device

This class is normally instantiated with canlib.kvrlib.openDevice:

rdev = kvrlib.openDevice(CHANNEL_NUMBER)

Once this is done, the currently active profile can be accessed:

active = rdev.active_profile

All profiles, including the active one, are canlib.kvrlib.ConfigProfile objects, see that documentation for all the operations available for profile objects.

The full list of profiles a device has can be inspected using rdev.profiles. This is a RemoteDevice.ProfileList object, which works much like a list:

# The profile list can be indexed
first = rdev.profiles[0]

# We can check if a configuration belongs to this device with 'in'
assert first in rdev.profiles

# The length of the profile list is the number of profiles
num_profiles = len(rdev.profiles)

# Using the number of profiles, we can get the last one
last = rdev.profiles[num_profiles - 1]

# But negative indexes also work and are a better way of getting
# the last profile
last = rdev.profiles[-1]

# You can also iterate over all profiles
for profile in rdev.profiles:
    ...

RemoteDevice also lets you access a variety of information about the specific device, as well as the ability to do a WLAN scan with RemoteDevice.wlan_scan.

If the device is password protected, that password can be passed to canlib.kvrlib.openDevice:

protected_device = kvrlib.openDevice(0, password="Once upon a playground rainy")

After the object is created, the password is available as:

password = protected_device.password

The password can be changed with:

protected_device.password = "Wolves without teeth"

The reason the password is stored as clear-text is because it must be supplied to the underlying library each time an operation is done using this and related classes. This also means that the password is only validated, and required, when one of the functions requiring a password is called.

If the device is not password-protected, the password should be an empty string:

unprotected_device = kvrlib.openDevice(1)
assert unprotected_device.password == ''
class ProfileList(channel_number)[source]

Bases: object

The available profiles in a remote-capable device

This is the type of RemoteDevice.profiles. It implements the following:

  • len(profiles)
  • profile in profiles
  • profile[index]
active_profile

The currently active profile

Activating another profile is done by assigning this attribute to another profile:

new_profile = remote_device.profiles[index]
remote_device.active_profile = new_profile

The value assigned to this property must be a canlib.kvrlib.ConfigProfile that belongs to this device, i.e. the following must be True:

new_profile in remote_device.profiles
Type:canlib.kvrlib.ConfigProfile
address_info

Information about network address settings

Note

Accessing this attribute requires the correct password be set on the object.

Type:canlib.kvrlib.AddressInfo
connection_status

Connection status information

The returned tuple is a (state, tx_rate, rx_rate, channel, rssi, tx_power) namedtuple of:

  1. state (canlib.kvrlib.NetworkState): Network connection state
  2. tx_rate (int): Transmit rate in kbit/s
  3. rx_rate (int): Receive rate in kbit/s
  4. channel (int): Channel
  5. rssi (int): Receive Signal Strength Indicator
  6. tx_power (int): Transmit power level in dB

Note

Accessing this attribute requires the correct password be set on the object.

Type:canlib.kvrlib.ConnectionStatus
connection_test()[source]

Creates a connection test for this device

Returns:canlib.kvrlib.ConnectionTest

See the documentation of canlib.kvrlib.ConnectionTest for more information.

Note

Accessing this attribute requires the correct password be set on the object.

hostname

Device’s hostname

Note

Accessing this attribute requires the correct password be set on the object.

Type:str
password_valid()[source]

Checks whether the password set is valid

Returns:boolTrue if the password is valid, False otherwise.
wlan_scan(active=False, bss_type=<BasicServiceSet.ANY: 2>, domain=<RegulatoryDomain.WORLD: 3>)[source]

Creates and starts a wlan scan for this device

Returns:canlib.kvrlib.WlanScan

See the documentation of canlib.kvrlib.WlanScan for more information.

Note

Accessing this attribute requires the correct password be set on the object.

class canlib.kvrlib.RemoteState[source]

Bases: canlib.cenum.CEnum

kvrRemoteState_xxx

State of connection to device.

AVAILABLE = 1
CLOSING = 10
CONFIG_CHANGED = 13
CONNECTION_DOWN = 5
CONNECTION_UP = 6
DISCOVERED = 2
INSTALLING = 15
REDISCOVER = 7
REDISCOVER_PENDING = 9
REMOVE_ME = 11
STANDBY = 12
STARTED = 4
STARTING = 3
STOPPING = 14
UNWILLING = 8
VOID = 0
class canlib.kvrlib.ServiceState[source]

Bases: canlib.cenum.CEnum

kvrServiceState_xxx

Current service state.

AVAILABLE = 1
CLOSING = 10
CONFIG_CHANGED = 13
CONNECTION_DOWN = 5
CONNECTION_UP = 6
DISCOVERED = 2
INSTALLING = 15
REDISCOVER = 7
REDISCOVER_PENDING = 9
REMOVE_ME = 11
STANDBY = 12
STARTED = 4
STARTING = 3
STOPPING = 14
UNWILLING = 8
VOID = 0
class canlib.kvrlib.ServiceStatus(state, start_info, text)

Bases: tuple

start_info

Alias for field number 1

state

Alias for field number 0

text

Alias for field number 2

class canlib.kvrlib.StartInfo[source]

Bases: canlib.cenum.CEnum

kvrStartInfo_xxx

Current start information.

ERR_CONFIGURING = 5
ERR_ENCRYPTION_PWD = 7
ERR_IN_USE = 2
ERR_NOTME = 4
ERR_PARAM = 6
ERR_PWD = 3
NONE = 0
START_OK = 1
class canlib.kvrlib.WEPKeys(key64, key128)

Bases: tuple

key128

Alias for field number 1

key64

Alias for field number 0

class canlib.kvrlib.WlanScan(config_handle)[source]

Bases: object

A wlan scan for this device

The device starts scanning as soon as this object is created by RemoteDevice.wlan_scan:

scan = rdev.wlan_scan()

When calling RemoteDevice.wlan_scan, you can also specify whether the scan should be an active one, the Basic Service Set (bss) to use, and the regulatory domain:

scan = rdev.wlan_scan(
    active=True,
    bss=kvrlib.BasicServiceSet.INFRASTRUCTURE,
    domain=kvrlib.RegulatoryDomain.EUROPE_ETSI,
)

Results from the scan are retrieved by iterating over the WlanScan object:

for result in scan:
print(result)

When getting the next result, the code will block until a new result is available or until no more results are available, in which case the iteration stops.

Wlan scans are automatically closed when garbage-collected, but they can also be closed manually with WlanScan.close.

close()[source]

Closes the internal handle

class canlib.kvrlib.WlanScanResult(rssi, channel_number, mac, bss_type, ssid, security_text)

Bases: tuple

bss_type

Alias for field number 3

channel_number

Alias for field number 1

mac

Alias for field number 2

rssi

Alias for field number 0

security_text

Alias for field number 5

ssid

Alias for field number 4

canlib.kvrlib.addressFromString(type, address)[source]
canlib.kvrlib.configActiveProfileGet(channel)[source]
canlib.kvrlib.configActiveProfileSet(channel, profile_number)[source]
canlib.kvrlib.configNoProfilesGet(channel)[source]
canlib.kvrlib.deviceGetServiceStatus(device_info)[source]
canlib.kvrlib.deviceGetServiceStatusText(device_info)[source]
canlib.kvrlib.discover_info_set(delay=100, timeout=1000, addresses=None, report_stored=True)[source]
canlib.kvrlib.dllversion()[source]

Get the kvrlib version number as a str

canlib.kvrlib.ean2ean_hi(ean)[source]

Return EAN high part.

Returns the high part of the supplied EAN as an integer. Calling ean2ean_hi(ean=”73-30130-00671-3”) returns 0x73301.

canlib.kvrlib.ean2ean_lo(ean)[source]

Return EAN low part.

Returns the low part of the supplied EAN as an integer. Calling ean2ean_lo(ean=”73-30130-00671-3”) returns 0x30006713.

canlib.kvrlib.ean_hi_lo2ean(ean_hi, ean_lo)[source]

Build EAN from high and low part.

Returns the EAN as a string built from high and low parts in integer format. Calling ean_hi_lo2ean(ean_hi=0x73301, ean_lo=0x30006713) returns “73-30130-00671-3”.

canlib.kvrlib.empty_info_set()[source]
canlib.kvrlib.generate_wep_keys(pass_phrase)[source]

Generates four 64-bit and one 128-bit WEP keys

Parameters:pass_phrase (str) – The pass phrase to use to generate the keys.

Returns a (key64, key128) (WEPKeys) namedtuple, where key64 is a list of four bytes object with the four 64-bit WEP keys, and where `key128 is a bytes object with the single 128-bit WEP key.

canlib.kvrlib.generate_wpa_keys(pass_phrase, ssid)[source]

Generate a WPA key from a pass phrase and ssid

Parameters:
  • pass_phrase (str) – The pass phrase to use to generate the key.
  • ssid (str) – The SSID to use to generate the key.
Returns:

bytes – The generated WPA key.

canlib.kvrlib.getVersion[source]

Get the kvrlib version number as a str

Deprecated since version 1.5: Use dllversion instead.

canlib.kvrlib.get_default_discovery_addresses(broadcast=True, stored=False)[source]

Retrieve the default discovery addresses

Parameters:
  • broadcast (bool) – If True (the default), then the returned list will contain broadcast addresses.
  • stored (bool) – If True (defaults to False), then the returned list will contain earlier stored addresses.

If both arguments are False, a ValueError will be raised.

Retruns a list of canlib.kvrlib.Address objects.

canlib.kvrlib.hostname(ean, serial)[source]

Generate a hostname from ean and serial number

Parameters:
  • ean `EAN` – European Article Number
  • serial `int` – Serial number
canlib.kvrlib.initializeLibrary()[source]
canlib.kvrlib.kvrAccessibility

alias of canlib.kvrlib.enums.Accessibility

class canlib.kvrlib.kvrAddress[source]

Bases: _ctypes.Structure

TypeText = {0: 'UNKNOWN', 1: 'IPV4', 2: 'IPV6', 3: 'IPV4_PORT', 4: 'MAC'}
Type_IPV4 = 1
Type_IPV4_PORT = 3
Type_IPV6 = 2
Type_MAC = 4
Type_UNKNOWN = 0
address

Structure/Union member

type

Structure/Union member

class canlib.kvrlib.kvrAddressList(num_of_structs=20)[source]

Bases: _ctypes.Structure

STRUCT_ARRAY

Structure/Union member

elements

Structure/Union member

canlib.kvrlib.kvrAvailability

alias of canlib.kvrlib.enums.Availability

canlib.kvrlib.kvrBlank

alias of canlib.kvrlib.exceptions.KvrBlank

class canlib.kvrlib.kvrConfig(kvrlib=None, channel=0, mode=0, password='', profile_no=0)[source]

Bases: object

MODE_ERASE = 2
MODE_R = 0
MODE_RW = 1
XML_BUFFER_SIZE = 2046
clear()[source]
close()[source]
getXml()[source]
openEx(channel=None, mode=None, password=None, profile_no=None)[source]
setXml()[source]
class canlib.kvrlib.kvrDeviceInfo[source]

Bases: _ctypes.Structure

accessibility

Structure/Union member

accessibility_pwd

Structure/Union member

availability

Structure/Union member

base_station_id

Structure/Union member

client_address

Structure/Union member

connect()[source]
device_address

Structure/Union member

disconnect()[source]
ean_hi

Structure/Union member

ean_lo

Structure/Union member

encryption_key

Structure/Union member

fw_build_ver

Structure/Union member

fw_major_ver

Structure/Union member

fw_minor_ver

Structure/Union member

host_name

Structure/Union member

name

Structure/Union member

request_connection

Structure/Union member

reserved1

Structure/Union member

reserved2

Structure/Union member

ser_no

Structure/Union member

struct_size

Structure/Union member

usage

Structure/Union member

class canlib.kvrlib.kvrDeviceInfoList(deviceInfos)[source]

Bases: _ctypes.Structure

STRUCT_ARRAY

Structure/Union member

elements

Structure/Union member

canlib.kvrlib.kvrDeviceUsage

alias of canlib.kvrlib.enums.DeviceUsage

class canlib.kvrlib.kvrDiscovery(kvrlib=None)[source]

Bases: object

clearDevicesAtExit(onoff)[source]
close()[source]
classmethod getDefaultAddresses(addressTypeFlag=<AddressTypeFlag.BROADCAST: 1>, listSize=20)[source]
getResults()[source]
setAddresses(addressList)[source]
setEncryptionKey(device_info, key)[source]
setPassword(device_info, password)[source]
setScanTime(delay_ms, timeout_ms)[source]
start(delay_ms=None, timeout_ms=None)[source]
storeDevices(deviceInfos)[source]
canlib.kvrlib.kvrError

alias of canlib.kvrlib.exceptions.KvrError

class canlib.kvrlib.kvrVersion[source]

Bases: _ctypes.Structure

major

Structure/Union member

minor

Structure/Union member

canlib.kvrlib.kvrlib

alias of canlib.kvrlib.wrapper.KvrLib

canlib.kvrlib.openDevice(channel_number, password='', validate_password=False)[source]

Create a RemoteDevice object bound to a channel number

Parameters:
  • channel_number (int) – CANlib channel number of the device to open
  • password (str) – Password of the device, if any
  • validate_password (bool) – Whether the password should be validated (defaults to False).

This function checks that a remote-capable device is currently connection on the channel channel_number. If validate_password is True, it also checks that the password supplied is correct. If any of these checks fail, a ValueError will be raised.

canlib.kvrlib.openDiscovery()[source]

Creates and returns a canlib.kvrlib.Discovery object

Device discovery is normally done using canlib.kvrlib.discover_info_set.

canlib.kvrlib.set_clear_stored_devices_on_exit(val)[source]

Sets whether kvrlib should clear stored devices when the application exist

canlib.kvrlib.start_discovery(delay, timeout, addresses=None, report_stored=True)[source]

Start and return a canlib.kvrlib.Discovery

Device discovery is normally done using canlib.kvrlib.discover_info_set.

The returned object should usually be used as a context handler:

with kvrlib.start_discovery(delay=100, timeout=1000) as disc:
    for result in disc.results():
        # process the discovery result
        print(result)
canlib.kvrlib.store_devices(devices)[source]

Store a collection of canlib.kvrlib.DeviceInfo objects in the registry

See canlib.kvrlib.DeviceInfoSet for a simpler way of dealing with device infos and the registry.

Note

Previously stored devices are cleared.

canlib.kvrlib.stored_devices()[source]

Read the devices stored in the registry as a tuple of canlib.kvrlib.DeviceInfo objects

canlib.kvrlib.stored_info_set()[source]
canlib.kvrlib.stringFromAddress(address)[source]
canlib.kvrlib.unload()[source]
canlib.kvrlib.verify_xml(xml_string)[source]

Verify that the xml string complies with both the DTD and internal restrictions