Сдвиг фрейма Modbus при чтении ответа от устройства


#1

Попробовал прицепить к контроллеру по RS485 имеющийся у меня китайский термометр-гигрометр. Возникает следующая ситуация: при чтении ответа от датчика перед фреймом возникает лишний нулевой байт из-за чего весь фрейм сдвигается, последний байт фрейма выбрасывается и не совпадает CRC

root@wirenboard-AAKTIXM7:~# wb-mqtt-serial -c /etc/wb-mqtt-serial.conf -d
address: 0
address: 1
Setting up devices at </dev/ttyRS485-1 9600 8 N1 timeout 500>
CreateDevice: temp-humidity-sensor_5 (Temperature and humidity sensor) @ 5 -- protocol: modbus
AddRegister: 0x7f81dae0
AddRegister: 0x7f81ddd0
Adding range: 2 holding(s) @ 0 of device modbus:5
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02Connected with code 0
c5 8f
ReadFrame:  00 05 03 04 00 F6 00 79 9E
read noise: 23
read noise: 00
ModbusRTU::ReadRegisterRange(): failed to read 2 holding(s) @ 0 of device modbus:5: Serial protocol error: invalid crc

В чем может быть проблема? Этот же самый датчик у меня без проблем читается в NodeRED на компьютере через USB адаптер RS485.

Шаблон:

{
"device_ttype": "Temperature and humidity sensor",
"device": {
"name": "Temperature and numidity sensor",
"id": "temp-humidity-sensor",
"max_read_registers": 2,
    "channels": [
        {
            "name": "Temperature",
            "reg_type": "holding",
            "address": 0,
            "type": "value",
            "format": "s16",
            "scale": 0.1
        },
        {
            "name": "Humidity",
            "reg_type": "holding",
            "address": 1,
            "type": "value",
            "format": "s16",
            "scale": 0.1
        }
    ]
}
}

#2
  1. Покажите содержимое /etc/wb-mqtt-serial.conf целиком пожалуйста

  2. Покажите версию wb-mqtt-serial, например вывод команды

    dpkg -s wb-mqtt-serial

Вообще, кажется проблема здесь:

Судя по логам, нулевой байт есть и до пакета с ответом, и после. Это похоже на то, что датчик неправильно управляет приёмопередатчиком RS-485: включает и выключает его невовремя.


#3

{
“debug”: true,
“ports”: [
{
“path”: “/dev/ttyRS485-1”,
“devices”: [
{
“slave_id”: “5”,
“device_type”: “Temperature and humidity sensor”,
“device_timeout_ms”: 10000
}
],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 1,
“poll_interval”: 3000,
“enabled”: true
},
{
“path”: “/dev/ttyMOD1”,
“devices”: [
{
“slave_id”: 5,
“device_type”: “Temperature and humidity sensor”
}
],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: false
},
{
“path”: “/dev/ttyMOD2”,
“devices”: [],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: false
},
{
“path”: “/dev/ttyMOD3”,
“devices”: [],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: false
}
]
}

root@wirenboard-AAKTIXM7:~# dpkg -s wb-mqtt-serial
Package: wb-mqtt-serial
Status: install ok installed
Priority: optional
Section: misc
Installed-Size: 1013
Maintainer: Evgeny Boger boger@contactless.ru
Architecture: armhf
Version: 1.44
Replaces: wb-homa-modbus (<< 1.14.1)
Depends: libc6 (>= 2.4), libgcc1 (>= 1:3.5), libjsoncpp1 (>= 1.7.4), libmosquitto1 (>= 1.0), libmosquittopp1 (>= 1.0), libstdc++6 (>= 6), libwbmqtt0 (>= 1.7), bsdutils
Breaks: wb-homa-modbus (<< 1.14.1), wb-mqtt-confed (<< 1.0.2), wb-mqtt-homeui (<< 1.7)
Conffiles:
/etc/init.d/wb-mqtt-serial 1cfd1f4e29c3502bc6eac8ccbd9986ec
/etc/wb-configs.d/11wb-mqtt-serial 5325e375bc486e31384ed908b8ceae0e
/etc/wb-mqtt-serial.conf.sample c8c1adbf630e6fd7ec871b1b5c4a5e0f
Description: Wiren Board Smart Home MQTT serial protocol driver.


