canlib.canlib¶
Wrapper for the Kvaser CANlib library
At the core of canlib you have functions to set bus parameters (e.g. bit rate), go bus on/off and read/write CAN messages. You can also use CANlib to download and start t programs on your device. All of this is done on a device that is attached to your computer, and they are universally available across all supported Kvaser Devices. If you can see your device listed in the Kvaser Hardware tool, it is connected and you can communicate with it through CANlib.
-
class
canlib.canlib.
AcceptFilterFlag
[source]¶ Bases:
canlib.cenum.CEnum
canFILTER_SET_xxx
-
NULL_MASK
= 0¶
-
SET_CODE_EXT
= 5¶
-
SET_CODE_STD
= 3¶
-
SET_MASK_EXT
= 6¶
-
SET_MASK_STD
= 4¶
-
-
class
canlib.canlib.
BusTypeGroup
[source]¶ Bases:
canlib.cenum.CEnum
kvBUSTYPE_GROUP_xxx
Bus type group.
-
INTERNAL
= 4¶
-
LOCAL
= 2¶
-
REMOTE
= 3¶
-
VIRTUAL
= 1¶
-
-
class
canlib.canlib.
CANLib
[source]¶ Bases:
object
Deprecated wrapper class for the Kvaser CANlib.
Deprecated since version 1.5.
All functionality of this class has been moved to the canlib module itself:
# deprecated from canlib import canlib cl = canlib.CANLib() # or canlib.canlib() cl.functionName() # use this instead from canlib import canlib canlib.functionName()
-
dll
= <canlib.canlib.dll.CanlibDll object>¶
-
-
exception
canlib.canlib.
CanError
[source]¶ Bases:
canlib.exceptions.DllException
Base class for exceptions raised by the canlib class
Looks up the error text in the canlib dll and presents it together with the error code and the wrapper function that triggered the exception.
-
exception
canlib.canlib.
CanNoMsg
[source]¶ Bases:
canlib.canlib.exceptions.CanError
Raised when no matching message was available
-
status
= -2¶
-
-
exception
canlib.canlib.
CanNotFound
[source]¶ Bases:
canlib.canlib.exceptions.CanError
Specified device or channel not found
There is no hardware available that matches the given search criteria. For example, you may have specified canOPEN_REQUIRE_EXTENDED but there’s no controller capable of extended CAN. You may have specified a channel number that is out of the range for the hardware in question. You may have requested exclusive access to a channel, but the channel is already occupied.
New in version 1.6.
-
status
= -3¶
-
-
exception
canlib.canlib.
CanScriptFail
[source]¶ Bases:
canlib.canlib.exceptions.CanError
Raised when a script call failed.
This exception represents several different failures, for example: - Trying to load a corrupt file or not a .txe file - Trying to start a t script that has not been loaded - Trying to load a t script compiled with the wrong version of the t compiler - Trying to unload a t script that has not been stopped - Trying to use an envvar that does not exist
-
status
= -39¶
-
-
class
canlib.canlib.
Channel
(channel_number, flags=0)[source]¶ Bases:
object
Helper class that represents a CANlib channel.
This class wraps the canlib class and tries to implement a more Pythonic interface to CANlib.
Channels are automatically closed on garbage collection, and can also be used as context managers in which case they close as soon as the context exits.
-
busOff
()[source]¶ Takes the specified channel off-bus.
Closes the channel associated with the handle. If no other threads are using the CAN circuit, it is taken off bus. The handle can not be used for further references to the channel.
-
busOn
()[source]¶ Takes the specified channel on-bus.
If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call busOn() once for each handle.
-
canAccept
(envelope, flag)[source]¶ Set acceptance filters mask or code.
This routine sets the message acceptance filters on a CAN channel.
Setting flag to
canlib.canlib.AcceptFilterFlag.NULL_MASK
(0) removes the filter.Note that not all CAN boards support different masks for standard and extended CAN identifiers.
Parameters: - envelope – The mask or code to set.
- flag – Any of
canlib.canlib.AcceptFilterFlag
-
canSetAcceptanceFilter
(code, mask, is_extended=False)[source]¶ Set message acceptance filter.
This routine sets the message acceptance filters on a CAN channel. The message is accepted if ‘id AND mask == code’ (this is actually imlepemented as if ((code XOR id) AND mask) == 0).
Using standard 11-bit CAN identifiers and setting mask = 0x7f0, code = 0x080 accepts CAN messages with standard id 0x080 to 0x08f.
Setting the mask to canFILTER_NULL_MASK (0) removes the filter.
Note that not all CAN boards support different masks for standard and extended CAN identifiers.
Parameters: - mask (int) – A bit mask that indicates relevant bits with ‘1’.
- code (int) – The expected state of the masked bits.
- is_extended (Boolean) – If true, both mask and code applies to 29-bit CAN identifiers.
-
close
()[source]¶ Close CANlib channel
Closes the channel associated with the handle. If no other threads are using the CAN circuit, it is taken off bus.
Note
It is normally not necessary to call this function directly, as the internal handle is automatically closed when the
Channel
object is garbage collected.
-
fileCopyFromDevice
(deviceFileName, hostFileName=None)[source]¶ Copy an arbitrary file from the device to the host.
Parameters: - deviceFileName (string) – The device file name.
- hostFileName (string, optional) – The target host file name. Defaults to deviceFileName.
-
fileCopyToDevice
(hostFileName, deviceFileName=None)[source]¶ Copy an arbitrary file from the host to the device.
The filename must adhere to the FAT ‘8.3’ naming standard, max 8 characters - a dot - max 3 characters.
Parameters: - hostFileName (string) – The target host file name.
- deviceFileName (string, optional) – The device file name. Defaults to hostFileName.
-
fileGetCount
()[source]¶ Get the number of files on the device.
Returns: count (int) – The number of files.
-
fileGetName
(fileNo)[source]¶ Get the name of the file with the supplied number.
Parameters: fileNo (int) – The number of the file. Returns: fileName (string) – The name of the file.
-
flashLeds
(action, timeout_ms)[source]¶ Turn Leds on or off.
Parameters: - action (int) – One of
canlib.canlib.LEDAction
, defining which LED to turn on or off. - timeout_ms (int) – Specifies the time, in milliseconds, during which the action is to be carried out. When the timeout expires, the LED(s) will return to its ordinary function.
- action (int) – One of
-
getBusParams
()[source]¶ Get bus timing parameters for classic CAN
This function retrieves the current bus parameters for the specified channel.
- Returns: A tuple containing:
freq: Bitrate in bit/s.
tseg1: Number of quanta from but not including the Sync Segment to the sampling point.
tseg2: Number of quanta from the sampling point to the end of the bit.
sjw: The Synchronization Jump Width, can be 1,2,3, or 4.
noSamp: The number of sampling points, only 1 is supported.
syncmode: Unsupported, always read as zero.
-
getBusParamsFd
()[source]¶ Get bus timing parameters for BRS in CAN FD
This function retrieves the bus current timing parameters used in BRS (Bit rate switch) mode for the current CANlib channel.
The library provides default values for tseg1_brs, tseg2_brs and sjw_brs when freq is specified to one of the pre-defined constants,
canlib.canlib.canFD_BITRATE_xxx
If freq is any other value, no default values are supplied by the library.
- Returns: A tuple containing:
freq_brs: Bitrate in bit/s.
tseg1_brs: Number of quanta from (but not including) the Sync Segment to the sampling point.
tseg2_brs: Number of quanta from the sampling point to the end of the bit.
sjw_brs: The Synchronization Jump Width.
-
getChannelData_CardNumber
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).card_number
-
getChannelData_Chan_No_On_Card
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).chan_no_on_card
-
getChannelData_Cust_Name
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).custom_name
-
getChannelData_DriverName
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).driver_name
-
getChannelData_EAN
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).card_upc_no
-
getChannelData_Firmware
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).card_firmware_rev
-
getChannelData_Name
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).device_name
-
getChannelData_Serial
[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData
;ChannelData(Channel.index).card_serial_no
-
ioCtl_flush_rx_buffer
[source]¶ Deprecated function
Deprecated since version 1.5: Use
IOControl
;Channel.iocontrol.flush_rx_buffer()
.
-
ioCtl_get_report_access_errors
[source]¶ Deprecated function
Deprecated since version 1.5: Use
IOControl
;Channel.iocontrol.report_access_errors
-
ioCtl_set_report_access_errors
[source]¶ Deprecated function
Deprecated since version 1.5: Use
IOControl
;Channel.iocontrol.report_access_errors = on
-
ioCtl_set_timer_scale
[source]¶ Deprecated function
Deprecated since version 1.5: Use
IOControl
;Channel.iocontrol.timer_scale = scale
-
iocontrol
¶ canIoCtl
helper object for this channelSee the documentation for
IOControl
for how it can be used to perform all functionality of the C functioncanIoCtl
.Type: IOControl
-
kvDeviceGetMode
()[source]¶ Read the current device’s mode.
Note
The mode is device specific, which means that not all modes are implemented in all products.
Returns: mode (int) – One of canlib.canlib.DeviceMode
, indicating which mode is in use.
-
kvDeviceSetMode
(mode)[source]¶ Set the current device’s mode.
Note
The mode is device specific, which means that not all modes are implemented in all products.
Parameters: mode (int) – One of canlib.canlib.DeviceMode
, defining which mode to use.
-
read
(timeout=0)[source]¶ Read a CAN message and metadata.
Reads a message from the receive buffer. If no message is available, the function waits until a message arrives or a timeout occurs.
Parameters: timeout (int) – Timeout in milliseconds, -1 gives an infinite timeout. Returns: (Frame) – Frame object
-
scriptGetText
()[source]¶ Read text from subscribed script slots
Text-subscriptions must first be set up with
Channel.scriptRequestText
.Returns: ScriptText
Raises: canlib.canlib.CanNoMsg
– No more text is currently available.New in version 1.7.
-
scriptRequestText
(slot, request=<ScriptRequest.SUBSCRIBE: 2>)[source]¶ Set up a printf subscription to a selected script slot
Parameters: - slot (
int
) – The script slot to subscribe/unsubscribe from. - request (
canlib.canlib.ScriptRequest
) – Whether to subscribe or unsubscribe.
Text printed with
printf()
by a t-script that you are subscribed to is saved and can be retrieved withChannel.scriptGetText
.New in version 1.7.
- slot (
-
scriptStatus
(slot)[source]¶ Retreives t program status for selected slot
Parameters: slot (int) – Slot number to be queried Returns: canlib.ScriptStatus
New in version 1.6.
-
setBusParams
(freq, tseg1=0, tseg2=0, sjw=0, noSamp=0, syncmode=0)[source]¶ Set bus timing parameters for classic CAN
This function sets the bus timing parameters for the specified CAN controller.
The library provides default values for tseg1, tseg2, sjw and noSamp when freq is specified to one of the pre-defined constants,
canlib.canlib.canBITRATE_xxx
.If freq is any other value, no default values are supplied by the library.
If you are using multiple handles to the same physical channel, for example if you are writing a threaded application, you must call busOff() once for each handle. The same applies to busOn() - the physical channel will not go off bus until the last handle to the channel goes off bus.
Parameters: - freq – Bitrate in bit/s.
- tseg1 – Number of quanta from (but not including) the Sync Segment to the sampling point.
- tseg2 – Number of quanta from the sampling point to the end of the bit.
- sjw – The Synchronization Jump Width, can be 1,2,3, or 4.
- nosamp – The number of sampling points, only 1 is supported.
- syncMode – Unsupported and ignored.
-
setBusParamsFd
(freq_brs, tseg1_brs=0, tseg2_brs=0, sjw_brs=0)[source]¶ Set bus timing parameters for BRS in CAN FD
This function sets the bus timing parameters used in BRS (Bit rate switch) mode for the current CANlib channel.
The library provides default values for tseg1_brs, tseg2_brs and sjw_brs when freq is specified to one of the pre-defined constants,
canlib.canlib.canFD_BITRATE_xxx
If freq is any other value, no default values are supplied by the library.
Parameters: - freq_brs – Bitrate in bit/s.
- tseg1_brs – Number of quanta from (but not including) the Sync Segment to the sampling point.
- tseg2_brs – Number of quanta from the sampling point to the end of the bit.
- sjw_brs – The Synchronization Jump Width.
-
set_callback
(function, event, context=None)[source]¶ Register callback function
This will register a callback function which is called when certain events occur. You can register at most one callback function per handle at any time.
Note:
The callback function is called in the context of a high-priority thread created by CANlib. You should take precaution not to do any time consuming tasks in the callback.
Small example of usage:
# Declare callback function def callback_func(hnd, context, event): event = canlib.Notify(event) # The nonlocal statement causes the listed identifiers to refer # to previously bound variables in the nearest enclosing scope # excluding globals. nonlocal callback_has_been_called print("Callback called, context:{}, event:{!r}".format(context, event)) # Notify the main program by setting the flag callback_has_been_called = True # setup communication variable and callback callback_has_been_called = False callback = canlib.dll.KVCALLBACK_T(callback_func) with canlib.openChannel(0) as ch: ch.set_callback(callback, context=121, event=canlib.Notify.BUSONOFF) # trigger the callback ch.busOn() # do something else time.sleep(0.5) # Verify that the callback was triggered assert callback_has_been_called
Note:
It is very important to make sure that you keep a reference to the callback type (
callback
in the sample above) for as long as any C library might call it. If it gets deleted by the garbage collector, calling it from C is likely to either cause a segfault or maybe even interpret random memory as machine language.- Arguments:
function (
canlib.canlib.KVCALLBACK_T
): A ctypes wrapped Python function- event (
canlib.canlib.Notify
): A combination of flags to indicate - what events to trigger on
- event (
# .. versionadded:: 1.7
-
write
(frame=None, *args, **kwargs)[source]¶ Send a CAN message.
This function sends a Frame object as a CAN message. Note that the message has been queued for transmission when this calls return. It has not necessarily been sent.
If you are using the same channel via multiple handles, note that the default behaviour is that the different handles will “hear” each other just as if each handle referred to a channel of its own. If you open, say, channel 0 from thread A and thread B and then send a message from thread A, it will be “received” by thread B. This behaviour can be changed using canIOCTL_SET_LOCAL_TXECHO.
Also see
Channel.write_raw
for sending messages without constructing Frame objects.Deprecated since version 1.5: Sending the
Frame
contents as separate arguments; this functionality has been taken over bywrite_raw
.Parameters: frame (Frame)
-
writeSync
(timeout)[source]¶ Wait for queued messages to be sent
Waits until all CAN messages for the specified handle are sent, or the timeout period expires.
Parameters: timeout (int) – The timeout in milliseconds, None
or0xFFFFFFFF
for an infinite timeout.
-
writeWait
(frame, timeout, *args, **kwargs)[source]¶ Sends a CAN message and waits for it to be sent.
This function sends a CAN message. It returns when the message is sent, or the timeout expires. This is a convenience function that combines write() and writeSync().
Deprecated since version 1.5: Sending the
Frame
contents as separate arguments; this functionality has been taken over bywriteWait_raw
.Parameters: - frame (Frame) – Frame containing the CAN data to be sent
- timeout – The timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout.
-
writeWait_raw
(id_, msg, flag=0, dlc=0, timeout=0)[source]¶ Sends a CAN message and waits for it to be sent.
This function sends a CAN message. It returns when the message is sent, or the timeout expires. This is a convenience function that combines write() and writeSync().
Parameters: - id_ – The identifier of the CAN message to send.
- msg – An array or bytearray of the message data
- flag – A combination of
canlib.canlib.MessageFlag
. Use this parameter e.g. to send extended (29-bit) frames. - dlc – The length of the message in bytes. For Classic CAN dlc can
be at most 8, unless
canlib.canlib.Open.ACCEPT_LARGE_DLC
is used. For CAN FD dlc can be one of the following 0-8, 12, 16, 20, 24, 32, 48, 64. Optional, if omitted, dlc is calculated from the msg array. - timeout – The timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout.
-
write_raw
(id_, msg, flag=0, dlc=None)[source]¶ Send a CAN message
See docstring of
Channel.write
for general information about sending CAN messages.The variable name id (as used by canlib) is a built-in function in Python, so the name
id_
is used instead.Parameters: - id_ – The identifier of the CAN message to send.
- msg – An array or bytearray of the message data
- flag – A combination of
canlib.canlib.MessageFlag
. Use this parameter e.g. to send extended (29-bit) frames. - dlc – The length of the message in bytes. For Classic CAN dlc can
be at most 8, unless
canlib.canlib.Open.ACCEPT_LARGE_DLC
is used. For CAN FD dlc can be one of the following 0-8, 12, 16, 20, 24, 32, 48, 64. Optional, if omitted, dlc is calculated from the msg array.
-
-
class
canlib.canlib.
ChannelCap
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
canCHANNEL_CAP_xxx
Channel capabilities.
Changed in version 1.7.
-
BUS_STATISTICS
= <ChannelCap.BUS_STATISTICS: 2>¶
-
CAN_FD
= <ChannelCap.CAN_FD: 524288>¶
-
CAN_FD_NONISO
= <ChannelCap.CAN_FD_NONISO: 1048576>¶
-
DIAGNOSTICS
= <ChannelCap.DIAGNOSTICS: 134217728>¶
-
ERROR_COUNTERS
= <ChannelCap.ERROR_COUNTERS: 4>¶
-
EXTENDED_CAN
= <ChannelCap.EXTENDED_CAN: 1>¶
-
GENERATE_ERROR
= <ChannelCap.GENERATE_ERROR: 16>¶
-
GENERATE_OVERLOAD
= <ChannelCap.GENERATE_OVERLOAD: 32>¶
-
LIN_HYBRID
= <ChannelCap.LIN_HYBRID: 67108864>¶
-
LOGGER
= <ChannelCap.LOGGER: 8388608>¶
-
REMOTE_ACCESS
= <ChannelCap.REMOTE_ACCESS: 16777216>¶
-
RESERVED_1
= <ChannelCap.RESERVED_1: 262144>¶
-
RESERVED_2
= <ChannelCap.RESERVED_2: 8>¶
-
SCRIPT
= <ChannelCap.SCRIPT: 33554432>¶
-
SILENT_MODE
= <ChannelCap.SILENT_MODE: 2097152>¶
-
SIMULATED
= <ChannelCap.SIMULATED: 131072>¶
-
SINGLE_SHOT
= <ChannelCap.SINGLE_SHOT: 4194304>¶
-
TXACKNOWLEDGE
= <ChannelCap.TXACKNOWLEDGE: 128>¶
-
TXREQUEST
= <ChannelCap.TXREQUEST: 64>¶
-
VIRTUAL
= <ChannelCap.VIRTUAL: 65536>¶
-
-
class
canlib.canlib.
ChannelData
(channel_number)[source]¶ Bases:
object
Object for querying various information about a channel
After instantiating a
ChannelData
object with a channel number, a variety of information is available as attributes. Most attributes are named after the C constant used to retrieve the information and are found in the list below.Other information does not follow the C implementation completely, and are documented as separate properties further down.
There is also the
raw
function, that is used internally to get all information and can also be used to interact more directly with the dll.Variables: - bus_type – A member of the
BusTypeGroup
enum. Not implemented in Linux. - card_firmware_rev – A
VersionNumber
object with the version of the card’s firmware. - card_hardware_rev – A
VersionNumber
object with the version of the card’s hardware. - card_number – An
int
with the card’s number in the computer. Each card type is numbered separately. - card_serial_no – An
int
with the serial number of the card, or 0 if it doesn’t have a serial number. - card_type – A member of the
HardwareType
enum representing the hardware type of the card. - card_upc_no – An
EAN
object with the EAN of the card, orNone
if it doesn’t one. - chan_no_on_card – An
int
of the channel number on the card. - channel_cap – A
ChannelCap
object with the capabilities of the channel as flags. Also seechannel_cap_mask
. - channel_cap_mask – A
ChannelCap
with which flags this device knows about. - channel_flags – A
ChannelFlags
object with the status of the channel as flags. Not implemented in Linux. - channel_quality – An
int
between 0 and 100 (inclusively) with the quality of the channel in percent of optimal quality. Not implemented in Linux. - devdescr_ascii – A
str
with the product name of the device. - devdescr_unicode – A
str
with the product name of the device. Not implemented in Linux. - device_physical_position – An
int
with the address of the device on its underlying bus. Not implemented in Linux. - devname_ascii – A
str
with the current device name. Not implemented in Linux. - dll_file_version – A
VersionNumber
with the version of the dll file. - dll_filetype – 1 if “kvalapw.dll” is used, 2 if “kvalapw2.dll”
- dll_product_version – A
VersionNumber
with the product version of the dll file. - driver_file_version – A
VersionNumber
with the version of the kernel-mode driver. Not implemented in Linux. - driver_name – A
str
with the name of the device driver. - driver_product_version – A
VersionNumber
with the product version of the kernel-mode driver. Not implemented in Linux. - feature_ean – An
EAN
object with an internal EAN. This is only intended for internal use. - hw_status – Six
int
with hardware status codes. This is only intended for internal use. - is_remote – A
bool
for whether the device is currently connected as a remote device. Not implemented in Linux. - logger_type – A member of the
LoggerType
enum. Not implemented in Linux. - max_bitrate – An
int
with the maximum bitrate of the device. Zero means no limit on the bitrate. - mfgname_ascii – A
str
with the manufacturer’s name. - mfgname_unicode – A
str
with the manufacturer’s name. Not implemented in Linux. - remote_host_name – A
str
with the remote host name of the device. Not implemented in Linux. - remote_mac – A
str
with the remote mac address of the device. Not implemented in Linux. - remote_operational_mode – A member of the
OperationalMode
enum. Not implemented in Linux. - remote_profile_name – A
str
with the remote profile name of the device. Not implemented in Linux. - remote_type – A member of the
RemoteType
enum. Not implemented in Linux. - roundtrip_time – An
int
with the roundtrip time measured in milliseconds. Not implemented in Linux. - time_since_last_seen – An
int
with the time in milliseconds since last communication occured. Not implemented in Linux. - timesync_enabled – A
bool
for whether legacy time synchronization is enabled. Not implemented in Linux. - trans_cap – A
DriverCap
object with the capabilities of the transceiver as flags. Not implemented in Linux. - trans_serial_no – An
int
with the serial number of the transceiver, or 0 if it doesn’t have a serial number. Not implemented in Linux. - trans_type – A member of the
TransceiverType
enum. - trans_upc_no – An
EAN
object with the EAN of the transceiver, orNone
if it doesn’t have one. Not implemented in Linux. - ui_number – An
int
with the number associated with the device that can be displayed in the user interface. Not implemented in Linux.
-
channel_name
¶ The product channel name.
Retrieves a clear text name of the channel. The name is returned as a string.
Type: str
-
custom_name
¶ The custom channel name if set, or an empty string otherwise
Type: str
-
device_name
¶ Deprecated since version 1.7.
-
raw
(item, ctype=<class 'ctypes.c_ulong'>)[source]¶ A raw call to
canGetChannelData
Parameters: - item (
ChannelDataItem
) – The information to be retrieved. - ctype – The
ctypes
type that the information should be interpreted as.
- item (
- bus_type – A member of the
-
class
canlib.canlib.
ChannelDataItem
[source]¶ Bases:
canlib.cenum.CEnum
-
BUS_TYPE
= 30¶
-
CARD_FIRMWARE_REV
= 9¶
-
CARD_HARDWARE_REV
= 10¶
-
CARD_NUMBER
= 5¶
-
CARD_SERIAL_NO
= 7¶
-
CARD_TYPE
= 4¶
-
CARD_UPC_NO
= 11¶
-
CHANNEL_CAP
= 1¶
-
CHANNEL_CAP_MASK
= 38¶
-
CHANNEL_FLAGS
= 3¶
-
CHANNEL_NAME
= 13¶
-
CHANNEL_QUALITY
= 28¶
-
CHAN_NO_ON_CARD
= 6¶
-
CUST_CHANNEL_NAME
= 39¶
-
DEVDESCR_ASCII
= 26¶
-
DEVDESCR_UNICODE
= 25¶
-
DEVICE_PHYSICAL_POSITION
= 18¶
-
DEVNAME_ASCII
= 31¶
-
DLL_FILETYPE
= 16¶
-
DLL_FILE_VERSION
= 14¶
-
DLL_PRODUCT_VERSION
= 15¶
-
DRIVER_FILE_VERSION
= 21¶
-
DRIVER_NAME
= 27¶
-
DRIVER_PRODUCT_VERSION
= 22¶
-
FEATURE_EAN
= 44¶
-
HW_STATUS
= 43¶
-
IS_REMOTE
= 40¶
-
LOGGER_TYPE
= 42¶
-
MAX_BITRATE
= 37¶
-
MFGNAME_ASCII
= 24¶
-
MFGNAME_UNICODE
= 23¶
-
REMOTE_HOST_NAME
= 35¶
-
REMOTE_MAC
= 36¶
-
REMOTE_OPERATIONAL_MODE
= 33¶
-
REMOTE_PROFILE_NAME
= 34¶
-
REMOTE_TYPE
= 41¶
-
ROUNDTRIP_TIME
= 29¶
-
TIMESYNC_ENABLED
= 20¶
-
TIME_SINCE_LAST_SEEN
= 32¶
-
TRANS_CAP
= 2¶
-
TRANS_SERIAL_NO
= 8¶
-
TRANS_TYPE
= 17¶
-
TRANS_UPC_NO
= 12¶
-
UI_NUMBER
= 19¶
-
-
class
canlib.canlib.
ChannelData_Channel_Flags
[source]¶ Bases:
_ctypes.Union
Holds data from
canlib.getChannelData_Channel_Flags()
Deprecated since version 1.5.
Data in this object may be accessed as an c_uint32 using
object.asbyte
, or as indivisual flags using the classChannelData_Channel_Flags_bits
.-
asbyte
¶ Structure/Union member
-
b
¶ Structure/Union member
-
-
class
canlib.canlib.
ChannelData_Channel_Flags_bits
[source]¶ Bases:
_ctypes.Structure
Access flags of
ChannelData_Channel_Flags
Deprecated since version 1.5.
Gives access to individual parts in
ChannelData_Channel_Flags
as flags.-
is_canfd
¶ Structure/Union member
-
is_exclusive
¶ Structure/Union member
-
is_open
¶ Structure/Union member
-
-
class
canlib.canlib.
ChannelFlags
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
canCHANNEL_IS_xxx
These channelFlags are used in
Channel.getChannelData
and in conjunction withChannelDataItem.CHANNEL_FLAGS
.-
IS_CANFD
= <ChannelFlags.IS_CANFD: 4>¶
-
IS_EXCLUSIVE
= <ChannelFlags.IS_EXCLUSIVE: 1>¶
-
IS_LIN
= <ChannelFlags.IS_LIN: 16>¶
-
IS_LIN_MASTER
= <ChannelFlags.IS_LIN_MASTER: 32>¶
-
IS_LIN_SLAVE
= <ChannelFlags.IS_LIN_SLAVE: 64>¶
-
IS_OPEN
= <ChannelFlags.IS_OPEN: 2>¶
-
-
class
canlib.canlib.
Driver
[source]¶ Bases:
canlib.cenum.CEnum
-
NORMAL
= 4¶
-
OFF
= 0¶
-
SELFRECEPTION
= 8¶
-
SILENT
= 1¶
-
-
class
canlib.canlib.
DriverCap
[source]¶ Bases:
canlib.cenum.CEnum
canDRIVER_CAP_xxx
Driver (transceiver) capabilities.
-
HIGHSPEED
= 1¶
-
-
exception
canlib.canlib.
EnvvarException
[source]¶ Bases:
exceptions.Exception
Base class for exceptions related to environment variables.
-
exception
canlib.canlib.
EnvvarNameError
(envvar)[source]¶ Bases:
canlib.canlib.exceptions.EnvvarException
Raised when the name of the environment variable is illegal.
-
exception
canlib.canlib.
EnvvarValueError
(envvar, type_, value)[source]¶ Bases:
canlib.canlib.exceptions.EnvvarException
Raised when the type of the value does not match the type of the environment variable.
-
class
canlib.canlib.
Error
[source]¶ Bases:
canlib.cenum.CEnum
-
INVALID_PASSWORD
= -128¶
-
INVALID_SESSION
= -131¶
-
INVHANDLE
= -10¶
-
NOCARD
= -26¶
-
NOCHANNELS
= -5¶
-
NOMSG
= -2¶
-
NOTFOUND
= -3¶
-
NOT_AUTHORIZED
= -130¶
-
NOT_IMPLEMENTED
= -32¶
-
NO_SUCH_FUNCTION
= -129¶
-
PARAM
= -1¶
-
SCRIPT_FAIL
= -39¶
-
TIMEOUT
= -7¶
-
TXBUFOFL
= -13¶
-
-
class
canlib.canlib.
HardwareType
[source]¶ Bases:
canlib.cenum.CEnum
canHWTYPE_xxx
The following constants can be returned from canGetChannelData(), using the canCHANNELDATA_CARD_TYPE item code. They identify the hardware type for the channel specified in the call to canGetChannelData().
Note
The members indicate a hardware type, but not necessarily a specific product. For example, canHWTYPE_LAPCAN is returned both for LAPcan and LAPcan II. (You can use canGetChannelData() to obtain the UPC/EAN code for the device. This number uniquely identifies the product.)
-
ACQUISITOR
= 46¶
-
BAGEL
= 64¶
-
BLACKBIRD
= 58¶
-
BLACKBIRD_V2
= 64¶
-
CANLINHYBRID
= 84¶
-
CANPARI
= 3¶
-
EAGLE
= 62¶
-
ETHERCAN
= 70¶
-
IRIS
= 58¶
-
LAPCAN
= 2¶
-
LEAF
= 48¶
-
LEAF2
= 80¶
-
MEMORATOR_II
= 54¶
-
MEMORATOR_LIGHT
= 60¶
-
MEMORATOR_PRO
= 54¶
-
MEMORATOR_PRO2
= 78¶
-
MEMORATOR_V2
= 82¶
-
MINIHYDRA
= 62¶
-
MINIPCIE
= 66¶
-
NONE
= 0¶
-
PC104_PLUS
= 50¶
-
PCCAN
= 8¶
-
PCICAN
= 9¶
-
PCICANX_II
= 52¶
-
PCICAN_II
= 40¶
-
PCIE_V2
= 76¶
-
SIMULATED
= 44¶
-
USBCAN
= 11¶
-
USBCAN_II
= 42¶
-
USBCAN_KLINE
= 68¶
-
USBCAN_LIGHT
= 72¶
-
USBCAN_PRO
= 56¶
-
USBCAN_PRO2
= 74¶
-
VIRTUAL
= 1¶
-
-
class
canlib.canlib.
IOControl
(channel)[source]¶ Bases:
object
Helper object for using
canIoCtl
Provides a variety of functionality, some of which are represented as attributes of this object and some as functions. See the respective entries below for more information.
Variables: - brlimit – An
int
with the hardware bitrate limit, or zero for the device’s default. Write-only. - bus_type – A member of the
BusTypeGroup
enum. Not implemented in Linux. Read-only. - buson_time_auto_reset – A
bool
for whether the CAN clock is reset at bus-on. Not implemented in Linux. Write-only. - channel_quality – An
int
between 0 and 100 (inclusively) with the quality of the channel in percent. Not implemented in Linux. Read-only. - devname_ascii – A
str
with the current device name. Not implemented in Linux. Read-only. - driverhandle – The windows handle related to the CANlib handle. Not implemented in Linux. Read-only.
- error_frames_reporting – A
bool
for whether error frames are reported. Not implemented in Linux. Write-only. - eventhandle – An
int
with the windows event handle. Not implemented in Linux. Read-only. - local_txecho – A
bool
for whether local transmit echo is turned on. Write-only. - report_access_errors – A
bool
for whether Access Reporting is turned on - roundtrip_time – An
int
with the roundtrip time in milliseconds. Not implemented in Linux. Read-only. - rx_buffer_level – An
int
with the approximate receive queue level. Read-only. - rx_queue_size – An
int
with the size of the receive buffer. Can only be used off-bus. Not implemented in Linux. Write-only. - throttle_scaled – An
int
between 0 and 100 (inclusively) where 0 means the device is very responsive but generates more CPU load and 100 means the device is less responsive with less CPU load. Note that not all devices support setting this. Some hardware will accept this command but neglect it. Not implemented in Linux. - time_since_last_seen – An
int
with the time in milliseconds since the last communication occured. Not implemented in Linux. Read-only. - timer_scale – An
int
with the time-stamp clock resolution in microseconds. - tx_buffer_level – An
int
with the approximate transmit queue level. Read-only. - tx_interval – An
int
with the number of microseconds with the minimum CAN message transmit interval. - txack – 0 for Transmit Acknowledges off, 1 for Transmit Acknowledges on, and 2 for Transmit Acknowledges off, even for the driver’s internal usage (this will break parts of the library).
- txrq – A
bool
for whether Transmit Requests are turned on. Write-only.
-
connect_to_virtual_bus
(value)¶ Connects the channel to the virtual bus number
value
.
-
disconnect_from_virtual_bus
(value)¶ Disconnects the channel to the virtual bus number
value
.
-
flush_rx_buffer
()¶ Discard the current contents of the RX queue.
-
flush_tx_buffer
()¶ Discard the current contents of the TX queue.
-
prefer_ext
()¶ Tells CANlib to assume
MessageFlag.EXT
when sending messages if neitherMessageFlag.EXT
orMessageFlag.STD
is specified. Not implemented in Linux.
-
prefer_std
()¶ Tells CANlib to assume
MessageFlag.STD
when sending messages if neitherMessageFlag.EXT
orMessageFlag.STD
is specified. Not implemented in Linux.
-
reset_overrun_count
()¶ Resets overrun count and flags.
-
raw
(item, value=None, ctype=<class 'ctypes.c_ulong'>)[source]¶ A raw call to
canIoCtl
Parameters: - item (
IOControlItem
) – The “function code” to be passed tocanIoCtl
. - value – The value sent to
canIoCtl
orNone
if no value should be given. Must be compatible with thectype
argument. - ctype – The
ctypes
type that should be used to when sending thevalue
argument and when interpreting the result ofcanIoCtl
.
- item (
- brlimit – An
-
class
canlib.canlib.
IOControlItem
[source]¶ Bases:
canlib.cenum.CEnum
-
CLEAR_ERROR_COUNTERS
= 5¶
-
CONNECT_TO_VIRTUAL_BUS
= 22¶
-
DISCONNECT_FROM_VIRTUAL_BUS
= 23¶
-
FLUSH_RX_BUFFER
= 10¶
-
FLUSH_TX_BUFFER
= 11¶
-
GET_BUS_TYPE
= 36¶
-
GET_CHANNEL_QUALITY
= 34¶
-
GET_DEVNAME_ASCII
= 37¶
-
GET_DRIVERHANDLE
= 17¶
-
GET_EVENTHANDLE
= 14¶
-
GET_REPORT_ACCESS_ERRORS
= 21¶
-
GET_ROUNDTRIP_TIME
= 35¶
-
GET_RX_BUFFER_LEVEL
= 8¶
-
GET_THROTTLE_SCALED
= 42¶
-
GET_TIMER_SCALE
= 12¶
-
GET_TIME_SINCE_LAST_SEEN
= 38¶
-
GET_TREF_LIST
= 39¶
-
GET_TXACK
= 31¶
-
GET_TX_BUFFER_LEVEL
= 9¶
-
GET_USB_THROTTLE
= 29¶
-
GET_USER_IOPORT
= 25¶
-
GET_WAKEUP
= 19¶
-
LIN_MODE
= 45¶
-
MAP_RXQUEUE
= 18¶
-
PREFER_EXT
= 1¶
-
PREFER_STD
= 2¶
-
RESET_OVERRUN_COUNT
= 44¶
-
SET_BRLIMIT
= 43¶
-
SET_BUFFER_WRAPAROUND_MODE
= 26¶
-
SET_BUSON_TIME_AUTO_RESET
= 30¶
-
SET_BYPASS_MODE
= 15¶
-
SET_ERROR_FRAMES_REPORTING
= 33¶
-
SET_LOCAL_TXECHO
= 32¶
-
SET_REPORT_ACCESS_ERRORS
= 20¶
-
SET_RX_QUEUE_SIZE
= 27¶
-
SET_THROTTLE_SCALED
= 41¶
-
SET_TIMER_SCALE
= 6¶
-
SET_TXACK
= 7¶
-
SET_TXRQ
= 13¶
-
SET_USB_THROTTLE
= 28¶
-
SET_USER_IOPORT
= 24¶
-
SET_WAKEUP
= 16¶
-
TX_INTERVAL
= 40¶
-
-
class
canlib.canlib.
LEDAction
[source]¶ Bases:
canlib.cenum.CEnum
kvLED_ACTION_xxx
The following can be used together with
canlib.canlib.Channel.flashLeds
.-
ALL_LEDS_OFF
= 1¶ Turn all LEDs off.
-
ALL_LEDS_ON
= 0¶ Turn all LEDs on.
-
LED_0_OFF
= 3¶ Turn LED 0 off.
-
LED_0_ON
= 2¶ Turn LED 0 on.
-
LED_1_OFF
= 5¶ Turn LED 1 off.
-
LED_1_ON
= 4¶ Turn LED 1 on.
-
LED_2_OFF
= 7¶ Turn LED 2 off.
-
LED_2_ON
= 6¶ Turn LED 2 on.
-
LED_3_OFF
= 9¶ Turn LED 3 off.
-
LED_3_ON
= 8¶ Turn LED 3 on.
-
-
class
canlib.canlib.
LoggerType
[source]¶ Bases:
canlib.cenum.CEnum
kvLOGGER_TYPE_xxx
Logger type, returned when using canCHANNELDATA_LOGGER_TYPE
-
NOT_A_LOGGER
= 0¶
-
V1
= 1¶
-
V2
= 2¶
-
-
class
canlib.canlib.
MessageFlag
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
Message information flags
The following flags can be returned from canRead() et al, or passed to canWrite().
This enum is a combination of flags for messages, CAN FD messages, and message errors. Normal messages flags are the flags covered by
MSG_MASK
, CAN FD message flags are those covered byFDMSG_MASK
, and message errors are those covered byMSGERR_MASK
.Note
FDF
,BRS
, andESI
require CAN FD.RTR
cannot be set for CAN FD messages.Not all hardware platforms can detect the difference between hardware overruns and software overruns, so your application should test for both conditions. You can use the symbol
OVERRUN
for this purpose.-
BIT
= <MessageFlag.BIT: 49152>¶
-
BIT0
= <MessageFlag.BIT0: 16384>¶
-
BIT1
= <MessageFlag.BIT1: 32768>¶
-
BRS
= <MessageFlag.BRS: 131072>¶
-
BUSERR
= <MessageFlag.BUSERR: 63488>¶
-
CRC
= <MessageFlag.CRC: 8192>¶
-
ERROR_FRAME
= <MessageFlag.ERROR_FRAME: 32>¶
-
ESI
= <MessageFlag.ESI: 262144>¶
-
EXT
= <MessageFlag.EXT: 4>¶
-
FDF
= <MessageFlag.FDF: 65536>¶
-
FDMSG_MASK
= <MessageFlag.FDMSG_MASK: 16711680>¶
-
FORM
= <MessageFlag.FORM: 4096>¶
-
HW_OVERRUN
= <MessageFlag.HW_OVERRUN: 512>¶
-
MSGERR_MASK
= <MessageFlag.MSGERR_MASK: 65280>¶
-
MSG_MASK
= <MessageFlag.MSG_MASK: 255>¶
-
NERR
= <MessageFlag.NERR: 16>¶
-
OVERRUN
= <MessageFlag.OVERRUN: 1536>¶
-
RTR
= <MessageFlag.RTR: 1>¶
-
STD
= <MessageFlag.STD: 2>¶
-
STUFF
= <MessageFlag.STUFF: 2048>¶
-
SW_OVERRUN
= <MessageFlag.SW_OVERRUN: 1024>¶
-
TXACK
= <MessageFlag.TXACK: 64>¶
-
TXRQ
= <MessageFlag.TXRQ: 128>¶
-
WAKEUP
= <MessageFlag.WAKEUP: 8>¶
-
-
class
canlib.canlib.
Notify
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
canNOTIFY_xxx
These notify flags are used in
canlib.canlib.set_callback
to indicate different kind of events.-
BUSONOFF
= <Notify.BUSONOFF: 32>¶
-
ENVVAR
= <Notify.ENVVAR: 16>¶
-
ERROR
= <Notify.ERROR: 4>¶
-
NONE
= <Notify.NONE: 0>¶
-
REMOVED
= <Notify.REMOVED: 64>¶
-
RX
= <Notify.RX: 1>¶
-
STATUS
= <Notify.STATUS: 8>¶
-
TX
= <Notify.TX: 2>¶
-
-
class
canlib.canlib.
Open
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
-
ACCEPT_LARGE_DLC
= <Open.ACCEPT_LARGE_DLC: 512>¶
-
ACCEPT_VIRTUAL
= <Open.ACCEPT_VIRTUAL: 32>¶
-
CAN_FD
= <Open.CAN_FD: 1024>¶
-
CAN_FD_NONISO
= <Open.CAN_FD_NONISO: 2048>¶
-
EXCLUSIVE
= <Open.EXCLUSIVE: 8>¶
-
NO_INIT_ACCESS
= <Open.NO_INIT_ACCESS: 256>¶
-
OVERRIDE_EXCLUSIVE
= <Open.OVERRIDE_EXCLUSIVE: 64>¶
-
REQUIRE_EXTENDED
= <Open.REQUIRE_EXTENDED: 16>¶
-
REQUIRE_INIT_ACCESS
= <Open.REQUIRE_INIT_ACCESS: 128>¶
-
-
class
canlib.canlib.
OperationalMode
[source]¶ Bases:
canlib.cenum.CEnum
canCHANNEL_OPMODE_xxx
Current WLAN operational mode.
-
ADH
= 4¶
-
INFRASTRUCTURE
= 2¶
-
NONE
= 1¶
-
RESERVED
= 3¶
-
-
class
canlib.canlib.
RemoteType
[source]¶ Bases:
canlib.cenum.CEnum
kvREMOTE_TYPExxx
Remote type, returned when using canCHANNELDATA_REMOTE_TYPE
-
LAN
= 2¶
-
NOT_REMOTE
= 0¶
-
WLAN
= 1¶
-
-
class
canlib.canlib.
ScriptRequest
[source]¶ Bases:
canlib.cenum.CEnum
kvSCRIPT_REQUEST_TEXT_xxx
These defines are used in kvScriptRequestText() for printf message subscribe/unsubscribe.
-
ALL_SLOTS
= 255¶
-
SUBSCRIBE
= 2¶
-
UNSUBSCRIBE
= 1¶
-
-
class
canlib.canlib.
ScriptStatus
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
Status of t program
New in version 1.6.
Changed in version 1.7: Is now based on
IntFlag
instead ofIntEnum
-
IDLE
= <ScriptStatus.IDLE: 0>¶
-
LOADED
= <ScriptStatus.LOADED: 1>¶
-
RUNNING
= <ScriptStatus.RUNNING: 2>¶
-
-
class
canlib.canlib.
ScriptText
[source]¶ Bases:
str
Text returned by
Channel.scriptGetText
Subclass of built-in
str
, so it can be used just like a normall string.It also has the following attributes:
Variables: - slot (
int
) – Which script-slot the text came from. - time (
int
) – Timestamp of when the text was printed. - flags (
canlib.canlib.Stat
) – Any flags associated with the text.
New in version 1.7.
- slot (
-
class
canlib.canlib.
SourceElement
(name, contents)¶ Bases:
tuple
-
contents
¶ Alias for field number 1
-
name
¶ Alias for field number 0
-
-
class
canlib.canlib.
Stat
(*args, **kwds)[source]¶ Bases:
canlib.cenum.CFlag
canSTAT_xxx
The following circuit status flags are returned by canReadStatus(). Note that more than one flag might be set at any one time.
Note
Usually both canSTAT_HW_OVERRUN and canSTAT_SW_OVERRUN are set when overrun has occurred. This is because the kernel driver can’t see the difference between a software overrun and a hardware overrun. So the code should always test for both types of overrun using the flag.
-
BUS_OFF
= <Stat.BUS_OFF: 2>¶
-
ERROR_ACTIVE
= <Stat.ERROR_ACTIVE: 8>¶
-
ERROR_PASSIVE
= <Stat.ERROR_PASSIVE: 1>¶
-
ERROR_WARNING
= <Stat.ERROR_WARNING: 4>¶
-
HW_OVERRUN
= <Stat.HW_OVERRUN: 512>¶
-
OVERRUN
= <Stat.OVERRUN: 1536>¶
-
RESERVED_1
= <Stat.RESERVED_1: 64>¶
-
RXERR
= <Stat.RXERR: 256>¶
-
RX_PENDING
= <Stat.RX_PENDING: 32>¶
-
SW_OVERRUN
= <Stat.SW_OVERRUN: 1024>¶
-
TXERR
= <Stat.TXERR: 128>¶
-
TX_PENDING
= <Stat.TX_PENDING: 16>¶
-
-
class
canlib.canlib.
TransceiverType
[source]¶ Bases:
canlib.cenum.CEnum
Transceiver (logical) types
The following constants can be returned from canGetChannelData(), using the canCHANNELDATA_TRANS_TYPE item code. They identify the bus transceiver type for the channel specified in the call to canGetChannelData.
Note
If the type starts with a number
T_
has been prepended to the name.They indicate a hardware type, but not necessarily a specific circuit or product.
-
CANFD
= 22¶
-
CANFD_LIN
= 24¶
-
DNOPTO
= 3¶
-
EVA
= 7¶
-
FIBER
= 8¶
-
K
= 10¶
-
K251
= 9¶
-
KONE
= 20¶
-
LIN
= 19¶
-
LINX_J1708
= 66¶
-
LINX_K
= 68¶
-
LINX_LIN
= 64¶
-
LINX_LS
= 72¶
-
LINX_SWC
= 70¶
-
RS485
= 18¶
-
SWC
= 6¶
-
SWC_OPTO
= 12¶
-
SWC_PROTO
= 5¶
-
TT
= 13¶
-
T_1041
= 16¶
-
T_1041_OPTO
= 17¶
-
T_1050
= 14¶
-
T_1050_OPTO
= 15¶
-
T_1054_OPTO
= 11¶
-
T_251
= 1¶
-
T_252
= 2¶
-
UNKNOWN
= 0¶
-
W210
= 4¶
-
-
class
canlib.canlib.
Txe
(path)[source]¶ Bases:
object
The Txe class provides an interface to compiled t programs (.txe) files.
New in version 1.6.
-
compiler_version
¶ t compiler version number.
Type: VersionNumber
-
date
¶ Compilation date and time.
Type: datetime.datetime
-
description
¶ t program description.
Type: str
-
file_version
¶ .txe binary format version number.
Type: VersionNumber
-
is_encrypted
¶ true if the source and byte-code sections of the .txe binary have been encrypted.
Type: bool
-
path
¶ Path of compiled t program (.txe) file.
Type: str
-
size_of_code
¶ Size in bytes of byte-code section.
Type: int
-
source
¶ Yields name and content of the source files used to create the .txe binary file.
If the t source files used to create the .txe binary was included at compilation time, then this attribute will yield
SourceElement
tuples containing the name and content of the individual source files.Sample usage:
for name, contents in txe.source: print('file name:{} contents:{}'.format(name, contents))
If the source and byte-code sections of the .txe binary have been encrypted then it’s not possible to parse the source list and a
TxeFileIsEncrypted
exception will be raised.If no source files have been included in the .txe binary then an empty iterator is returned.
Yields: SourceElement
– Name and contents tuple.Raises: TxeFileIsEncrypted
– If the source and byte-code sections of the .txe binary have been encrypted.
-
-
class
canlib.canlib.
TxeDataItem
[source]¶ Bases:
canlib.cenum.CEnum
-
COMPILER_VERSION
= 2¶
-
DATE
= 3¶
-
DESCRIPTION
= 4¶
-
FILE_VERSION
= 1¶
-
IS_ENCRYPTED
= 7¶
-
SIZE_OF_CODE
= 6¶
-
SOURCE
= 5¶
-
-
exception
canlib.canlib.
TxeFileIsEncrypted
[source]¶ Bases:
exceptions.Exception
Raised when trying to access
Txe.source
and the source and byte-code sections of the .txe binary have been encrypted.
-
class
canlib.canlib.
bitrateSetting
(freq=1000000, tseg1=4, tseg2=3, sjw=1, nosamp=1, syncMode=0)[source]¶ Bases:
object
Class that holds bitrate setting.
Variables: - freq – Bitrate in bit/s.
- tseg1 – Number of quanta from (but not including) the Sync Segment to the sampling point.
- tseg2 – Number of quanta from the sampling point to the end of the bit.
- sjw – The Synchronization Jump Width, can be 1,2,3, or 4.
- nosamp – The number of sampling points, only 1 is supported.
- syncMode – Unsupported and ignored.
-
canlib.canlib.
canError
¶ alias of
canlib.canlib.exceptions.CanError
-
canlib.canlib.
canNoMsg
¶ alias of
canlib.canlib.exceptions.CanNoMsg
-
canlib.canlib.
canScriptFail
¶ alias of
canlib.canlib.exceptions.CanScriptFail
-
canlib.canlib.
canlib
¶ alias of
canlib.canlib.wrapper.CANLib
-
canlib.canlib.
dllversion
()[source]¶ Get the CANlib DLL version number
Parameters: None Returns a
BetaVersionNumber
if the CANlib DLL is marked as beta (preview), otherwise returnsVersionNumber
.Changed in version 1.6.
-
canlib.canlib.
envvar
¶ alias of
canlib.canlib.envvar.EnvVar
-
canlib.canlib.
getChannelData_CardNumber
[source]¶ Get the card number
Deprecated since version 1.5: Use
ChannelData
and theircard_number
attribute instead.Retrieves the card’s number in the computer. Each card type is numbered separately. For example, the first PCIEcan card in a machine will have number 0, the second PCIEcan number 1, etc.
Parameters: channel (int) – The channel you are interested in Returns: card_number (int) – The device’s card number
-
canlib.canlib.
getChannelData_Chan_No_On_Card
[source]¶ Get the channel number on the card.
Deprecated since version 1.5: Use
ChannelData
and theirchan_no_on_card
attribute instead.Retrieves the channel number, as numbered locally on the card, device connected to channel.
Parameters: channel (int) – The channel you are interested in Returns: number (int) – The local channel number
-
canlib.canlib.
getChannelData_Channel_Flags
[source]¶ Get channel status flags
Deprecated since version 1.5: Use
ChannelData
and theirchannel_flags
attribute instead.Returns a
ChannelData_Channel_Flags
object holding information about the channel.Note: Currently not implemented!
-
canlib.canlib.
getChannelData_Cust_Name
[source]¶ Get the customized channel name.
Deprecated since version 1.5: Use
ChannelData
and theircustom_name
attribute instead.Retrieves the customized device channel name of the device connected to channel. The name is returned as a string.
Parameters: channel (int) – The channel you are interested in Returns: custom_name (string) – The customized device channel name
-
canlib.canlib.
getChannelData_DriverName
[source]¶ Get device driver name
Deprecated since version 1.5: Use
ChannelData
and theirdriver_name
attribute instead.Retrieves the name of the device driver (e.g. “kcany”) for the device connected to channel. The device driver names have no special meanings and may change from a release to another.
Parameters: channel (int) – The channel you are interested in Returns: driver_name (str) – The device driver name
-
canlib.canlib.
getChannelData_EAN
[source]¶ Get EAN code
Deprecated since version 1.5: Use
ChannelData
and theircard_upc_no
attribute instead.Retrieves the EAN number for the device connected to channel. If there is no EAN number, “00-00000-00000-0” will be returned.
Parameters: channel (int) – The channel you are interested in Returns: ean (str) – The device’s EAN number
-
canlib.canlib.
getChannelData_EAN_short
[source]¶ Get short EAN code
Deprecated since version 1.5: Use
ChannelData
and their.card_upc_no.product()
instead.Retrieves the short EAN number, aka product number, for the device connected to channel. If there is no EAN number, “00000-0” will be returned.
Parameters: channel (int) – The channel you are interested in Returns: ean (str) – The device’s shortened EAN number
-
canlib.canlib.
getChannelData_Firmware
[source]¶ Get device firmware version
Deprecated since version 1.5: Use
ChannelData
and theircard_firmware_rev
attribute instead.Retrieves the firmvare version numbers for the device connected to channel.
Parameters: channel (int) – The channel you are interested in Returns: (fw_major, fw_minor, fw_build) – The version number
-
canlib.canlib.
getChannelData_Name
[source]¶ Get the product name.
Deprecated since version 1.5: Use
ChannelData
and theirdevice_name
attribute instead.Retrieves the product name of the device connected to channel. The name is returned as a string.
Parameters: channel (int) – The channel you are interested in Returns: product_name (string) – The product name
-
canlib.canlib.
getChannelData_Serial
[source]¶ Get device serial number
Deprecated since version 1.5: Use
ChannelData
and theircard_serial_no
attribute instead.Retrieves the serial number for the device connected to channel. If the device does not have a serial number, 0 is returned.
Parameters: channel (int) – The channel you are interested in Returns: serial (int) – The device serial number
-
canlib.canlib.
getNumberOfChannels
(driver=False)[source]¶ Get number of available CAN channels.
Returns the number of available CAN channels in the computer. The virtual channels are included in this number.
Parameters: None Returns: chanCount (int) – Number of available CAN channels
-
canlib.canlib.
getVersion
[source]¶ Get the CANlib DLL version number as a
str
Deprecated since version 1.5: Use
dllversion
instead.
-
canlib.canlib.
initializeLibrary
()[source]¶ Initialize CANlib library
Note
This initializes the driver and must be called before any other function in the CANlib DLL is used. This is handled in most cases by the Python wrapper but if you want to trigger a re-enumeration of connected devices, call this function.
Any errors encountered during library initialization will be “silent” and an appropriate error code will be returned later on when an API call that requires initialization is called.
-
canlib.canlib.
openChannel
(channel, flags=0, bitrate=None, data_bitrate=None)[source]¶ Open CAN channel
Retrieves a canChannel object for the given CANlib channel number using the supplied flags.
Parameters: - channel (int) – CANlib channel number
- flags (int) – Flags, a combination of the
canlib.canlib.Open
flag values. Default is zero, i.e. no flags. - bitrate (canBITRATE_XXX or canFD_BITRATE_XXX) – The desired bitrate. Must be one of the predefined canBITRATE_XXX (for classic CAN) or canFD_BITRATE_XXX (for CAN FD) constants. For CAN FD, this is the arbitration bitrate.
- data_bitrate (canFD_BITRATE_XXX) – The desired data bitrate for CAN FD. Must be one of the predefined canFD_BITRATE_XXX constants. This is only valid when opening a CAN FD channel.
Returns: A canChannel object created with channel and flags
New in version 1.6: The
bitrate
anddata_bitrate
arguments.
-
canlib.canlib.
reinitializeLibrary
()[source]¶ Reinitializes the CANlib driver.
Convenience function that calls
unloadLibrary
andinitializeLibrary
in succession.
-
canlib.canlib.
translateBaud
(freq)[source]¶ Translate bitrate constant
This function translates the canBITRATE_xxx constants to their corresponding bus parameter values.
Parameters: freq – Any of the predefined constants canBITRATE_xxx Returns: - A bitrateSetting object containing the actual values of
- frequency, tseg1, tseg2 etc.
-
canlib.canlib.
unloadLibrary
()[source]¶ Unload CANlib
Unload canlib and release all internal handles.
Warning
Calling
unloadLibrary
invalidates every canlib-object. Use at your own risk.