Vector#

This interface adds support for CAN controllers by Vector. Only Windows is supported.

Configuration#

By default this library uses the channel configuration for CANalyzer. To use a different application, open Vector Hardware Configuration program and create a new application and assign the channels you may want to use. Specify the application name as app_name='Your app name' when constructing the bus or in a config file.

Channel should be given as a list of channels starting at 0.

Here is an example configuration file connecting to CAN 1 and CAN 2 for an application named “python-can”:

[default]
interface = vector
channel = 0, 1
app_name = python-can

VectorBus#

class can.interfaces.vector.VectorBus(channel, can_filters=None, poll_interval=0.01, receive_own_messages=False, bitrate=None, rx_queue_size=16384, app_name='CANalyzer', serial=None, fd=False, data_bitrate=None, sjw_abr=2, tseg1_abr=6, tseg2_abr=3, sjw_dbr=2, tseg1_dbr=6, tseg2_dbr=3, **kwargs)[source]#

Bases: can.bus.BusABC

The CAN Bus implemented for the Vector interface.

Parameters
  • channel (Union[int, Sequence[int], str]) – The channel indexes to create this bus with. Can also be a single integer or a comma separated string.

  • can_filters (Optional[Sequence[Union[can.typechecking.CanFilter, can.typechecking.CanFilterExtended]]]) – See can.BusABC.

  • receive_own_messages (bool) – See can.BusABC.

  • poll_interval (float) – Poll interval in seconds.

  • bitrate (Optional[int]) – Bitrate in bits/s.

  • rx_queue_size (int) – Number of messages in receive queue (power of 2). CAN: range 16…32768 CAN-FD: range 8192…524288

  • app_name (Optional[str]) – Name of application in Vector Hardware Config. If set to None, the channel should be a global channel index.

  • serial (Optional[int]) – Serial number of the hardware to be used. If set, the channel parameter refers to the channels ONLY on the specified hardware. If set, the app_name does not have to be previously defined in Vector Hardware Config.

  • fd (bool) – If CAN-FD frames should be supported.

  • data_bitrate (Optional[int]) – Which bitrate to use for data phase in CAN FD. Defaults to arbitration bitrate.

  • sjw_abr (int) – Bus timing value sample jump width (arbitration).

  • tseg1_abr (int) – Bus timing value tseg1 (arbitration)

  • tseg2_abr (int) – Bus timing value tseg2 (arbitration)

  • sjw_dbr (int) – Bus timing value sample jump width (data)

  • tseg1_dbr (int) – Bus timing value tseg1 (data)

  • tseg2_dbr (int) – Bus timing value tseg2 (data)

  • kwargs (Any) –

Raises
Return type

None

send(msg, timeout=None)[source]#

Transmit a message to the CAN bus.

Override this method to enable the transmit path.

Parameters
  • msg (Message) – A message object.

  • timeout (Optional[float]) – If > 0, wait up to this many seconds for message to be ACK’ed or for transmit queue to be ready depending on driver implementation. If timeout is exceeded, an exception will be raised. Might not be supported by all interfaces. None blocks indefinitely.

Raises

CanOperationError – If an error occurred while sending

Return type

None

flush_tx_buffer()[source]#

Discard every message that may be queued in the output buffer(s).

Return type

None

shutdown()[source]#

Called to carry out any interface specific cleanup required in shutting down a bus.

Return type

None

static popup_vector_hw_configuration(wait_for_finish=0)[source]#

Open vector hardware configuration window.

Parameters

wait_for_finish (int) – Time to wait for user input in milliseconds.

Return type

None

static get_application_config(app_name, app_channel)[source]#

Retrieve information for an application in Vector Hardware Configuration.

Parameters
  • app_name (str) – The name of the application.

  • app_channel (int) – The channel of the application.

Returns

Returns a tuple of the hardware type, the hardware index and the hardware channel.

Raises

can.interfaces.vector.VectorInitializationError – If the application name does not exist in the Vector hardware configuration.