#4

device_ttype это специально или опечатка?


#5

В конфигах всё нормально, версия свежая. Остаётся только смотреть осциллографом (в крайнем случае лог. анализатором) на шину и смотреть, всё ли датчик делает правильно.

Если неправильно, то поставим в очередь добавление в наш драйвер очередного костыля для устройств, нарушающих стандарт.


#6

Боюсь, что проблема может быть не в китайском железе, а в российском. Проверил этот же датчик на WirenBoard 5 - всё прекрасно работает

root@wirenboard-A5Q6XVOE:~# wb-mqtt-serial -c /etc/wb-mqtt-serial.conf -d
address: 0
address: 1
Setting up devices at </dev/ttyAPP1 9600 8 N1 timeout 500>
CreateDevice: temp-humidity-sensor_0x05 (Temperature and humidity sensor) @ 0x05 – protocol: modbus
AddRegister: 0x7ff9b820
AddRegister: 0x7ff9bb58
Warning: no devices defined for port </dev/ttyAPP4 9600 8 N2 timeout 500> . Skipping.
Adding range: 2 holding(s) @ 0 of device modbus:5
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 Connected with code 0
02 c5 8f
ReadFrame: 05 03 04 00 F4 00 7F BF E1
new val for Subscription succeeded.
<modbus:5:holding: 0>: f4
register value change: <modbus:5:holding: 0> <- 24.4
channel Temperature device id: temp-humidity-sensor_0x05 – topic: /devices/temp-humidity-sensor_0x05/controls/Temperature <-- 24.4
new val for <modbus:5:holding: 1>: 7f
register value change: Subscription succeeded.
<modbus:5:holding: 1> <- 12.7
channel Humidity device id: temp-humidity-sensor_0x05 – topic: /devices/temp-humidity-sensor_0x05/controls/Humidity <-- 12.7
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F4 00 7F BF E1
235386: Wait until 235434
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F4 00 7F BF E1
235476: Wait until 235535
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F4 00 7F BF E1
235565: Wait until 235635
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F4 00 7F BF E1
235665: Wait until 235735
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F3 00 7F 0E 20
new val for <modbus:5:holding: 0>: f3
register value change: <modbus:5:holding: 0> <- 24.3
channel Temperature device id: temp-humidity-sensor_0x05 – topic: /devices/temp-humidity-sensor_0x05/controls/Temperature <-- 24.3
235781: Wait until 235835
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F3 00 7F 0E 20
235866: Wait until 235936
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F3 00 7F 0E 20
235966: Wait until 236036
modbus: read 2 holding(s) @ 0 of device modbus:5
Write: 05 03 00 00 00 02 c5 8f
ReadFrame: 05 03 04 00 F3 00 7F 0E 20

Прошивку на wb5 обновил до последней 201810040755_emmc_wb58_stretch.img.zip

Версия wb-mqtt-serial та же
root@wirenboard-A5Q6XVOE:~# dpkg -s wb-mqtt-serial
Package: wb-mqtt-serial
Status: install ok installed
Priority: optional
Section: misc
Installed-Size: 1097
Maintainer: Evgeny Boger boger@contactless.ru
Architecture: armel
Version: 1.44
Replaces: wb-homa-modbus (<< 1.14.1)
Depends: libc6 (>= 2.4), libgcc1 (>= 1:3.5), libjsoncpp1 (>= 1.7.4), libmosquitto1 (>= 1.0), libmosquittopp1 (>= 1.0), libstdc++6 (>= 6), libwbmqtt0 (>= 1.7), bsdutils
Breaks: wb-homa-modbus (<< 1.14.1), wb-mqtt-confed (<< 1.0.2), wb-mqtt-homeui (<< 1.7)
Conffiles:
/etc/init.d/wb-mqtt-serial 1cfd1f4e29c3502bc6eac8ccbd9986ec
/etc/wb-configs.d/11wb-mqtt-serial 5325e375bc486e31384ed908b8ceae0e
/etc/wb-mqtt-serial.conf.sample c8c1adbf630e6fd7ec871b1b5c4a5e0f
Description: Wiren Board Smart Home MQTT serial protocol driver.

