- iDigi Dia Home
- User
  - Getting Started
  - Dia Concepts
  - Devices
  - Loggers
  - Presentations
  - Services
  - Tracing
- Developer
  - Overview
  - Drivers
  - Loggers
  - Presentations
  - Services
  - Integrating Application
  - Tracing Manager
  - Debugging
  - Specific Considerations
  - API Reference

- Email
- Phone
- Contact us:

### Navigation

- index
- iDigi Dia |

# CAN Device

## Overview

This device provides a generic and low level CAN support to the iDigi Dia framework. By adding a new CAN device to an iDigi Dia project, user will be able to configure some general BUS settings such as bus speed (Baud Rate) or CAN interface and then several specific settings for each filter channel (up to 4 channels).

Filter channels let user to capture specific ID CAN messages previously configured in the project. These messages will remain in the channel until they are replaced by new ones.

CAN Device will also be able to send messages to the CAN Bus making use of a transmit channel. Transmit channel let user to write the data to be sent later to the CAN Bus.

## Configuration

A typical CAN device configuration block looks like this:

    - name: can0
      driver: devices.can_device:CANDevice
      settings:
          baud_rate: 125000
          interface: 0
          filters:
            - filter_length: 11
              filter_id: 0x700
              filter_mask: 0x7FF

            - filter_length: 11
              filter_id: 0x700
              filter_mask: 0x700

### Settings

baud_rate (required, default: 125000)
  Bus speed in bits per second (bps).
interface (required, default: 0)
  Select the CAN interface the driver will use (`0` or `1`). Not all devices might have 2 available interfaces.
filters (required)

  The list of filters. Each filter has the following settings:

  filter_length (required, default: 11)
    Specify whether the filter will trigger for IDs of `11` or `29` bits.
  filter_id (optional, default: 0)
    Specify the starting Message ID value to capture messages for this filter. To capture all messages, `0` must be set in both Filter ID and Filter mask options.
  filter_mask (optional, default: 0)
    Specify the last Message ID value to capture messages for this filter. To capture all messages, `0` must be set in both Filter ID and Filter mask options.

## Channels

packets_sent (Get, type: integer)
  Displays the number total packets sent by the device.
packets_filtered (Get, type: integer)
  Displays the number total packets filtered by any of the configured filters.
packets_received (Get, type: integer)
  Displays the number total packets received.
reset_stats (Set, type: string)
  Resets the statistic channels (packets_sent, packets_filtered and packets_received). Write anything to reset them.
speed (Get, type: integer, unit: bps)
  Displays the baud rate configured for the driver in bits per second.
data_send (Set, type: string)

  Sends a message to the CAN bus. Message must be a string with the following structure:

  `"{'ID': 0x07E5, 'ID_Length': 11, 'Is_Remote': False, 'Data': '\x01\x02\x03\x04\x05\x06\x07\x08'}"`

  Where:

  - ID: Is the CAN ID of the message.
  - ID_Length: Is the header length (in bits) of the message. 11 bits for standard and 29 for extended.
  - Is_Remote: Indicates whether the message is RTR (True) or not (False).
  - Data: Contains the byte-string value of the message.

### Filter channels

For each configured (enabled) filter, the driver will generate a filter channel containing its latest captured message. The channel data is a string with the same structure as the data_send channel.

`"{'ID': 0x07E5, 'ID_Length': 11, 'Is_Remote': False, 'Data': '\x01\x02\x03\x04\x05\x06\x07\x08'}"`

Where:

- ID: Is the CAN ID of the message.
- ID_Length: Is the header length (in bits) of the message. 11 bits for standard and 29 for extended.
- Is_Remote: Indicates whether the message is RTR (True) or not (False).
- Data: Contains the byte-string value of the message.

This is an example of a generated filter channel:

filter0 (Get, type: string)
  Displays the latest packet captured by filter 0.

### Navigation

- index
- iDigi Dia |