Return type

Tuple[can.interfaces.vector.xldefine.XL_HardwareType, int, int]

static set_application_config(app_name, app_channel, hw_type, hw_index, hw_channel, **kwargs)[source]#

Modify the application settings in Vector Hardware Configuration.

This method can also be used with a channel config dictionary:

import can
from can.interfaces.vector import VectorBus

configs = can.detect_available_configs(interfaces=['vector'])
cfg = configs[0]
VectorBus.set_application_config(app_name="MyApplication", app_channel=0, **cfg)
Parameters
  • app_name (str) – The name of the application. Creates a new application if it does not exist yet.

  • app_channel (int) – The channel of the application.

  • hw_type (can.interfaces.vector.xldefine.XL_HardwareType) – The hardware type of the interface. E.g XL_HardwareType.XL_HWTYPE_VIRTUAL

  • hw_index (int) – The index of the interface if multiple interface with the same hardware type are present.

  • hw_channel (int) – The channel index of the interface.

  • kwargs (Any) –

Raises

can.interfaces.vector.VectorInitializationError – If the application name does not exist in the Vector hardware configuration.

Return type

None

set_filters(filters=None)#

Apply filtering to all messages received by this Bus.

All messages that match at least one filter are returned. If filters is None or a zero length sequence, all messages are matched.

Calling without passing any filters will reset the applied filters to None.

Parameters

filters (Optional[Sequence[Union[can.typechecking.CanFilter, can.typechecking.CanFilterExtended]]]) –

A iterable of dictionaries each containing a “can_id”, a “can_mask”, and an optional “extended” key.

>>> [{"can_id": 0x11, "can_mask": 0x21, "extended": False}]

A filter matches, when <received_can_id> & can_mask == can_id & can_mask. If extended is set as well, it only matches messages where <received_is_extended> == extended. Else it matches every messages based only on the arbitration ID and mask.

Return type

None

recv(timeout=None)#

Block waiting for a message from the Bus.

Parameters

timeout (Optional[float]) – seconds to wait for a message or None to wait indefinitely

Returns

None on timeout or a Message object.

Raises

CanOperationError – If an error occurred while reading

Return type

Optional[can.message.Message]

send_periodic(msgs, period, duration=None, store_task=True)#

Start sending messages at a given period on this bus.

The task will be active until one of the following conditions are met:

  • the (optional) duration expires

  • the Bus instance goes out of scope

  • the Bus instance is shutdown

  • stop_all_periodic_tasks() is called

  • the task’s stop() method is called.

Parameters
  • msgs (Union[can.message.Message, Sequence[can.message.Message]]) – Message(s) to transmit

  • period (float) – Period in seconds between each message

  • duration (Optional[float]) – Approximate duration in seconds to continue sending messages. If no duration is provided, the task will continue indefinitely.

  • store_task (bool) – If True (the default) the task will be attached to this Bus instance. Disable to instead manage tasks manually.

Returns

A started task instance. Note the task can be stopped (and depending on the backend modified) by calling the task’s stop() method.

Return type

can.broadcastmanager.CyclicSendTaskABC

Note

Note the duration before the messages stop being sent may not be exactly the same as the duration specified by the user. In general the message will be sent at the given rate until at least duration seconds.

Note

For extremely long running Bus instances with many short lived tasks the default api with store_task==True may not be appropriate as the stopped tasks are still taking up memory as they are associated with the Bus instance.

stop_all_periodic_tasks(remove_tasks=True)#

Stop sending any messages that were started using send_periodic().

Note

The result is undefined if a single task throws an exception while being stopped.

Parameters

remove_tasks (bool) – Stop tracking the stopped tasks.

Return type

None

Exceptions#

exception can.interfaces.vector.VectorError(error_code, error_string, function)[source]#

Bases: can.exceptions.CanError

exception can.interfaces.vector.VectorInitializationError(error_code, error_string, function)[source]#

Bases: can.interfaces.vector.exceptions.VectorError, can.exceptions.CanInitializationError

