Jump to content

CAN

From Wiren Board
This is the approved revision of this page, as well as being the most recent.

Описание

Работа происходит через стандартную подсистему Linux — SocketCAN. В Wiren Board 6 и Wiren Board 7 один встроенный порт CAN, он работает вместо порта RS485-2 после переключения режима. Порт доступен в системе как сетевой интерфейс can0 или can1, в зависимости от модели контроллера. Для работы CAN на контроллерах до версии 6.7.x нужен джампер терминатора на порту. Начиная с версии 6.7.x терминатор 120 Ом включается программно в настройках порта, по умолчанию он выключен.

В Wiren Board 8 встроенного порта CAN нет, порты добавляют модули расширения WBE2-I-CAN-ISO v.2: до двух в Wiren Board 8.4 и до четырёх в Wiren Board 8.5 и 8M. Интерфейс модуля называется canMODx, где x — номер внутреннего слота, терминатор включается в настройках модуля и по умолчанию включён. В примерах ниже вместо can0 подставьте имя своего интерфейса.

Setting

Configuring the can interface. Allow-hotplug allows the interface to rise automatically
Setting the RS485-2 port to CAN mode and enabling the can driver in linux

Via web interface

To configure via the web interface, you need to update the wb-mqtt-confed package to version 1.2.3+

The CAN interface will rise by itself when:

  • system boot - service wb-hwconf-manager is responsible for this,
  • change the RS-485/2 port mode to «CAN».

Using standard linux tools (automatically)

The Network Interfaces section of the web interface is a wrapper around the /etc/network/interfaces file, so CAN configuration can be done using the debian network management service. For this you need:

  1. Add to /etc/network/interfaces an entry like this:
    allow-hotplug can0
    iface can0 can static
    bitrate 125000
    
  2. Switch RS-485-2 port to CAN mode

We will get a result similar to setting through the web-interface.

Веб-интерфейс хранит CAN-соединение в файле /etc/network/interfaces, поэтому настройку CAN можно произвести с помощью службы управления сетями ОС Debian. Для этого нужно:

  1. Добавить в /etc/network/interfaces запись вида:
    allow-hotplug can0
    iface can0 can static
        bitrate 125000
  2. Переключить порт RS-485-2 в режим CAN

Получим результат, аналогичный настройке через веб-интерфейс.

Using standard linux tools (manually)

After switching the port to CAN mode, you need to do:

ip link set can0 up type can bitrate 125000

Working with CAN

The cansend and candump utilities are included in the controller's standard software package. If for some reason they are not there, you can install the can-utils package:

apt update && apt install can-utils

Command examples:

  • Sending four bytes with address 123:
    cansend can0 123#DEADBEEF
    
  • Show incoming packets:
    candump can0
    
  • Show statistics:
    cat /proc/net/can/stats
    


Please note that in case of problems on the bus (no terminator, no receiving device, short circuit), the controller may stop working. To start working again, run:

ifconfig can0 down && ip link set can0 up type can bitrate 125000

For more information see the «AmadeuS» wiki article «CAN bus Linux driver».