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: - type (
canlib.kvrlib.AddressType
) – Address type. - address (
list[int]
) – A list of integers, the numbers in the address.
-
classmethod
from_c
(c_addr)[source]¶ Create an
Address
object from acanlib.kvrlib.kvrAddress
object
-
to_c
()[source]¶ Create a
canlib.kvrlib.kvrAddress
from this object
- type (
-
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 getConfigProfile
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 handleNone
; in other words:xml = profile.read() # Do anything, including writing new configurations ... profile.write(xml)
Will always work even if
xml
isNone
. 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 withConnectionTest.start
and stopped withConnectionTest.stop
, after which its results are retrieved byConnectionTest.results
. If it is acceptable to block while the test is running, these three calls can be combined intoConnectionTest.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
.-
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)
. Bothrssi
andrtt
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 returnedrssi
andrtt
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 forduration
seconds, then callsConnectionTest.stop
before finally returning theConnectionTestResult
fromConnectionTest.results
.Parameters: - duration (
int
) – Seconds to run the test for. - maxresults (
int
) – Passed toConnectionTest.results
asmaxlen
.
- duration (
-
-
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 getDeviceInfo
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)
, wherestate
is acanlib.kvrlib.ServiceState
,start_info
is acanlib.kvrlib.StartInfo
, andtext
is astr
with local connection status.Type: canlib.kvrlib.ServiceStatus
-
stored
¶ Whether this
DeviceInfo
was read from the registryType: 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 registryThere 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 theDeviceInfo
elements can also be modified. Once all modification is done, the set can be written to the registry withDeviceInfoSet.store
.The main difference between
DeviceInfoSet
and normal sets is that it can only contain oneDeviceInfo
with a specific combination of EAN and serial number, even if they otherwise are not equal. This means that even ifinfo 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 useDeviceInfoSet.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 thisDeviceInfoSet
Parameters: info ( DeviceInfo
) – The element to add to this setIf the set already contains a
DeviceInfo
with the same EAN and serial number asinfo
, the previousDeviceInfo
will be discarded and replaced byinfo
.
-
find
(ean, serial)[source]¶ Find and return a specific
DeviceInfo
in this setParameters: - 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 aDeviceInfoSet
.- ean (
-
find_remove
(ean, serial)[source]¶ Find a specific
DeviceInfo
and remove it from this setLike
DeviceInfoSet.find
but immediately removes theDeviceInfo
found from the set.Parameters: - ean (
canlib.ean.EAN
) – The EAN to search for - serial (
int
) – The serial number to search for
- ean (
-
has
(ean, serial)[source]¶ Check whether the set contains a specific
DeviceInfo
Similar to
DeviceInfoSet.find
but instead of returning aDeviceInfo
or raising an exception, this function returnsTrue
orFalse
.Parameters: - ean (
canlib.ean.EAN
) – The EAN to search for - serial (
int
) – The serial number to search for
- ean (
-
new_info
(ean, serial, **attrs)[source]¶ Create and return new
DeviceInfo
in this setAny 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: - ean (
canlib.ean.EAN
) – The EAN of the info (DeviceInfo.ean
) - serial (
int
) – The serial number of the info (DeviceInfo.serial
) - **attrs – Any other attributes to be set on the
DeviceInfo
If the set already contains a
DeviceInfo
with the EANean
and serial numberserial
, the previousDeviceInfo
will be discarded and replaced by the newDeviceInfo
created by this function.- ean (
-
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 butDeviceInfo
objects, or this function will raiseTypeError
without modifying thisDeviceInfoSet
.
-
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 acanlib.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 usingcanlib.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 bycanlib.kvrlib.start_discovery
, the addresses are automatically set. Otherwise, they must be assigned beforeDiscovery.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 bycanlib.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
) – ifTrue
(the default), stored devices will be discovered.
- delay (
-
-
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¶
-
-
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.
-
-
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 aRemoteDevice.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 withRemoteDevice.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 beTrue
: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:state
(canlib.kvrlib.NetworkState
): Network connection statetx_rate
(int
): Transmit rate in kbit/srx_rate
(int
): Receive rate in kbit/schannel
(int
): Channelrssi
(int
): Receive Signal Strength Indicatortx_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: bool
–True
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
-
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
.
-
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.
discover_info_set
(delay=100, timeout=1000, addresses=None, report_stored=True)[source]¶
-
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.
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, wherekey64
is a list of fourbytes
object with the four 64-bit WEP keys, and where`key128
is abytes
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.- pass_phrase (
-
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
) – IfTrue
(the default), then the returned list will contain broadcast addresses. - stored (
bool
) – IfTrue
(defaults toFalse
), then the returned list will contain earlier stored addresses.
If both arguments are
False
, aValueError
will be raised.Retruns a
list
ofcanlib.kvrlib.Address
objects.- broadcast (
-
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.
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¶
-
-
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
-
device_address
¶ Structure/Union member
-
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
-
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 numberParameters: - 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 toFalse
).
This function checks that a remote-capable device is currently connection on the channel
channel_number
. Ifvalidate_password
isTrue
, it also checks that the password supplied is correct. If any of these checks fail, aValueError
will be raised.- channel_number (
-
canlib.kvrlib.
openDiscovery
()[source]¶ Creates and returns a
canlib.kvrlib.Discovery
objectDevice 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 registrySee
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