root@wirenboard-A5Q6XVOE:~# cat /etc/wb-mqtt-serial.conf
{
“debug”: false,
“ports”: [
{
“path”: “/dev/ttyAPP1”,
“devices”: [
{
“slave_id”: “0x05”,
“device_type”: “Temperature and humidity sensor”,
“enabled”: true
}
],
“port_type”: “serial”,
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 1,
“poll_interval”: 100,
“enabled”: true
},
{
“path”: “/dev/ttyAPP4”,
“devices”: [],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: true
},
{
“path”: “/dev/ttyAPP2”,
“devices”: [],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: false
},
{
“path”: “/dev/ttyAPP3”,
“devices”: [],
“baud_rate”: 9600,
“parity”: “N”,
“data_bits”: 8,
“stop_bits”: 2,
“poll_interval”: 10,
“enabled”: false
}
]
}

device_ttype - опечатка.


#7

Вполне может быть и в российском, конечно.

В любом случае, разобраться в чём дело без осциллографа будет весьма тяжело.

Проверьте пожалуйста две вещи ещё:

  1. У вас замкнута перемычка терминатора RS-485 на этом порту? Они находятся рядом с разъёмами антенн

  2. Проверьте пожалуйста, что в настройках у вас включен failsafe bias на этом порту. Это в Configs => Hardware modules => RS485-1


#8

Перемычка на месте
failsafe bias включен

К слову и другие модули, которые нормально работают с WB5, тут работают странно сыплется большое кол-во таймаутов.


#9

А другие модули вы подключаете по одному к контроллеру, или всю шину RS-485? А этот китайский модуль?


#10

Подключаю по одному.
Модули у меня все китайские с aliexpress

Вот попробовал сегодня релейный модуль. Та же история:

address: 0
address: 1
address: 2
address: 3
address: 4
address: 5
address: 6
address: 7
address: 8
address: 9
address: 10
address: 11
address: 12
address: 13
address: 14
address: 15
Setting up devices at </dev/ttyRS485-1 9600 8 N1 timeout 500>
CreateDevice: pk9066_1 (PK9066 Relay Output Module) @ 1 – protocol: modbus
AddRegister: 0x80ec1180
AddRegister: 0x80ec13f8
AddRegister: 0x80ec16c0
AddRegister: 0x80ec1928
AddRegister: 0x80ec1bb0
AddRegister: 0x80ec1eb0
AddRegister: 0x80ec2120
AddRegister: 0x80ec23a8
AddRegister: 0x80ec2630
AddRegister: 0x80ec28b8
AddRegister: 0x80e89850
AddRegister: 0x80e89c58
AddRegister: 0x80e89e80
AddRegister: 0x80e8a0a8
AddRegister: 0x80e8a330
AddRegister: 0x80e8a5b8
read noise: 00
Adding range: 16 coil(s) @ 0 of device modbus:1
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
Connected with code 0
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540415: Wait until 540477
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
Subscription succeeded.
Subscription succeeded.
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540509: Wait until 540577
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540608: Wait until 540677
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540711: Wait until 540777
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540817: Wait until 540877
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc
ModbusRTU::ReadRegisterRange(): failed to read 16 coil(s) @ 0 of device modbus:1: Serial protocol error: invalid crc
540912: Wait until 540978
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 00 01 01 02 00 00 B9
read noise: fc

Потом подключил к WB6 конвертор USB<->RS485 на 4 порта и через него тот же модуль. Все работает:

address: 0
address: 1
address: 2
address: 3
address: 4
address: 5
address: 6
address: 7
address: 8
address: 9
address: 10
address: 11
address: 12
address: 13
address: 14
address: 15
Setting up devices at </dev/ttyUSB0 9600 8 N1 timeout 500>
CreateDevice: pk9066_1 (PK9066 Relay Output Module) @ 1 – protocol: modbus
AddRegister: 0x810f5170
AddRegister: 0x810f53e8
AddRegister: 0x810f56b0
AddRegister: 0x810f5918
AddRegister: 0x810f5ba0
AddRegister: 0x810f5ea0
AddRegister: 0x810f6110
AddRegister: 0x810f6398
AddRegister: 0x810f6620
AddRegister: 0x810f68a8
AddRegister: 0x8124d5f0
AddRegister: 0x8124d9f8
AddRegister: 0x8124dc20
AddRegister: 0x8124de48
AddRegister: 0x8124e0d0
AddRegister: 0x8124e358
Adding range: 16 coil(s) @ 0 of device modbus:1
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6Connected with code 0

ReadFrame: 01 01 02 00 00 B9 FC
register value change: <modbus:1:coil: 0> <- 0
channel RL0 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL0 <-- 0
register value change: <modbus:1:coil: 1> <- 0
Subscription succeeded.
channel RL1 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL1 <-- 0
register value change: <modbus:1:coil: 2> <- 0
channel RL2 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL2 <-- 0
register value change: <modbus:1:coil: 3> <- 0
channel RL3 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL3 <-- 0
register value change: <modbus:1:coil: 4> <- 0
channel RL4Subscription succeeded.
device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL4 <-- 0
register value change: <modbus:1:coil: 5> <- 0
channel RL5 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL5 <-- 0
Subscription succeeded.
register value change: <modbus:1:coil: 6> <- 0
channel RL6 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL6Subscription succeeded.
<-- 0
register value change: <modbus:1:coil: 7> <- 0
channel RL7 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL7 <-- 0
register value change: Subscription succeeded.
<modbus:1:coil: 8> <- 0
channel RL8 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL8 <-- 0
Subscription succeeded.
register value change: <modbus:1:coil: 9> <- 0
channel RL9 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL9 <-- 0
Subscription succeeded.
register value change: <modbus:1:coil: 10> <- 0
channel RL10 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL10 <-- 0
register value change: Subscription succeeded.
<modbus:1:coil: 11> <- 0
channel RL11 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL11 <-- 0
register value change: <modbus:1:coil: 12> <- 0
channel RL12 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL12 <-- 0
register value change: <modbus:1:coil: 13> <- 0
channel RL13 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL13 <-- 0
Subscription succeeded.
register value change: <modbus:1:coil: 14> <- 0
channel RL14 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL14 <-- 0
Subscription succeeded.
register value change: <modbus:1:coil: 15> <- 0
channel RL15 device id: pk9066_1 – topic: /devices/pk9066_1/controls/RL15 <-- 0
Subscription succeeded.
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
Subscription succeeded.
ReadFrame: 01 01 02 00 00 B9 FC
3703044: Wait until 3703116
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
Subscription succeeded.
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703140: Wait until 3703216
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703252: Wait until 3703316
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703348: Wait until 3703416
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703447: Wait until 3703517
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703543: Wait until 3703617
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703652: Wait until 3703717
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703757: Wait until 3703817
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703844: Wait until 3703918
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3703964: Wait until 3704018
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704052: Wait until 3704118
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704148: Wait until 3704218
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704244: Wait until 3704318
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704340: Wait until 3704418
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704454: Wait until 3704519
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704549: Wait until 3704619
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704645: Wait until 3704719
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704757: Wait until 3704819
modbus: read 16 coil(s) @ 0 of device modbus:1
Write: 01 01 00 00 00 10 3d c6
ReadFrame: 01 01 02 00 00 B9 FC
3704852: Wait until 3704919

Датчик температуры то же работает если подключать через конвертор.
Вот такой модуль и конвертор:

Так же пробовал подключать через шлюз USR-M511 по Modbus over TCP. То же все работает. Может мне просто попался бракованый WB6?


#11

Вряд ли: в контроллере же два независимых порта, и если они оба не работают, то значит проблема интереснее.

В общем вариантов кроме осциллографа не осталось. Могу предложить только отправить к нам какой-нибудь китайский датчик, на котором с WB6 эта проблема гарантировано воспроизводится. Мы подключим и посмотрим осциллографом.