gpt4 book ai didi

python - pymodbus解码错误: [Input/Output] No response received from the remote unit/Unable to decode response

转载 作者:行者123 更新时间:2023-12-01 08:34:44 33 4
gpt4 key购买 nike

我在使用 pymodbus 的 Raspberry Pi 3B 上遇到解码错误。设计了一个使用 MAX14854G 作为 RS-485 收发器的电路板,该收发器连接到 RPI3 的 UART 引脚 (8 和 10)。目前正在使用 RS-485 电缆和 modbus 模拟器对其进行测试(Modbus 模拟器 --> RS485 电缆 --> RS-485 HAT 板 UART --> Raspberry Pi 3B)。

框图:

enter image description here

其他信息:我通过交换 ttyS0 和 ttyAMA0 以及禁用串行控制台和蓝牙来使用 UART (ttyAMA0) 的全部功能:

$ sudo systemctl disable serial-getty@ttyAMA0.service
$ sudo systemctl disable serial-getty@ttyS0.service
$ sudo systemctl disable serial-getty@serial0.service
$ sudo systemctl disable serial-getty@serial1.service

这是我的代码+错误+日志:

In [1]: import pymodbus
...: import serial
...: import serial.rs485
...: from pymodbus.pdu import ModbusRequest
...: from pymodbus.client.sync import ModbusSerialClient as ModbusClient
...: from pymodbus.transaction import ModbusRtuFramer
...: from pymodbus.register_read_message import ReadInputRegistersResponse
...:
...: import logging
...: logging.basicConfig()
...: log = logging.getLogger()
...: log.setLevel(logging.DEBUG)

In [2]: msys = ModbusClient(method='rtu',port='/dev/ttyAMA0',stopbits=1,bytesize=8,parity='O',baudrate=9600,timeout=2)

In [3]: msys.inter_char_timeout = 0.05

In [4]: HR2 = msys.read_holding_registers(0,1,unit=1)
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x1 0x3 0x0 0x0 0x0 0x1 0x84
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'

In [5]: HR2
Out[5]:
pymodbus.exceptions.ModbusIOException('No Response received from the remote unit/Unable to decode response',
3)

In [6]: print(HR2)
Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response

In [7]: print(HR2.registers)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-02134bc1ab17> in <module>()
----> 1 print(HR2.registers)

AttributeError: 'ModbusIOException' object has no attribute 'registers'

这是解码问题还是Raspberry Pi 3B的UART设置不正确?在禁用串行控制台之前,我什至无法连接到该设备。基于Modbus模拟器,有数据流量。

enter image description here

最佳答案

响应不正确。对于函数 3(读出单词),响应应类似于 [SlaveNb] [FnNb] [NbBytes] [Data] [CRC16].您的请求是正确的,您要求从地址 0 开始的 1 个单词

响应应为01 03 02 XX XX YY YY,其中02是数据字节数,XX XX是数据,YY YY 是 CRC16。您应该注意到,您的 NbBytes 字段响应为 0,但字数应加倍。

顺便说一句,您的响应看起来像是请求的回声。你没有接线错误吗?也许你循环了 rx&tx?

关于python - pymodbus解码错误: [Input/Output] No response received from the remote unit/Unable to decode response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53777992/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com