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

Материал из Wiren Board
(Новая страница: «For more information see the «AmadeuS» wiki article «[http://www.armadeus.com/wiki/index.php?title=CAN_bus_Linux_driver CAN bus Linux driver]».»)
Метки: правка с мобильного устройства правка из мобильной версии
(не показано 8 промежуточных версий этого же участника)
Строка 5: Строка 5:
[[Image:Can enable.png|300px|thumb|right|Setting the RS485-2 port to CAN mode and enabling the can driver in linux]]
[[Image:Can enable.png|300px|thumb|right|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 <code>wb-mqtt-confed</code> package to version 1.2.3+
Для настройки через веб-интерфейс нужно обновить пакет <code>wb-mqtt-confed</code> до версии 1.2.3+


Actions take place in the '''Configs''' section of the web-interface:
Действия происходят в разделе '''Configs''' веб-интерфейса:
# On the '''Network Interfaces''' tab, add a new interface <code>can0</code> (see screenshot). Click the '''Save''' button.
# На вкладке '''Network Interfaces''' добавьте новый интерфейс <code>can0</code> (см. скриншот). Нажмите кнопку '''Save'''.
# 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.
# Переключите порт <code>RS-485/CAN</code> в режим CAN: на вкладке '''Hardware Modules Configuration''' выберите настройки '''RS485-2/CAN interface config''', выберите в поле '''Module type''' «CAN interface» и нажмите кнопку '''Save'''.


The CAN interface will rise by itself when:
CAN-интерфейс будет подниматься сам при:
* system boot - service <code>wb-hwconf-manager</code> is responsible for this,
* загрузке системы — за это отвечает сервис <code>wb-hwconf-manager</code>,
* change the RS-485/2 port mode to «CAN».
* смене режима порта RS-485/2 в «CAN».


==== Using standard linux tools (automatically) ====
==== Стандартными средствами linux (автоматически) ====
The '''Network Interfaces''' section of the web interface is a wrapper around the <code>/etc/network/interfaces</code> file, so CAN configuration can be done using the debian network management service. For this you need:
Раздел '''Network Interfaces''' веб-интерфейса — это обёртка вокруг файла <code>/etc/network/interfaces</code>, поэтому настройку CAN можно произвести с помощью службы управления сетями ОС debian. Для этого нужно:
# Add to <code>/etc/network/interfaces</code> an entry like this:
# Добавить в <code>/etc/network/interfaces</code> запись вида:
#:<syntaxhighlight lang="bash">
#:<syntaxhighlight lang="bash">
allow-hotplug can0
allow-hotplug can0
Строка 24: Строка 24:
bitrate 125000
bitrate 125000
</syntaxhighlight>
</syntaxhighlight>
# Switch RS-485-2 port to CAN mode
# Переключить порт RS-485-2 в режим CAN
We will get a result similar to setting through the web-interface.
Получим результат, аналогичный настройке через веб-интерфейс.


==== Using standard linux tools (manually) ====
==== Стандартными средствами linux (вручную) ====


After switching the port to CAN mode, you need to do:
После переключения порта в режим CAN, нужно выполнить:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
ip link set can0 up type can bitrate 125000
ip link set can0 up type can bitrate 125000
</syntaxhighlight>
</syntaxhighlight>


== Working with CAN ==
== Работа с CAN ==


The <code>cansend</code> and <code>candump</code> utilities are included in the controller's standard software package. If for some reason they are not there, you can install the <code>can-utils</code> package:
Утилиты <code>cansend</code> и <code>candump</code> есть в стандартном наборе ПО контроллера. Если по каким-то причинам их нет, можно поставить пакет <code>can-utils</code>:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
apt update && apt install can-utils
apt update && apt install can-utils
</syntaxhighlight>
</syntaxhighlight>


Command examples:
Примеры команд:
* Sending four bytes with address 123:
* Отправка четырех байт c адресом 123:
*:<syntaxhighlight lang="bash">
*:<syntaxhighlight lang="bash">
cansend can0 123#DEADBEEF
cansend can0 123#DEADBEEF
</syntaxhighlight>
</syntaxhighlight>


* Show incoming packets:
* Показывать входящие пакеты:
*:<syntaxhighlight lang="bash">
*:<syntaxhighlight lang="bash">
candump can0
candump can0
</syntaxhighlight>
</syntaxhighlight>


* Show statistics:
* Показать статистику:
*:<syntaxhighlight lang="bash">
*:<syntaxhighlight lang="bash">
cat /proc/net/can/stats
cat /proc/net/can/stats
Строка 58: Строка 58:




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:
Для того чтобы начать работу вновь, выполните:  
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
ifconfig can0 down && ip link set can0 up type can bitrate 125000
ifconfig can0 down && ip link set can0 up type can bitrate 125000
</syntaxhighlight>
</syntaxhighlight>


For more information see the «AmadeuS» wiki article «[http://www.armadeus.com/wiki/index.php?title=CAN_bus_Linux_driver CAN bus Linux driver]».
Больше информации смотрите в вики проекта «AmadeuS», статья «[http://www.armadeus.com/wiki/index.php?title=CAN_bus_Linux_driver CAN bus Linux driver]».

Версия 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».