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

Материал из Wiren Board
(Новая страница: «RS-485 data exchange parameters registers In the factory configuration, all Wiren Board devices are supplied with the following RS-485 settings: 9600 bps, no pari…»)
 
(не показано 15 промежуточных версий этого же участника)
Строка 4: Строка 4:




== RS-485 data exchange parameters registers
== Registers of parameters of data exchange via RS-485 ==
==


RS-485 data exchange parameters registers
In the factory configuration, all Wiren Board devices are supplied with the following RS-485 settings: 9600 bps, no parity bit (none), stop bit count — 2. However, the firmware of almost all modern Wiren Board devices supports additional registers, which set parameters of data exchange via RS-485:
In the factory configuration, all Wiren Board devices are supplied with the following RS-485 settings: 9600 bps, no parity bit (none), stop bit count — 2. However, the firmware of almost all modern devices Wiren Board supports additional registers settings data exchange via RS-485:


{|  border="1" class="wikitable" style="text-align:center; width:1000px;"
{|  border="1" class="wikitable" style="text-align:center; width:1000px;"
!Регистр / адрес
!Register / address
!Тип
!Type
!Чтение/запись
!Read/write
!Значение по умолчанию
!Value by default
!Формат
!Format
!Назначение
!Function
|-
|-
| 110 || holding || RW || 96 ||  baud rate / 100 || скорость порта RS-485, '''делённая на 100'''. Допустимые скорости: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200  
| 110 || holding || RW || 96 ||  baud rate / 100 || RS-485 port speed, '''divided by 100'''. Permissible speeds: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200  
|-
|-
| 111 || holding || RW || 0 || || настройка бита чётности порта RS-485. Допустимые значения: 0 - нет бита чётности (none), 1 - нечётный (odd), 2 - чётный (even)
| 111 || holding || RW || 0 || || set the parity bit of the RS-485 port. Valid values: 0 - no parity bit (none), 1 - odd , 2 - even  
|-
|-
| 112 || holding || RW || 2 || || количество стоп-битов порта RS-485. Допустимые значения: 1, 2  
| 112 || holding || RW || 2 || || umber of stop bits of RS-485 port. Valid values: 1, 2
|-
|-
|}
|}




== Изменение параметров обмена данными ==
== Changing data exchange settings ==


Чтобы иметь возможность обратиться к устройству, поддерживающем протокол modbus RTU по шине RS-485, необходимо знать его modbus-адрес, а так же установленные на устройстве скорость обмена данными, четность, количество стоп-битов. '''Важно: Перед выполнением команд, описанных ниже, остановите сервис wb-mqtt-serial: <code>service wb-mqtt-serial stop</code>'''
To be able to access the device that supports the modbus RTU Protocol over the RS-485 bus, it is necessary to know its modbus address, as well as the data exchange rate, parity, the number of stop bits installed on the device. '''Important: Before executing the commands below, stop the wb-mqtt-serial:<code> service wb-mqtt-serial stop service</code>'''


Узнать текущие настройки параметров обмена данными, можно, прочитав значение указанных выше регистров, например:
You can find out the current settings of the data exchange parameters by reading the value of the above registers, for example:


     (echo -n '100 \* '; echo  -e `modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x03 -r110 | grep Data | sed -e 's/Data://' -e 's/s//g'` | xargs printf "%d") | xargs expr
     (echo -n '100 \* '; echo  -e `modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x03 -r110 | grep Data | sed -e 's/Data://' -e 's/s//g'` | xargs printf "%d") | xargs expr
Строка 37: Строка 35:
     9600
     9600


Подробнее смотрите описание команды [[Special:MyLanguage/Modbus-client|modbus_client]].
For details, see the description of the [[Modbus-client/en|modbus_client]] command. '''Important: the examples below use the /dev/ttyAPP1 port. If the device is connected to another port, you must replace /dev/ttyAPP1 with the name of that port!'''
'''Важно: в примерах ниже используется порт /dev/ttyAPP1. Если устройство подключено к другому порту, необходимо заменить /dev/ttyAPP1 на название этого порта!'''


Записать новое значение можно с помощью следующей команды:
You can write a new value by using the following command:


     modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x06 -r110 1152
     modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x06 -r110 1152


Теперь устройство передает и принимает данные на скорости 115200 бит/с.
The device now transmits and receives data at 115200 bps.


Записью в соответствующие регистры изменяется четность и количество стоп-битов.
Writing to the appropriate registers changes the parity and the number of stop bits.


При этом возникает парадоксальная ситуация: мы не можем узнать значение скорости, если мы заранее не укажем её значение при обращении к устройству! Поэтому стоит внимательно относиться к тому, какие коммуникационные параметры вы устанавливайте. Наклейте на устройство наклейку с новыми параметрами. В случае, если все коммуникационные параметры неизвестны, найти их можно только перебором:
In this case, a paradoxical situation arises: we can not know the value of the speed, if we do not specify its value in advance when referring to the device! Therefore, you should pay attention to what communication parameters you set. Stick a sticker with the new settings on the device. If all communication parameters are unknown, you can find them only by searching:


     #/bin/bash
     #/bin/bash
Строка 64: Строка 61:
     done
     done


