CAN/en: различия между версиями

Материал из Wiren Board
(Новая страница: «The work takes place through a standard Linux subsystem - SocketCAN. CAN ports are similar to network interfaces <code>can0</code> or <code>can1</code>, depending on the controller model. For CAN to work on controllers up to version 6.7.x, you need a terminator jumper on the port. Starting from version 6.7.x, the terminator is controlled by software and turns on automatically.»)
Строка 1: Строка 1:
<languages/>The work takes place through a standard Linux subsystem - SocketCAN. CAN ports are similar to network interfaces <code>can0</code> or <code>can1</code>, depending on the controller model. For CAN to work on controllers up to version 6.7.x, you need a terminator jumper on the port. Starting from version 6.7.x, the terminator is controlled by software and turns on automatically.  
<languages/>The work takes place through a standard Linux subsystem - SocketCAN. CAN ports are similar to network interfaces <code>can0</code> or <code>can1</code>, depending on the controller model. For CAN to work on controllers up to version 6.7.x, you need a terminator jumper on the port. Starting from version 6.7.x, the terminator is controlled by software and turns on automatically.  


== Настройка ==
== Setting ==
[[Image:Can iface.png|300px|thumb|right|Настройка can-интерфейса. Allow-hotplug позволяет интерфейсу подниматься автоматически]]
[[Image:Can iface.png|300px|thumb|right|Configuring the can interface. Allow-hotplug allows the interface to rise automatically]]
[[Image:Can enable.png|300px|thumb|right|Перевод порта RS485-2 в режим CAN и включение драйвера can в linux]]
[[Image:Can enable.png|300px|thumb|right|Setting the RS485-2 port to CAN mode and enabling the can driver in linux]]


==== Через веб-интерфейс ====
==== Через веб-интерфейс ====

Версия 22:55, 3 октября 2022

Другие языки:

The work takes place through a standard Linux subsystem - SocketCAN. CAN ports are similar to network interfaces can0 or can1, depending on the controller model. For CAN to work on controllers up to version 6.7.x, you need a terminator jumper on the port. Starting from version 6.7.x, the terminator is controlled by software and turns on automatically.

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

Через веб-интерфейс

Для настройки через веб-интерфейс нужно обновить пакет wb-mqtt-confed до версии 1.2.3+

Действия происходят в разделе Configs веб-интерфейса:

  1. На вкладке Network Interfaces добавьте новый интерфейс can0 (см. скриншот). Нажмите кнопку Save.
  2. Переключите порт RS-485/CAN в режим CAN: на вкладке Hardware Modules Configuration выберите настройки RS485-2/CAN interface config, выберите в поле Module type «CAN interface» и нажмите кнопку Save.

CAN-интерфейс будет подниматься сам при:

  • загрузке системы — за это отвечает сервис wb-hwconf-manager,
  • смене режима порта RS-485/2 в «CAN».

Стандартными средствами linux (автоматически)

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

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

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

Стандартными средствами linux (вручную)

После переключения порта в режим CAN, нужно выполнить:

ip link set can0 up type can bitrate 125000

Работа с CAN

Утилиты cansend и candump есть в стандартном наборе ПО контроллера. Если по каким-то причинам их нет, можно поставить пакет can-utils:

apt update && apt install can-utils

Примеры команд:

  • Отправка четырех байт c адресом 123:
    cansend can0 123#DEADBEEF
    
  • Показывать входящие пакеты:
    candump can0
    
  • Показать статистику:
    cat /proc/net/can/stats
    


Обратите внимание, что в случае проблем на шине (нет терминатора, нет принимающего устройства, короткое замыкание), контроллер может прекратить работу. Для того чтобы начать работу вновь, выполните:

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

Больше информации смотрите в вики проекта «AmadeuS», статья «CAN bus Linux driver».