exception can.interfaces.vector.VectorOperationError(error_code, error_string, function)[source]#

Bases: can.interfaces.vector.exceptions.VectorError, can.exceptions.CanOperationError

Miscellaneous#

can.interfaces.vector.get_channel_configs()[source]#

Read channel properties from Vector XL API.

Return type

List[can.interfaces.vector.canlib.VectorChannelConfig]

class can.interfaces.vector.VectorChannelConfig(name, hw_type, hw_index, hw_channel, channel_index, channel_mask, channel_capabilities, channel_bus_capabilities, is_on_bus, connected_bus_type, bus_params, serial_number, article_number, transceiver_name)[source]#

Bases: NamedTuple

NamedTuple which contains the channel properties from Vector XL API.

Parameters
class can.interfaces.vector.canlib.VectorBusParams(bus_type, can, canfd)[source]#

Bases: NamedTuple

Parameters
class can.interfaces.vector.canlib.VectorCanParams(bitrate, sjw, tseg1, tseg2, sam, output_mode, can_op_mode)[source]#

Bases: NamedTuple

Parameters
class can.interfaces.vector.canlib.VectorCanFdParams(bitrate, data_bitrate, sjw_abr, tseg1_abr, tseg2_abr, sam_abr, sjw_dbr, tseg1_dbr, tseg2_dbr, output_mode, can_op_mode)[source]#

Bases: NamedTuple

Parameters
class can.interfaces.vector.xldefine.XL_HardwareType(value)[source]#

Bases: enum.IntEnum

An enumeration.

XL_HWTYPE_NONE = 0#
XL_HWTYPE_VIRTUAL = 1#
XL_HWTYPE_CANCARDX = 2#
XL_HWTYPE_CANAC2PCI = 6#
XL_HWTYPE_CANCARDY = 12#
XL_HWTYPE_CANCARDXL = 15#
XL_HWTYPE_CANCASEXL = 21#
XL_HWTYPE_CANCASEXL_LOG_OBSOLETE = 23#
XL_HWTYPE_CANBOARDXL = 25#
XL_HWTYPE_CANBOARDXL_PXI = 27#
XL_HWTYPE_VN2600 = 29#
XL_HWTYPE_VN2610 = 29#
XL_HWTYPE_VN3300 = 37#
XL_HWTYPE_VN3600 = 39#
XL_HWTYPE_VN7600 = 41#
XL_HWTYPE_CANCARDXLE = 43#
XL_HWTYPE_VN8900 = 45#
XL_HWTYPE_VN8950 = 47#
XL_HWTYPE_VN2640 = 53#
XL_HWTYPE_VN1610 = 55#
XL_HWTYPE_VN1630 = 57#
XL_HWTYPE_VN1640 = 59#
XL_HWTYPE_VN8970 = 61#
XL_HWTYPE_VN1611 = 63#
XL_HWTYPE_VN5240 = 64#
XL_HWTYPE_VN5610 = 65#
XL_HWTYPE_VN5620 = 66#
XL_HWTYPE_VN7570 = 67#
XL_HWTYPE_VN5650 = 68#
XL_HWTYPE_IPCLIENT = 69#
XL_HWTYPE_IPSERVER = 71#
XL_HWTYPE_VX1121 = 73#
XL_HWTYPE_VX1131 = 75#
XL_HWTYPE_VT6204 = 77#
XL_HWTYPE_VN1630_LOG = 79#
XL_HWTYPE_VN7610 = 81#
XL_HWTYPE_VN7572 = 83#
XL_HWTYPE_VN8972 = 85#
XL_HWTYPE_VN0601 = 87#
XL_HWTYPE_VN5640 = 89#
XL_HWTYPE_VX0312 = 91#
XL_HWTYPE_VH6501 = 94#
XL_HWTYPE_VN8800 = 95#
XL_HWTYPE_IPCL8800 = 96#
XL_HWTYPE_IPSRV8800 = 97#
XL_HWTYPE_CSMCAN = 98#
XL_HWTYPE_VN5610A = 101#
XL_HWTYPE_VN7640 = 102#
XL_HWTYPE_VX1135 = 104#
XL_HWTYPE_VN4610 = 105#
XL_HWTYPE_VT6306 = 107#
XL_HWTYPE_VT6104A = 108#
XL_HWTYPE_VN5430 = 109#
XL_HWTYPE_VTSSERVICE = 110#
XL_HWTYPE_VN1530 = 112#
XL_HWTYPE_VN1531 = 113#
XL_HWTYPE_VX1161A = 114#
XL_HWTYPE_VX1161B = 115#
XL_MAX_HWTYPE = 120#
class can.interfaces.vector.xldefine.XL_ChannelCapabilities(value)[source]#

