PCAN Basic API

Interface to Peak-System’s PCAN-Basic API.

The required drivers can be downloaded here:

Configuration

Here is an example configuration file for using PCAN-USB:

[default]
interface = pcan
channel = PCAN_USBBUS1
state = can.bus.BusState.PASSIVE
bitrate = 500000

channel: (default PCAN_USBBUS1) CAN interface name

state: (default can.bus.BusState.ACTIVE) BusState of the channel

bitrate: (default 500000) Channel bitrate

Valid channel values:

PCAN_ISABUSx
PCAN_DNGBUSx
PCAN_PCIBUSx
PCAN_USBBUSx
PCAN_PCCBUSx
PCAN_LANBUSx

Where x should be replaced with the desired channel number starting at 1.

Linux installation

Kernels >= 3.4 supports the PCAN adapters natively via SocketCAN, refer to: PCAN.

Bus

class can.interfaces.pcan.PcanBus(channel='PCAN_USBBUS1', state=<BusState.ACTIVE: 1>, bitrate=500000, *args, **kwargs)[source]

A PCAN USB interface to CAN.

On top of the usual Bus methods provided, the PCAN interface includes the flash() and status() methods.

Parameters
  • channel (str) – The can interface name. An example would be ‘PCAN_USBBUS1’. Alternatively the value can be an int with the numerical value. Default is ‘PCAN_USBBUS1’

  • state (can.bus.BusState) – BusState of the channel. Default is ACTIVE

  • bitrate (int) – Bitrate of channel in bit/s. Default is 500 kbit/s. Ignored if using CanFD.

  • fd (bool) – Should the Bus be initialized in CAN-FD mode.

  • f_clock (int) – Clock rate in Hz. Any of the following: 20000000, 24000000, 30000000, 40000000, 60000000, 80000000. Ignored if not using CAN-FD. Pass either f_clock or f_clock_mhz.

  • f_clock_mhz (int) – Clock rate in MHz. Any of the following: 20, 24, 30, 40, 60, 80. Ignored if not using CAN-FD. Pass either f_clock or f_clock_mhz.

  • nom_brp (int) – Clock prescaler for nominal time quantum. In the range (1..1024) Ignored if not using CAN-FD.

  • nom_tseg1 (int) – Time segment 1 for nominal bit rate, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. In the range (1..256). Ignored if not using CAN-FD.

  • nom_tseg2 (int) – Time segment 2 for nominal bit rate, that is, the number of quanta from the sampling point to the end of the bit. In the range (1..128). Ignored if not using CAN-FD.

  • nom_sjw (int) – Synchronization Jump Width for nominal bit rate. Decides the maximum number of time quanta that the controller can resynchronize every bit. In the range (1..128). Ignored if not using CAN-FD.

  • data_brp (int) – Clock prescaler for fast data time quantum. In the range (1..1024) Ignored if not using CAN-FD.

  • data_tseg1 (int) – Time segment 1 for fast data bit rate, that is, the number of quanta from (but not including) the Sync Segment to the sampling point. In the range (1..32). Ignored if not using CAN-FD.

  • data_tseg2 (int) – Time segment 2 for fast data bit rate, that is, the number of quanta from the sampling point to the end of the bit. In the range (1..16). Ignored if not using CAN-FD.

  • data_sjw (int) – Synchronization Jump Width for fast data bit rate. Decides the maximum number of time quanta that the controller can resynchronize every bit. In the range (1..16). Ignored if not using CAN-FD.