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.CEnumcanFILTER_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.CEnumkvBUSTYPE_GROUP_xxx
Bus type group.
-
INTERNAL= 4¶
-
LOCAL= 2¶
-
REMOTE= 3¶
-
VIRTUAL= 1¶
-
-
class
canlib.canlib.CANLib[source]¶ Bases:
objectDeprecated 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.DllExceptionBase 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.CanErrorRaised when no matching message was available
-
status= -2¶
-
-
exception
canlib.canlib.CanNotFound[source]¶ Bases:
canlib.canlib.exceptions.CanErrorSpecified 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.CanErrorRaised 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:
objectHelper 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 (
bool) – If true, both mask and code applies to 29-bit CAN identifiers.
- mask (
-
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
Channelobject 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_xxxIf 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
-
get_io_pin(index)[source]¶ Return I/O pin using index
Returns: io_pin (IoPinType) New in version 1.8.
-
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
-
io_confirm_config()[source]¶ Confirm current I/O configuration
It is required to confirm a configuration by calling this function before accessing any I/O pins value.
New in version 1.8.
-
io_pins()[source]¶ Generator that returns all I/O pins one by one
Returns object depending on pin type and direction:
iopin.AnalogIn,iopin.AnalogOut,iopin.DigitalIn,iopin.DigitalOutoriopin.Relay.New in version 1.8.
-
iocontrol¶ canIoCtlhelper object for this channelSee the documentation for
IOControlfor 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
-
readSpecificSkip(id_)[source]¶ Read a message with specified identifier
Reads a message with a specified identifier from the receive buffer. Any preceding message not matching the specified identifier will be removed in the receive buffer. If no message with the specified identifier is available, the function returns immediately with an error code.
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
canlib.IOControl.local_txecho.Returns: canlib.Frame
-
readStatus()[source]¶ Return status for the current channel
Returns the latest status reported by the hardware in a combination of the flags
canlib.Stat(bus on/error passive + status etc).Returns: canlib.Stat
-
readSyncSpecific(id_, timeout=0)[source]¶ Wait until the receive queue contains a message with the specified id
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
canlib.IOControl.local_txecho.
-
requestChipStatus()[source]¶ Request chip status messages
Requests that the hardware report the chip status (bus on/error passive status etc.) to the driver. The chip status can later be retrieved using
canlib.Channel.readStatus.Note
The
requestChipStatusfunction is asynchronous, that is, it completes before the answer is returned from the hardware. The time between a call torequestChipStatusand the point in time where the chip status is actually available via a call tocanlib.Channel.readStatusis not defined. Thecanlib.Channel.readStatusalways returns the latest data reported by the hardware.
-
scriptGetText()[source]¶ Read text from subscribed script slots
Text-subscriptions must first be set up with
Channel.scriptRequestText.Returns: ScriptTextRaises: 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 (
-
scriptSendEvent(slotNo=0, eventType=1, eventNo=97, data=0)[source]¶ Send specified event to specified t script
Send an event with given type, event number, and associated data to a script running in a specific slot.
-
scriptStatus(slot)[source]¶ Retreives t program status for selected slot
Parameters: slot (int) – Slot number to be queried Returns: canlib.ScriptStatusNew in version 1.6.
-
setBusOutputControl(drivertype=<Driver.NORMAL: 4>)[source]¶ Set driver type
This function sets the driver type for a CAN controller to e.g. silent mode. This corresponds loosely to the bus output control register in the CAN controller, hence the name of this function.
Note
Not all CAN driver types are supported on all cards.
Parameters: drivertype ( canlib.Driver) – Driver type to set.
-
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_xxxIf 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 (
callbackin 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_rawfor sending messages without constructing Frame objects.Deprecated since version 1.5: Sending the
Framecontents 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, Noneor0xFFFFFFFFfor 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
Framecontents 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_DLCis 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.writefor 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_DLCis 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.CFlagcanCHANNEL_CAP_xxx
Channel capabilities.
Changed in version 1.8.
-
BUS_STATISTICS= <ChannelCap.BUS_STATISTICS: 2>¶
-
CAN_FD= <ChannelCap.CAN_FD: 524288>¶
-
CAN_FD_NONISO= <ChannelCap.CAN_FD_NONISO: 1048576>¶
-
DIAGNOSTICS= <ChannelCap.DIAGNOSTICS: 268435456>¶
-
ERROR_COUNTERS= <ChannelCap.ERROR_COUNTERS: 4>¶
-
EXTENDED_CAN= <ChannelCap.EXTENDED_CAN: 1>¶
-
GENERATE_ERROR= <ChannelCap.GENERATE_ERROR: 16>¶
-
GENERATE_OVERLOAD= <ChannelCap.GENERATE_OVERLOAD: 32>¶
-
IO_API= <ChannelCap.IO_API: 134217728>¶
-
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:
objectObject for querying various information about a channel
After instantiating a
ChannelDataobject 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
rawfunction, 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
BusTypeGroupenum. Not implemented in Linux. - card_firmware_rev – A
VersionNumberobject with the version of the card’s firmware. - card_hardware_rev – A
VersionNumberobject with the version of the card’s hardware. - card_number – An
intwith the card’s number in the computer. Each card type is numbered separately. - card_serial_no – An
intwith the serial number of the card, or 0 if it doesn’t have a serial number. - card_type – A member of the
HardwareTypeenum representing the hardware type of the card. - card_upc_no – An
EANobject with the EAN of the card, orNoneif it doesn’t one. - chan_no_on_card – An
intof the channel number on the card. - channel_cap – A
ChannelCapobject with the capabilities of the channel as flags. Also seechannel_cap_mask. - channel_cap_mask – A
ChannelCapwith which flags this device knows about. - channel_flags – A
ChannelFlagsobject with the status of the channel as flags. Not implemented in Linux. - channel_quality – An
intbetween 0 and 100 (inclusively) with the quality of the channel in percent of optimal quality. Not implemented in Linux. - devdescr_ascii – A
strwith the product name of the device. - devdescr_unicode – A
strwith the product name of the device. Not implemented in Linux. - device_physical_position – An
intwith the address of the device on its underlying bus. Not implemented in Linux. - devname_ascii – A
strwith the current device name. Not implemented in Linux. - dll_file_version – A
VersionNumberwith the version of the dll file. - dll_filetype – 1 if “kvalapw.dll” is used, 2 if “kvalapw2.dll”
- dll_product_version – A
VersionNumberwith the product version of the dll file. - driver_file_version – A
VersionNumberwith the version of the kernel-mode driver. Not implemented in Linux. - driver_name – A
strwith the name of the device driver. - driver_product_version – A
VersionNumberwith the product version of the kernel-mode driver. Not implemented in Linux. - feature_ean – An
EANobject with an internal EAN. This is only intended for internal use. - hw_status – Six
intwith hardware status codes. This is only intended for internal use. - is_remote – A
boolfor whether the device is currently connected as a remote device. Not implemented in Linux. - logger_type – A member of the
LoggerTypeenum. Not implemented in Linux. - max_bitrate – An
intwith the maximum bitrate of the device. Zero means no limit on the bitrate. - mfgname_ascii – A
strwith the manufacturer’s name. - mfgname_unicode – A
strwith the manufacturer’s name. Not implemented in Linux. - remote_host_name – A
strwith the remote host name of the device. Not implemented in Linux. - remote_mac – A
strwith the remote mac address of the device. Not implemented in Linux. - remote_operational_mode – A member of the
OperationalModeenum. Not implemented in Linux. - remote_profile_name – A
strwith the remote profile name of the device. Not implemented in Linux. - remote_type – A member of the
RemoteTypeenum. Not implemented in Linux. - roundtrip_time – An
intwith the roundtrip time measured in milliseconds. Not implemented in Linux. - time_since_last_seen – An
intwith the time in milliseconds since last communication occured. Not implemented in Linux. - timesync_enabled – A
boolfor whether legacy time synchronization is enabled. Not implemented in Linux. - trans_cap – A
DriverCapobject with the capabilities of the transceiver as flags. Not implemented in Linux. - trans_serial_no – An
intwith 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
TransceiverTypeenum. - trans_upc_no – An
EANobject with the EAN of the transceiver, orNoneif it doesn’t have one. Not implemented in Linux. - ui_number – An
intwith 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
canGetChannelDataParameters: - item (
ChannelDataItem) – The information to be retrieved. - ctype – The
ctypestype 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.UnionHolds 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.StructureAccess flags of
ChannelData_Channel_FlagsDeprecated since version 1.5.
Gives access to individual parts in
ChannelData_Channel_Flagsas 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.CFlagcanCHANNEL_IS_xxx
These channelFlags are used in
Channel.getChannelDataand 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.CEnumcanDRIVER_CAP_xxx
Driver (transceiver) capabilities.
-
HIGHSPEED= 1¶
-
-
exception
canlib.canlib.EnvvarException[source]¶ Bases:
canlib.exceptions.CanlibExceptionBase class for exceptions related to environment variables.
-
exception
canlib.canlib.EnvvarNameError(envvar)[source]¶ Bases:
canlib.canlib.exceptions.EnvvarExceptionRaised when the name of the environment variable is illegal.
-
exception
canlib.canlib.EnvvarValueError(envvar, type_, value)[source]¶ Bases:
canlib.canlib.exceptions.EnvvarExceptionRaised 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¶
-
IO_CONFIG_CHANGED= -46¶
-
IO_NOT_CONFIRMED= -45¶
-
IO_NO_VALID_CONFIG= -48¶
-
IO_PENDING= -47¶
-
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.CEnumcanHWTYPE_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¶
-
DINRAIL= 86¶
-
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:
objectHelper object for using
canIoCtlProvides 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
intwith the hardware bitrate limit, or zero for the device’s default. Write-only. - bus_type – A member of the
BusTypeGroupenum. Not implemented in Linux. Read-only. - buson_time_auto_reset – A
boolfor whether the CAN clock is reset at bus-on. Not implemented in Linux. Write-only. - channel_quality – An
intbetween 0 and 100 (inclusively) with the quality of the channel in percent. Not implemented in Linux. Read-only. - devname_ascii – A
strwith 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
boolfor whether error frames are reported. Not implemented in Linux. Write-only. - eventhandle – An
intwith the windows event handle. Not implemented in Linux. Read-only. - local_txecho – A
boolfor whether local transmit echo is turned on. Write-only. - report_access_errors – A
boolfor whether Access Reporting is turned on - roundtrip_time – An
intwith the roundtrip time in milliseconds. Not implemented in Linux. Read-only. - rx_buffer_level – An
intwith the approximate receive queue level. Read-only. - rx_queue_size – An
intwith the size of the receive buffer. Can only be used off-bus. Not implemented in Linux. Write-only. - throttle_scaled – An
intbetween 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
intwith the time in milliseconds since the last communication occured. Not implemented in Linux. Read-only. - timer_scale – An
intwith the time-stamp clock resolution in microseconds. - tx_buffer_level – An
intwith the approximate transmit queue level. Read-only. - tx_interval – An
intwith 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
boolfor 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.EXTwhen sending messages if neitherMessageFlag.EXTorMessageFlag.STDis specified. Not implemented in Linux.
-
prefer_std()¶ Tells CANlib to assume
MessageFlag.STDwhen sending messages if neitherMessageFlag.EXTorMessageFlag.STDis 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
canIoCtlParameters: - item (
IOControlItem) – The “function code” to be passed tocanIoCtl. - value – The value sent to
canIoCtlorNoneif no value should be given. Must be compatible with thectypeargument. - ctype – The
ctypestype that should be used to when sending thevalueargument 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¶
-
-
exception
canlib.canlib.IoNoValidConfiguration[source]¶ Bases:
canlib.canlib.exceptions.CanErrorI/O pin configuration is invalid
No I/O pins was found, or unknown I/O pins was discovered.
New in version 1.8.
-
status= -48¶
-
-
exception
canlib.canlib.IoPinConfigurationNotConfirmed[source]¶ Bases:
canlib.canlib.exceptions.CanErrorI/O pin configuration is not confirmed
Before accessing any I/O pin value, the device I/O pin configuration must be confirmed, using e.g.
canlib.Channel.io_confirm_config.See also
canlib.iopin.Configuration.New in version 1.8.
-
status= -45¶
-
-
class
canlib.canlib.LEDAction[source]¶ Bases:
canlib.cenum.CEnumkvLED_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.CEnumkvLOGGER_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.CFlagMessage 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, andESIrequire CAN FD.RTRcannot 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
OVERRUNfor 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.CFlagcanNOTIFY_xxx
These notify flags are used in
canlib.canlib.set_callbackto 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.CEnumcanCHANNEL_OPMODE_xxx
Current WLAN operational mode.
-
ADH= 4¶
-
INFRASTRUCTURE= 2¶
-
NONE= 1¶
-
RESERVED= 3¶
-
-
class
canlib.canlib.RemoteType[source]¶ Bases:
canlib.cenum.CEnumkvREMOTE_TYPExxx
Remote type, returned when using canCHANNELDATA_REMOTE_TYPE
-
LAN= 2¶
-
NOT_REMOTE= 0¶
-
WLAN= 1¶
-
-
class
canlib.canlib.ScriptRequest[source]¶ Bases:
canlib.cenum.CEnumkvSCRIPT_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.CFlagStatus of t program
New in version 1.6.
Changed in version 1.7: Is now based on
IntFlaginstead ofIntEnum-
IDLE= <ScriptStatus.IDLE: 0>¶
-
LOADED= <ScriptStatus.LOADED: 1>¶
-
RUNNING= <ScriptStatus.RUNNING: 2>¶
-
-
class
canlib.canlib.ScriptText[source]¶ Bases:
strText returned by
Channel.scriptGetTextSubclass of built-in
str, so it can be used just like a normal 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.CFlagcanSTAT_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.CEnumTransceiver (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:
objectThe 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
SourceElementtuples 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
TxeFileIsEncryptedexception 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:
canlib.exceptions.CanlibExceptionRaised when trying to access
Txe.sourceand the source and byte-code sections of the .txe binary have been encrypted.New in version 1.6.
-
class
canlib.canlib.bitrateSetting(freq=1000000, tseg1=4, tseg2=3, sjw=1, nosamp=1, syncMode=0)[source]¶ Bases:
objectClass 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
BetaVersionNumberif 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
ChannelDataand theircard_numberattribute 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
ChannelDataand theirchan_no_on_cardattribute 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
ChannelDataand theirchannel_flagsattribute instead.Returns a
ChannelData_Channel_Flagsobject 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
ChannelDataand theircustom_nameattribute 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
ChannelDataand theirdriver_nameattribute 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
ChannelDataand theircard_upc_noattribute 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
ChannelDataand 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
ChannelDataand theircard_firmware_revattribute 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
ChannelDataand theirdevice_nameattribute 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
ChannelDataand theircard_serial_noattribute 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
strDeprecated since version 1.5: Use
dllversioninstead.
-
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.Openflag 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
bitrateanddata_bitratearguments.
-
canlib.canlib.prodversion()[source]¶ Get the CANlib Product version number
Parameters: None Returns a
BetaVersionNumberif the CANlib driver/DLL is marked as beta (preview), otherwise returnsVersionNumber.New in version 1.6.
-
canlib.canlib.reinitializeLibrary()[source]¶ Reinitializes the CANlib driver.
Convenience function that calls
unloadLibraryandinitializeLibraryin 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
unloadLibraryinvalidates every canlib-object. Use at your own risk.
Experimental support for accessing IO-pins on sub modules of the Kvaser DIN Rail SE 400S that was added to CANlib v5.26.
New in version 1.8.
-
class
canlib.canlib.iopin.AddonModule(module_type, fw_version=None, serial=None, first_pin_index=None)[source]¶ Bases:
objectContains information about one add-on module
Variables: New in version 1.9.
-
issubset(spec)[source]¶ Check if current attributes are fulfilling attributes in spec
Any attribute in spec that is set to None is automatically considered fulfilled.
The
fw_versionattribute is considered fulfilled whenself.fw_version >= spec.fw_version.This can be used to check if a specific module fulfills a manually created specification:
>>> module_spec = iopin.AddonModule(module_type=iopin.ModuleType.DIGITAL) >>> modules = iopin.Configuration(channel) >>> module[0].issubset(module_spec)
True
>>> module_spec = iopin.AddonModule(module_type=iopin.ModuleType.DIGITAL, fw_version=VersionNumber(major=3, minor=1), serial=2342)
>>> module[0].issubset(module_spec) False
config = iopin.Configuration(channel)
>>> config.issubset(config_spec) True
- config_spec = [iopin.AddonModule(module_type=iopin.ModuleType.ANALOG),
- iopin.AddonModule(module_type=iopin.ModuleType.DIGITAL,
- fw_version=VersionNumber(major=3, minor=1), serial=2342)]
>>> config.issubset(config_spec) False
-
-
class
canlib.canlib.iopin.AnalogIn(channel, pin)[source]¶ Bases:
canlib.canlib.iopin.IoPin-
hysteresis¶ The hysteresis in Volt for analog input pin
-
lp_filter_order¶ The low-pass filter order for analog input pin
-
value¶ Voltage level on the Analog input pin
-
-
class
canlib.canlib.iopin.AnalogOut(channel, pin)[source]¶ Bases:
canlib.canlib.iopin.IoPin-
value¶ Voltage level on the Analog output pin
-
-
class
canlib.canlib.iopin.CEnum[source]¶ Bases:
enum.IntEnumA ctypes-compatible IntEnum superclass.
-
class
canlib.canlib.iopin.Configuration(channel)[source]¶ Bases:
objectContains I/O pins and the
canlib.Channelto find them onCreating this object may take some time depending on the number of I/O pins availably on the given
canlib.Channel.Parameters: - channel (‘canlib.Channel’) – The channel where the discovery of I/O pins
- should take place.
Variables: - io_pins (list(
iopin.IoPin)) – All discovered I/O pins. - pin_names (list(str)) – List of label I/O pin names.
- (dict(str (pin_index) – int)): Dictionary with I/O pin label name as key, and pin index as value.
To create an
iopin.Configurationyou need to supply thecanlib.Channel, which is were we look for I/O pins:>>> from canlib.canlib import iopin
>>> from canlib import canlib, Device, EAN
>>> device = Device.find(ean=EAN('01059-8'), serial=225)
>>> channel = canlib.openChannel(device.channel_number(), canlib.Open.EXCLUSIVE)
>>> config = iopin.Configuration(channel)
Now we can investigate a specific pin by index:
>>> config.pin(index=80) Pin 80: <PinType.ANALOG: 2> <Direction.OUT: 8> bits=12 range=0.0-10.0 (<ModuleType.ANALOG: 2>)
It is also possible to find the label name from the index and vice verse for a pin, as well as access the pin using the label name:
>>> config.name(80) '4:AO1' >>> config.index('4:AO1') 80 >>> config.pin(name='4:AO1') Pin 80: <PinType.ANALOG: 2> <Direction.OUT: 8> bits=12 range=0.0-10.0 (<ModuleType.ANALOG: 2>)
Note
A configuration needs to be confirmed using
iopin.Configuration.confirm(which calls canlib.channel.io_confirm_config`) before accessing pin values:>>> config.pin(name='4:AO1').value = 4 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "...\canlib\canlib\iopin.py", line 271, in value File "...\canlib\canlib\dll.py", line 94, in _error_check raise can_error(result) canlib.canlib.exceptions.IoPinConfigurationNotConfirmed: I/O pin configuration is not confirmed (-45) I/O pin configuration is not confirmed (-45) >>> config.confirm() >>> config.pin(name='4:AO1').value = 4
An
iopin.Configurationmay be compared with an expected ordered list ofiopin.AddonModulebefore confirming usingiopin.AddonModule.issubsetChanged in version 1.9:
Configuration.modulesis now an attribute, containing an ordered list ofAddonModuleobjects.-
confirm()[source]¶ Confirm current configuration
Convenience function that calls
Channel.io_confirm_config.
-
issubset(spec)[source]¶ Check if attributes of modules in self is fulfilled by given spec
This is a convenience method that calls
AddonModule.issubseton all modules given byself.moduleswhich can be used to check if the current configuration fulfills a manually created specification:>>> config = iopin.Configuration(channel) >>> config_spec = [iopin.AddonModule(module_type=iopin.ModuleType.ANALOG),
- iopin.AddonModule(module_type=iopin.ModuleType.DIGITAL,
- fw_version=VersionNumber(major=3, minor=1), serial=2342)]
>>> config.issubset(config_spec) False
New in version 1.9.
-
class
canlib.canlib.iopin.DigitalIn(channel, pin)[source]¶ Bases:
canlib.canlib.iopin.IoPin-
high_low_filter¶ Filter time in micro seconds when a digital pin goes from HIGH to LOW
-
low_high_filter¶ Filter time in micro seconds when a digital pin goes from LOW to HIGH
-
value¶ Value on digital input pin (0 or 1)
-
-
class
canlib.canlib.iopin.DigitalOut(channel, pin)[source]¶ Bases:
canlib.canlib.iopin.IoPin-
value¶ Value on digital output pin (0 or 1)
-
-
class
canlib.canlib.iopin.DigitalValue[source]¶ Bases:
canlib.cenum.CEnumEnum used digital values
-
HIGH= 1¶
-
LOW= 0¶
-
-
class
canlib.canlib.iopin.Direction[source]¶ Bases:
canlib.cenum.CEnumEnum used for return values in
kvIoPinGetInfo-
IN= 4¶
-
OUT= 8¶
-
-
class
canlib.canlib.iopin.Info[source]¶ Bases:
canlib.cenum.CEnumEnum used for calls to
kvIoPinGetInfoandkvIoPinSetInfo-
AI_HYSTERESIS= 11¶
-
AI_LP_FILTER_ORDER= 10¶
-
DIRECTION= 2¶
-
DI_HIGH_LOW_FILTER= 9¶
-
DI_LOW_HIGH_FILTER= 8¶
-
FW_VERSION= 16¶
-
MODULE_NUMBER= 14¶
-
MODULE_TYPE= 1¶
-
NUMBER_OF_BITS= 5¶
-
PIN_TYPE= 4¶
-
RANGE_MAX= 7¶
-
RANGE_MIN= 6¶
-
SERIAL_NUMBER= 15¶
-
-
class
canlib.canlib.iopin.IoPin(channel, pin)[source]¶ Bases:
objectBase class of I/O ports
-
fw_version¶ Firmware version in module (Read-only)
Type: VersionNumber
-
hysteresis¶ Base class does not implement hysteresis attribute
-
lp_filter_order¶ Base class does not implement lp_filter_order attribute
-
module_type¶ Type of module (Read-only)
Type: ModuleType
-
number_of_bits¶ Resolution in number of bits (Read-only)
Type: int
-
range_max¶ Upper range limit in volts (Read-only)
Type: float
-
range_min¶ Lower range limit in volts (Read-only)
Type: float
-
serial¶ Module serial number (Read-only)
Type: int
-
value¶ Base class does not implement value attribute
-
-
class
canlib.canlib.iopin.ModuleType[source]¶ Bases:
canlib.cenum.CEnumEnum used for return values in
kvIoPinGetInfo-
ANALOG= 2¶
-
DIGITAL= 1¶
-
RELAY= 3¶
-
-
class
canlib.canlib.iopin.PinType[source]¶ Bases:
canlib.cenum.CEnumEnum used for return values in
kvIoPinGetInfo-
ANALOG= 2¶
-
DIGITAL= 1¶
-
RELAY= 3¶
-
-
class
canlib.canlib.iopin.Relay(channel, pin)[source]¶ Bases:
canlib.canlib.iopin.IoPin-
value¶ on)
Type: Value on relay (0 Type: off, 1
-
-
class
canlib.canlib.iopin.VersionNumber[source]¶ Bases:
tupleA tuple-subclass representing a version number
Version numbers can be created with from one to three positional arguments, representing the major, minor, and build number respectively:
v1 = VersionNumber(1) v12 = VersionNumber(1, 2) v123 = VersionNumber(1, 2, 3)
Keyword arguments can also be used:
v1 = VersionNumber(major=1) v12 = VersionNumber(major=1, minor=2) v123 = VersionNumber(major=1, minor=2, build=3)
A fourth number, the release number, can also be given as a keyword-only argument:
v1293 = VersionNumber(major=1, minor=2, release=9, build=3)
This release number is placed between the minor and build numbers, both for the string representation and in the tuple.
The major number is required and the other numbers are optional in the order minor, build, release.
All numbers can be accessed as attributes (
major,minor,release,build). If the number is unavailable, accessing the attribute returnsNone.-
beta¶
-
build¶
-
major¶
-
minor¶
-
release¶
-
-
canlib.canlib.iopin.get_io_pin(channel, index)[source]¶ Return io pin object for
indexParameters: index ( int) – The global pin numberReturns subclass of
IoPindepending on pin type and direction:AnalogIn,AnalogOut,DigitalIn,DigitalOutorRelay.
-
canlib.canlib.iopin.module_pin_names(module_type, prefix='')[source]¶ Return a list of names for
module_typeReturns a list of label names for the given type of module:
>>> iopin.module_pin_names(iopin.ModuleType.ANALOG) ['AO1', 'AO2', 'AO3', 'AO4', 'AI1', 'AI2', 'AI3', 'AI4'] >>> iopin.module_pin_names(iopin.ModuleType.RELAY) ['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'DI1', 'DI2', 'DI3', 'DI4', 'DI5', 'DI6', 'DI7', 'DI8']
Parameters: module_type ( iopin.ModuleType) – Type of module