Bases: enum.IntFlag

An enumeration.

XL_CHANNEL_FLAG_TIME_SYNC_RUNNING = 1#
XL_CHANNEL_FLAG_NO_HWSYNC_SUPPORT = 1024#
XL_CHANNEL_FLAG_SPDIF_CAPABLE = 16384#
XL_CHANNEL_FLAG_CANFD_BOSCH_SUPPORT = 536870912#
XL_CHANNEL_FLAG_CMACTLICENSE_SUPPORT = 1073741824#
XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT = 2147483648#
class can.interfaces.vector.xldefine.XL_BusCapabilities(value)[source]#

Bases: enum.IntFlag

An enumeration.

XL_BUS_COMPATIBLE_CAN = 1#
XL_BUS_ACTIVE_CAP_CAN = 65536#
XL_BUS_COMPATIBLE_LIN = 2#
XL_BUS_ACTIVE_CAP_LIN = 131072#
XL_BUS_COMPATIBLE_FLEXRAY = 4#
XL_BUS_ACTIVE_CAP_FLEXRAY = 262144#
XL_BUS_COMPATIBLE_MOST = 16#
XL_BUS_ACTIVE_CAP_MOST = 1048576#
XL_BUS_COMPATIBLE_DAIO = 64#
XL_BUS_ACTIVE_CAP_DAIO = 4194304#
XL_BUS_COMPATIBLE_J1708 = 256#
XL_BUS_ACTIVE_CAP_J1708 = 16777216#
XL_BUS_COMPATIBLE_KLINE = 2048#
XL_BUS_ACTIVE_CAP_KLINE = 134217728#
XL_BUS_COMPATIBLE_ETHERNET = 4096#
XL_BUS_ACTIVE_CAP_ETHERNET = 268435456#
XL_BUS_COMPATIBLE_A429 = 8192#
XL_BUS_ACTIVE_CAP_A429 = 536870912#
class can.interfaces.vector.xldefine.XL_BusTypes(value)[source]#

Bases: enum.IntFlag

An enumeration.

XL_BUS_TYPE_NONE = 0#
XL_BUS_TYPE_CAN = 1#
XL_BUS_TYPE_LIN = 2#
XL_BUS_TYPE_FLEXRAY = 4#
XL_BUS_TYPE_AFDX = 8#
XL_BUS_TYPE_MOST = 16#
XL_BUS_TYPE_DAIO = 64#
XL_BUS_TYPE_J1708 = 256#
XL_BUS_TYPE_KLINE = 2048#
XL_BUS_TYPE_ETHERNET = 4096#
XL_BUS_TYPE_A429 = 8192#
class can.interfaces.vector.xldefine.XL_OutputMode(value)[source]#

Bases: enum.IntEnum

An enumeration.

XL_OUTPUT_MODE_SILENT = 0#
XL_OUTPUT_MODE_NORMAL = 1#
XL_OUTPUT_MODE_TX_OFF = 2#
XL_OUTPUT_MODE_SJA_1000_SILENT = 3#
class can.interfaces.vector.xldefine.XL_CANFD_BusParams_CanOpMode(value)[source]#

Bases: enum.IntFlag

An enumeration.

