CAN/en: различия между версиями
Matveevrj (обсуждение | вклад) (Новая страница: «Actions take place in the '''Configs''' section of the web-interface: # On the '''Network Interfaces''' tab, add a new interface <code>can0</code> (see screenshot). Click the '''Save''' button. # Switch the <code>RS-485/CAN</code> port to CAN mode: on the '''Hardware Modules Configuration''' tab, select the settings '''RS485-2/CAN interface config''', select in the '''Module type''' «CAN interface» and click the '''Save''' button.») |
Matveevrj (обсуждение | вклад) (Новая страница: «The CAN interface will rise by itself when: * system boot - service <code>wb-hwconf-manager</code> is responsible for this, * change the RS-485/2 port mode to «CAN».») |
||
Строка 12: | Строка 12: | ||
# Switch the <code>RS-485/CAN</code> port to CAN mode: on the '''Hardware Modules Configuration''' tab, select the settings '''RS485-2/CAN interface config''', select in the '''Module type''' «CAN interface» and click the '''Save''' button. | # Switch the <code>RS-485/CAN</code> port to CAN mode: on the '''Hardware Modules Configuration''' tab, select the settings '''RS485-2/CAN interface config''', select in the '''Module type''' «CAN interface» and click the '''Save''' button. | ||
CAN | The CAN interface will rise by itself when: | ||
* | * system boot - service <code>wb-hwconf-manager</code> is responsible for this, | ||
* | * change the RS-485/2 port mode to «CAN». | ||
==== Стандартными средствами linux (автоматически) ==== | ==== Стандартными средствами linux (автоматически) ==== |
Версия 22:58, 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
Via web interface
To configure via the web interface, you need to update the wb-mqtt-confed
package to version 1.2.3+
Actions take place in the Configs section of the web-interface:
- On the Network Interfaces tab, add a new interface
can0
(see screenshot). Click the Save button. - Switch the
RS-485/CAN
port to CAN mode: on the Hardware Modules Configuration tab, select the settings RS485-2/CAN interface config, select in the Module type «CAN interface» and click the Save button.
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».
Стандартными средствами linux (автоматически)
Раздел Network Interfaces веб-интерфейса — это обёртка вокруг файла /etc/network/interfaces
, поэтому настройку CAN можно произвести с помощью службы управления сетями ОС debian. Для этого нужно:
- Добавить в
/etc/network/interfaces
запись вида:allow-hotplug can0 iface can0 can static bitrate 125000
- Переключить порт 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».