Vector

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

By default this library uses the channel configuration for CANalyzer. To use a different application, open Vector Hardware Config 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

If you are using Python 2.7 it is recommended to install pywin32, otherwise a slow and CPU intensive polling will be used when waiting for new messages.

Bus

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 (list) – The channel indexes to create this bus with. Can also be a single integer or a comma separated string.
  • poll_interval (float) – Poll interval in seconds.
  • bitrate (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 (str) – Name of application in Hardware Config. If set to None, the channel should be a global channel index.
  • serial (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 is unused.
  • fd (bool) – If CAN-FD frames should be supported.
  • data_bitrate (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)
flush_tx_buffer()[source]

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

static get_application_config(app_name, app_channel, bus_type)[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.
  • bus_type (XL_BusTypes) – The bus type Enum e.g. XL_BusTypes.XL_BUS_TYPE_CAN
Return type:

Tuple[XL_HardwareType, int, int]

Returns:

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

Raises:

VectorError – Raises a VectorError when the application name does not exist in Vector Hardware Configuration.

handle_can_event(event)[source]

Handle non-message CAN events.

Method is called by _recv_internal() when event.tag is not XL_RECEIVE_MSG. Subclasses can implement this method.

Parameters:event (XLevent) – XLevent that could have a XL_CHIP_STATE, XL_TIMER or XL_SYNC_PULSE tag.
Return type:None
Returns:None
handle_canfd_event(event)[source]

Handle non-message CAN FD events.

Method is called by _recv_internal() when event.tag is not XL_CAN_EV_TAG_RX_OK or XL_CAN_EV_TAG_TX_OK. Subclasses can implement this method.

Parameters:event (XLcanRxEvent) – XLcanRxEvent that could have a XL_CAN_EV_TAG_RX_ERROR, XL_CAN_EV_TAG_TX_ERROR, XL_TIMER or XL_CAN_EV_TAG_CHIP_STATE tag.
Return type:None
Returns: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
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:

can.CanError – if the message could not be sent

static set_application_config(app_name, app_channel, hw_type, hw_index, hw_channel, bus_type)[source]

Modify the application settings in Vector Hardware Configuration.

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 (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.
  • bus_type (XL_BusTypes) – The bus type of the interfaces, which should be XL_BusTypes.XL_BUS_TYPE_CAN for most cases.
Return type:

None

set_timer_rate(timer_rate_ms)[source]

Set the cyclic event rate of the port.

Once set, the port will generate a cyclic event with the tag XL_EventTags.XL_TIMER. This timer can be used to keep an application alive. See XL Driver Library Description for more information

Parameters:timer_rate_ms (int) – The timer rate in ms. The minimal timer rate is 1ms, a value of 0 deactivates the timer events.
Return type:None
shutdown()[source]

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

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

Bases: can.CanError