XL_BUS_PARAMS_CANOPMODE_CAN20 = 1#
XL_BUS_PARAMS_CANOPMODE_CANFD = 2#
XL_BUS_PARAMS_CANOPMODE_CANFD_NO_ISO = 8#
class can.interfaces.vector.xldefine.XL_Status(value)[source]#

Bases: enum.IntEnum

An enumeration.

XL_SUCCESS = 0#
XL_PENDING = 1#
XL_ERR_QUEUE_IS_EMPTY = 10#
XL_ERR_QUEUE_IS_FULL = 11#
XL_ERR_TX_NOT_POSSIBLE = 12#
XL_ERR_NO_LICENSE = 14#
XL_ERR_WRONG_PARAMETER = 101#
XL_ERR_TWICE_REGISTER = 110#
XL_ERR_INVALID_CHAN_INDEX = 111#
XL_ERR_INVALID_ACCESS = 112#
XL_ERR_PORT_IS_OFFLINE = 113#
XL_ERR_CHAN_IS_ONLINE = 116#
XL_ERR_NOT_IMPLEMENTED = 117#
XL_ERR_INVALID_PORT = 118#
XL_ERR_HW_NOT_READY = 120#
XL_ERR_CMD_TIMEOUT = 121#
XL_ERR_CMD_HANDLING = 122#
XL_ERR_HW_NOT_PRESENT = 129#
XL_ERR_NOTIFY_ALREADY_ACTIVE = 131#
XL_ERR_INVALID_TAG = 132#
XL_ERR_INVALID_RESERVED_FLD = 133#
XL_ERR_INVALID_SIZE = 134#
XL_ERR_INSUFFICIENT_BUFFER = 135#
XL_ERR_ERROR_CRC = 136#
XL_ERR_BAD_EXE_FORMAT = 137#
XL_ERR_NO_SYSTEM_RESOURCES = 138#
XL_ERR_NOT_FOUND = 139#
XL_ERR_INVALID_ADDRESS = 140#
XL_ERR_REQ_NOT_ACCEP = 141#
XL_ERR_INVALID_LEVEL = 142#
XL_ERR_NO_DATA_DETECTED = 143#
XL_ERR_INTERNAL_ERROR = 144#
XL_ERR_UNEXP_NET_ERR = 145#
XL_ERR_INVALID_USER_BUFFER = 146#
XL_ERR_INVALID_PORT_ACCESS_TYPE = 147#
XL_ERR_NO_RESOURCES = 152#
XL_ERR_WRONG_CHIP_TYPE = 153#
XL_ERR_WRONG_COMMAND = 154#
XL_ERR_INVALID_HANDLE = 155#
XL_ERR_RESERVED_NOT_ZERO = 157#
XL_ERR_INIT_ACCESS_MISSING = 158#
XL_ERR_WRONG_VERSION = 160#
XL_ERR_CANNOT_OPEN_DRIVER = 201#
XL_ERR_WRONG_BUS_TYPE = 202#
XL_ERR_DLL_NOT_FOUND = 203#
XL_ERR_INVALID_CHANNEL_MASK = 204#
XL_ERR_NOT_SUPPORTED = 205#
XL_ERR_CONNECTION_BROKEN = 210#
XL_ERR_CONNECTION_CLOSED = 211#
XL_ERR_INVALID_STREAM_NAME = 212#
XL_ERR_CONNECTION_FAILED = 213#
XL_ERR_STREAM_NOT_FOUND = 214#
XL_ERR_STREAM_NOT_CONNECTED = 215#
XL_ERR_QUEUE_OVERRUN = 216#
XL_ERROR = 255#
XL_ERR_INVALID_DLC = 513#
XL_ERR_INVALID_CANID = 514#
XL_ERR_INVALID_FDFLAG_MODE20 = 515#
XL_ERR_EDL_RTR = 516#
XL_ERR_EDL_NOT_SET = 517#
XL_ERR_UNKNOWN_FLAG = 518#