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

Материал из Wiren Board
(Новая страница: «CAN»)
 
(Новая страница: «For more information see the «AmadeuS» wiki article «[http://www.armadeus.com/wiki/index.php?title=CAN_bus_Linux_driver CAN bus Linux driver]».»)
Метки: правка с мобильного устройства правка из мобильной версии
 
(не показаны 22 промежуточные версии 3 участников)
Строка 1: Строка 1:
<languages/>
<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.  
Порты CAN доступны в системе как сетевые интерфейсы can0 или can1, в зависимости от модели контроллера.  


Работа происходит через стандартную подсистему Linux SocketCAN.
== Setting ==
[[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|Setting the RS485-2 port to CAN mode and enabling the can driver in linux]]


Для удобной работы с CAN, нужно поставить пакет apt-get install can-utils
==== 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+


Переключите порт RS-485/CAN в режим CAN: На вкладке Hardware Modules Configuration выберите настройки RS485-2/CAN interface config, выберите Module type '''CAN interface''' и нажмите кнопку Save.
Actions take place in the '''Configs''' section of the web-interface:
[[Special:MyLanguage/Файл:Can_enable.png|400px|right||Module type '''CAN 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.


Конфигурирование интерфейса
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».


<pre>
==== Using standard linux tools (automatically) ====
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:
# Add to <code>/etc/network/interfaces</code> an entry like this:
#:<syntaxhighlight lang="bash">
allow-hotplug can0
iface can0 can static
bitrate 125000
</syntaxhighlight>
# Switch RS-485-2 port to CAN mode
We will get a result similar to setting through the web-interface.
 
==== Using standard linux tools (manually) ====
 
After switching the port to CAN mode, you need to do:
<syntaxhighlight lang="bash">
ip link set can0 up type can bitrate 125000
ip link set can0 up type can bitrate 125000
</pre>
</syntaxhighlight>


== Working with CAN ==


отправка 4 байтов c адресом 123:
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:
<syntaxhighlight lang="bash">
apt update && apt install can-utils
</syntaxhighlight>


<pre>
Command examples:
* Sending four bytes with address 123:
*:<syntaxhighlight lang="bash">
cansend can0 123#DEADBEEF
cansend can0 123#DEADBEEF
</pre>
</syntaxhighlight>
 
показывать входящие пакеты:


<pre>
* Show incoming packets:
*:<syntaxhighlight lang="bash">
candump can0
candump can0
</pre>
</syntaxhighlight>
 
показать статистику:


<pre>
* Show statistics:
*:<syntaxhighlight lang="bash">
cat /proc/net/can/stats
cat /proc/net/can/stats
</pre>
</syntaxhighlight>




Обратите внимание, что в случае проблем на шине (нет терминатора, нет принимающего устройства, короткое замыкание), контроллер может прекратить работу.
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">
<pre>
ifconfig can0 down && ip link set can0 up type can bitrate 125000
ifconfig can0 down && ip link set can0 up type can bitrate 125000
</pre>
</syntaxhighlight>
 


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

Текущая версия на 23:01, 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

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:

  1. On the Network Interfaces tab, add a new interface can0 (see screenshot). Click the Save button.
  2. 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».

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.

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».