Channel¶
openChannel()¶
-
canlib.canlib.openChannel(channel, flags=0, bitrate=None, data_bitrate=None)[source]¶ Open CAN channel
Retrieves a
Channelobject for the given CANlib channel number using the supplied flags.Example usage:
>>> bitrate = canlib.busparams.BusParamsTq( ... tq=40, ... phase1=5, ... phase2=6, ... sjw=4, ... prescaler=2, ... prop=28, ... ) >>> data_bitrate = canlib.busparams.BusParamsTq( ... tq=40, ... phase1=31, ... phase2=8, ... sjw=2, ... prescaler=2, ... ) >>> ch = canlib.openChannel( ... channel=0, ... flags=canlib.Open.CAN_FD, ... bitrate=bitrate, ... data_bitrate=data_bitrate, ... )
Note
If both
bitrateanddata_bitrateis given, both must be of the same type, i.e. either BusParamsTq or BITRATE flags. It is not supported to mix the two.Parameters: - channel (
int) – CANlib channel number - flags (
int) – Flags, a combination of theOpenflag values. Default is zero, i.e. no flags. - bitrate (
BusParamsTqorBitrateorBitrateFD) – The desired bitrate. If the bitrate is not aBusParamsTq, the predefinedBitratevalues are used for classic CAN andBitrateFDvalues are used for CAN FD, e.g.canlib.Bitrate.BITRATE_1Mandcanlib.BitrateFD.BITRATE_1M_80P. For CAN FD, this parameter gives the arbitration bitrate. - data_bitrate (
BusParamsTqorBitrateFD) – The desired data bitrate for CAN FD. If notBusParamsTqis given, the predefinedBitrateFDvalues are used, e.g.canlib.BitrateFD.BITRATE_500K_80p. This parameter is only used when opening a CAN FD channel.
Returns: A
Channelobject created with channel and flagsNew in version 1.6: The bitrate and data_bitrate arguments was added.
Changed in version 1.16: The bitrate and data_bitrate arguments now accept
BusParamsTqobjects.- channel (
ErrorCounters¶
-
class
canlib.canlib.channel.ErrorCounters(tx, rx, overrun)¶ Error counters returned by
Channel.read_error_counters.-
overrun¶ Alias for field number 2
-
rx¶ Alias for field number 1
-
tx¶ Alias for field number 0
-
Channel¶
-
class
canlib.canlib.Channel(channel_number, flags=0)[source]¶ 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.
Variables: envvar ( EnvVar) – Used to access t program environment variables-
announceIdentityEx(item, value)[source]¶ AnnounceIdentityEx function is used by certain OEM applications.
New in version 1.17.
-
bitrate_to_BusParamsTq(freq_a, freq_d=None)[source]¶ Calculate bus parameters based on predefined frequencies.
This function uses the
BitrateandBitrateFDvalues to create bus parameters for use with the new bus parameter API.Parameters: Returns: (
nominal,None) for classic CAN, wherenominalis aBusParamsTqobject.(
nominal,data) for CAN FD, where bothnominalanddataareBusParamsTqobjects, representing the arbitration bitrate and the data bitrate, respectively.New in version 1.17.
-
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 implementing a multithreaded 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
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
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 asif ((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) – IfTrue, both mask and code applies to 29-bit CAN identifiers.
-
channel_data¶ canGetHandleDatahelper object for this channelSee the documentation for
ChannelData/HandleDatafor how it can be used to perform all functionality of the C functioncanGetHandleData.New in version 1.13.
Type: HandleData
-
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.
-
device()[source]¶ Get a Device object from the current channel
Returns: Device– Device used by this channel,New in version 1.16.
-
fileCopyFromDevice(deviceFileName, hostFileName=None)[source]¶ Copy an arbitrary file from the device to the host.
Parameters: - deviceFileName (
str) – The device file name. - hostFileName (
str, optional) – The target host file name. Defaults to deviceFileName.
- deviceFileName (
-
fileCopyToDevice(hostFileName, deviceFileName=None)[source]¶ Copy an arbitrary file from the host to the () isdevice.
The filename must adhere to the FAT ‘8.3’ naming standard, max 8 characters - a dot - max 3 characters.
Parameters: - hostFileName (
str) – The target host file name. - deviceFileName (
str, optional) – The device file name. Defaults to the same as hostFileName.
- hostFileName (
-
fileDiskFormat()[source]¶ Format the disk on the device, not supported by all devices.
New in version 1.11.
-
fileGetName(fileNo)[source]¶ Get the name of the file with the supplied number.
Parameters: fileNo ( int) – The number of the file.Returns: str– The name of the file.
-
flashLeds(action, timeout_ms)[source]¶ Turn Leds on or off.
Parameters: - action (
int) – One ofLEDAction, 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 (
-
getBusOutputControl()[source]¶ Get driver type
This function retrieves the current CAN controller driver type. 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.
Returns: drivertype ( canlib.Driver) – Driver type to set.New in version 1.11.
-
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 a
BitrateFDvalue.If freq is any other value, no default values are supplied by the library.
For finding out whether a channel is opened using
CAN_FDorCAN_FD_NONISOflags, seeis_can_fd()- 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.card_number
-
getChannelData_Chan_No_On_Card[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.chan_no_on_card
-
getChannelData_Cust_Name[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.custom_name
-
getChannelData_DriverName[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.driver_name
-
getChannelData_EAN[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.card_upc_no
-
getChannelData_Firmware[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.card_firmware_rev
-
getChannelData_Name[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.device_name
-
getChannelData_Serial[source]¶ Deprecated function
Deprecated since version 1.5: Use
ChannelData;ChannelData.card_serial_no
-
get_bus_params_tq()[source]¶ Get bus timing parameters, in time quanta
This function retrieves the current bus parameters for the specified channel. Only the returned
nominalparameter is valid when classic CAN is in use.Returns: A
tuplecontaining:nominal: (
BusParamsTq) Nominal bus timing parameters, also used in classic CAN.data: (
BusParamsTq) Bus timing parameters for data rate in CAN FD.New in version 1.16.
-
get_bus_statistics()[source]¶ Return bus statistics.
Returns: structures.CanBusStatistics
-
get_io_pin(index)[source]¶ Return I/O pin using index
Returns: iopin.IoPin– io pin object for index (Any ofiopin.AnalogIn,iopin.DigitalOutetc)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.Example usage:
>>> from canlib import canlib >>> ch = canlib.openChannel(channel=0) >>> ch.iocontrol.timer_scale 1000 >>> ch.iocontrol.local_txecho = False
Type: IOControl
-
is_can_fd()[source]¶ Return
Trueif the channel has been opened with theCAN_FDorCAN_FD_NONISOflags.Returns: Trueif CAN FD,Falseotherwise.
-
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: int– One ofDeviceMode, 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 ofDeviceMode, 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.
Note
If you are using the same channel via multiple handles, 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 by setting
local_txechotoFalse(usingIOControl):>>> from canlib import canlib >>> ch = canlib.openChannel(channel=0) >>> ch.iocontrol.local_txecho = False
Parameters: timeout ( int) – Timeout in milliseconds, -1 gives an infinite timeout.Returns: canlib.FrameRaises: CanNoMsg– No CAN message is currently available.
-
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.
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
Stat(bus on/error passive + status etc).Returns: canlib.canlib.Stat
-
readSyncSpecific(id_, timeout=0)[source]¶ Wait until the receive queue contains a message with the specified id
-
read_error_counters()[source]¶ Read the error counters of the CAN controller
Returns the latest known values of the error counters in the specified circuit. If the error counters change values precisely when
read_error_countersis called, it may not be reflected in the returned result.Use
clear_error_countersviaChannel.iocontrolto clear the counters.Returns: The returned tuple is a (rx, tx, overrun)named tuple of –rx(int): Receive error countertx(int): Transmit error counteroverrun(int): Number of overrun errors.
New in version 1.11.
-
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 toChannel.readStatusis not defined. TheChannel.readStatusalways returns the latest data reported by the hardware.
-
scriptEnvvarClose(envHandle)[source]¶ Low level function to close an Envvar
This should normally not be used directly, instead opening and closing of an envvar is automatically done when accessing via the
EnvVarclass throughChannel.envvar
-
scriptEnvvarGetFloat(envHandle)[source]¶ Low level function to read an Envvar of type float
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvar
-
scriptEnvvarGetInt(envHandle)[source]¶ Low level function to read an Envvar of type int
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvar
-
scriptEnvvarOpen(name)[source]¶ Low level function to open an Envvar
This should normally not be used directly, instead opening and closing of an envvar is automatically done when accessing via the
EnvVarclass throughChannel.envvar
-
scriptEnvvarSetFloat(envHandle, value)[source]¶ Low level function to set an Envvar of type float
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvar
-
scriptEnvvarSetInt(envHandle, value)[source]¶ Low level function to set an Envvar of type int
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvar
-
scriptGetText()[source]¶ Read text from subscribed script slots
Text-subscriptions must first be set up with
Channel.scriptRequestText.Returns: ScriptTextRaises: CanNoMsg– No more text is currently available.New in version 1.7.
-
scriptLoadFile(slot, filePathOnPC)[source]¶ Load compiled script file from host(PC)
Loads a compiled script file (.txe) stored on the host (PC) into a script slot on the device. The scripts default channel will be the same channel used when this Channel object was created.
Parameters: - slot (
int) – slot containing the running script we want to stop. - filePathOnPC (
str) – Path to compiled script (.txe) to load.
- slot (
-
scriptLoadFileOnDevice(slot, localFile)[source]¶ Load compiled, locally stored, script file
Loads a compiled script file (.txe) stored locally on the device (SD card) into a script slot on the device. The scripts default channel will be the same channel used when this Channel object was created.
Parameters: - slot (
int) – slot containing the running script we want to stop. - localFile (
str) – Name of compiled script (.txe) to load.
- slot (
-
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 (
ScriptRequest) – Whether to subscribe or unsubscribe.
Text printed with
printf()by a t-program 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=None, 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 queriedReturns: canlib.ScriptStatusNew in version 1.6.
-
scriptStop(slot, mode=<ScriptStop.NORMAL: 0>)[source]¶ Stop script running in specified slot
Parameters: - slot (
int) – slot containing the running script we want to stop. - mode (
canlib.ScriptStop) – Default mode iscanlib.ScriptStop.NORMAL.
- slot (
-
script_envvar_get_data(envHandle, len, start=0)[source]¶ Low level function to read a slice of an Envvar of type char
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvarNew in version 1.10.
-
script_envvar_set_data(envHandle, value, len, start=0)[source]¶ Low level function to write a slice of an Envvar of type char
This should normally not be used directly, instead set and get the value of an envvar using the
EnvVarclass throughChannel.envvarvalueneeds to be a bytes-like object or listNew in version 1.10.
-
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 a
Bitrate, e.g.Bitrate.BITRATE_1M.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 implementing a multithreaded application, you must call
busOn()once for each handle. The same applies tobusOff()- 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.
Changed in version 1.17: Now accepts
Bitrateenumerations.
-
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 a
BitrateFDvalue, e.g.BitrateFD.BITRATE_1M_80P.If freq is any other value, no default values are supplied by the library.
For finding out whether a channel is opened using
CAN_FDorCAN_FD_NONISOflags, seeis_can_fdParameters: - 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.
Changed in version 1.17: Now accepts
BitrateFDenumerations.
-
set_bus_params_tq(nominal, data=None)[source]¶ Set bus timing parameters, using time quanta
This function sets the bus timing parameters for the specified CAN controller. When setting bus parameters for CAN FD, both
nominalanddatamust be given.If you are using multiple handles to the same physical channel, for example if you are implementing a multithreaded application, you must call
busOff()once for each handle. The physical channel will not go off bus until the last handle to the channel goes off bus. The same applies tobusOn().Parameters: - nominal (
BusParamsTq) – Nominal Bus timing parameters, also used for classic CAN - data (
BusParamsTq) – Bus timing parameters for data rate in CAN FD.
New in version 1.16.
- nominal (
-
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.Parameters: - function (
KVCALLBACK_T) – A ctypes wrapped Python function - event (
Notify) – A combination of flags to indicate what events to trigger on
New in version 1.7.
- function (
-
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.
Note
If you are using the same channel via multiple handles, 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 by setting
local_txechotoFalse(usingIOControl):>>> from canlib import canlib >>> ch = canlib.openChannel(channel=0) >>> ch.iocontrol.local_txecho = False
Also see
Channel.write_rawfor sending messages without constructingcanlib.Frameobjects.Deprecated since version 1.5: Sending the
canlib.Framecontents as separate arguments; this functionality has been taken over bywrite_raw.Parameters: frame ( canlib.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 (
canlib.Frame) – Frame containing the CAN data to be sent - timeout (
int) – The timeout, in milliseconds. 0xFFFFFFFF gives an infinite timeout.
- frame (
-
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
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
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.
-
CanBusStatistics¶
-
class
canlib.canlib.structures.CanBusStatistics[source]¶ Result from reading bus statistics using
canlib.canlib.Channel.get_bus_statistics.Variables: - busLoad (
int) – The bus load, expressed as an integer in the interval 0 - 10000 representing 0.00% - 100.00% bus load. - errFrame (
int) – Number of error frames. - extData (
int) – Number of received extended (29-bit identifiers) data frames. - extRemote (
int) – Number of received extended (29-bit identifiers) remote frames. - overruns (
int) – The number of overruns detected by the hardware, firmware or driver. - stdData (
int) – Number of received standard (11-bit identifiers) data frames. - stdRemote (
int) – Number of received standard (11-bit identifiers) remote frames.
- busLoad (