В этом [[Special:MyLanguage/Media:Perebor.sh.tar.gz|скрипте]] мы обращаемся к регистру 0x80, в котором во всех modbus-устройствах Wiren Board хранится modbus-адрес. Вывод скрипта будет содержать строки, подобные этим:
In this [[Media:Perebor.sh.tar.gz|script]] we refer to the 0x80 register, which stores the modbus address in all Wiren Board Modbus devices. The output of the script will contain lines like these:
  Speed:9600      Stop bits:1    Parity:none    Modbus address:0x0001
  Speed:9600      Stop bits:1    Parity:none    Modbus address:0x0001
  Speed:9600      Stop bits:2    Parity:none    Modbus address:0x0001
  Speed:9600      Stop bits:2    Parity:none    Modbus address:0x0001


Для стоп-битов, скорее всего, вы получите два значения: 1 и 2. Уточнить настройку можно считав значение из регистра 112 с уже известным адресом, скоростью, четностью:
For stop bits, you will likely get two values: 1 and 2. You can refine the setting by reading the value from the register 112 with the already known address, speed, parity:


  modbus_client --debug -mrtu -b'''9600''' -p'''none''' -s'''2''' /dev/ttyAPP1 -a'''0x01''' -t0x03 -r112
  modbus_client --debug -mrtu -b'''9600''' -p'''none''' -s'''2''' /dev/ttyAPP1 -a'''0x01''' -t0x03 -r112


или
or


  modbus_client --debug -mrtu -b'''9600''' -p'''none''' -s'''1''' /dev/ttyAPP1 -a'''0x01''' -t0x03 -r112
  modbus_client --debug -mrtu -b'''9600''' -p'''none''' -s'''1''' /dev/ttyAPP1 -a'''0x01''' -t0x03 -r112
Строка 79: Строка 76:
     Data: 0x0002
     Data: 0x0002


Если при чтении из регистра 112 вы получаете ошибку, то устройство не поддерживает установку коммуникационных параметров. В этом случае для коммуникации используется значение по умолчанию,2 стоп-бита.
If you receive an error while reading from register 112, the device does not support setting communication parameters. In this case,the default value of 2 stop bits is used for communication.

Текущая версия на 17:27, 3 июня 2019

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

Внимание: Отображаемое название «Настройка параметров обмена данными по RS-485 для modbus-устройств Wiren Board» переопределяет ранее заданное отображаемое название «UART Communication Settings».


Registers of parameters of data exchange via RS-485

In the factory configuration, all Wiren Board devices are supplied with the following RS-485 settings: 9600 bps, no parity bit (none), stop bit count — 2. However, the firmware of almost all modern Wiren Board devices supports additional registers, which set parameters of data exchange via RS-485:

Register / address Type Read/write Value by default Format Function
110 holding RW 96 baud rate / 100 RS-485 port speed, divided by 100. Permissible speeds: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
111 holding RW 0 set the parity bit of the RS-485 port. Valid values: 0 - no parity bit (none), 1 - odd , 2 - even
112 holding RW 2 umber of stop bits of RS-485 port. Valid values: 1, 2


Changing data exchange settings

To be able to access the device that supports the modbus RTU Protocol over the RS-485 bus, it is necessary to know its modbus address, as well as the data exchange rate, parity, the number of stop bits installed on the device. Important: Before executing the commands below, stop the wb-mqtt-serial: service wb-mqtt-serial stop service

You can find out the current settings of the data exchange parameters by reading the value of the above registers, for example:

   (echo -n '100 \* '; echo  -e `modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x03 -r110 | grep Data | sed -e 's/Data://' -e 's/s//g'` | xargs printf "%d") | xargs expr
   9600

For details, see the description of the modbus_client command. Important: the examples below use the /dev/ttyAPP1 port. If the device is connected to another port, you must replace /dev/ttyAPP1 with the name of that port!

You can write a new value by using the following command:

   modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x06 -r110 1152

The device now transmits and receives data at 115200 bps.

Writing to the appropriate registers changes the parity and the number of stop bits.

In this case, a paradoxical situation arises: we can not know the value of the speed, if we do not specify its value in advance when referring to the device! Therefore, you should pay attention to what communication parameters you set. Stick a sticker with the new settings on the device. If all communication parameters are unknown, you can find them only by searching:

   #/bin/bash
   for l in {1,2};
   do
   for k in {none,odd,even};
   do
       for j in {1200,2400,4800,9600,19200,38400,57600,115200}; 
       do
           for i in {1..247}; do 
                       modbus_client -mrtu /dev/ttyAPP1 --debug -o 300 -a$i -t3 -r0x80 -b$j -s$l -p$k 
           done 2>/dev/null | grep Data: | sed -e 's/ //g' -e 's/\n//' | xargs -I {} printf "Speed:$j\tStop bits:$l\tParity:$k\tModbus address:{}" | grep Data: | sed -e 's/Data://'
       done
   done
   done

In this script we refer to the 0x80 register, which stores the modbus address in all Wiren Board Modbus devices. The output of the script will contain lines like these:

Speed:9600      Stop bits:1     Parity:none     Modbus address:0x0001
Speed:9600      Stop bits:2     Parity:none     Modbus address:0x0001

For stop bits, you will likely get two values: 1 and 2. You can refine the setting by reading the value from the register 112 with the already known address, speed, parity:

modbus_client --debug -mrtu -b9600 -pnone -s2 /dev/ttyAPP1 -a0x01 -t0x03 -r112

or

modbus_client --debug -mrtu -b9600 -pnone -s1 /dev/ttyAPP1 -a0x01 -t0x03 -r112
   SUCCESS: read 1 of elements:
   Data: 0x0002

If you receive an error while reading from register 112, the device does not support setting communication parameters. In this case,the default value of 2 stop bits is used for communication.