modbus - 使用 Python / ModBUS 从 Carlo Gavazzi EM24-DIN.AV5 读取寄存器时出现问题
问题描述
亲爱的,
我有一个 Carlo Gavazzi 能量计 EM24-DIN.AV5,我正在使用 USB/RS485 转换器 (zk-u485) 将它与 Raspberry PI 连接。USB-RS485 的 A/B/GND 端口与设备的 41/42/43 端口相连。
该设备有一个操纵杆来配置串行波特率和 ModBus 地址(在我的情况下它们是 9600 和 3)。
我使用这个代码示例来读取一些寄存器,但总是收到Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received) D
#!/usr/bin/env python
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', timeout=3, stopbits = 1, bytesize = 8, parity='N', baudrate= 9600)
val = client.connect()
if not val:
print("******** Connection error *************")
while True:
# rr = client.read_input_registers(address=37, count=2, unit=3);
rr = client.read_input_registers(2,2,unit=3)
print( rr);
按照完整的调试日志:
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x3 0x4 0x0 0x2 0x0 0x2 0xd1 0xe9
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received))
DEBUG:pymodbus.framer.rtu_framer:Frame - [] not ready
DEBUG:pymodbus.transaction:Getting transaction 3
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Modbus Error: [Input/Output] Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received)
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.transaction:Running transaction 2
DEBUG:pymodbus.transaction:SEND: 0x3 0x4 0x0 0x2 0x0 0x2 0xd1 0xe9
DEBUG:pymodbus.framer.rtu_framer:Changing state to IDLE - Last Frame End - None, Current Time stamp - 1596433492.94
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Incomplete message received, Expected 9 bytes Recieved 0 bytes !!!!
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV:
DEBUG:pymodbus.framer.rtu_framer:Frame - [] not ready
DEBUG:pymodbus.transaction:Getting transaction 3
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.transaction:Running transaction 3
DEBUG:pymodbus.transaction:SEND: 0x3 0x4 0x0 0x2 0x0 0x2 0xd1 0xe9
DEBUG:pymodbus.framer.rtu_framer:Changing state to IDLE - Last Frame End - 1596433495.95, Current Time stamp - 1596433495.95
DEBUG:pymodbus.framer.rtu_framer:Waiting for 3.5 char before next send - 4.01 ms
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
遵循 ModBus 协议文档: https : //www.ccontrols.com/support/dp/CarloGavazziEM24.pdf ModBus 地址
非常感激你的帮助。
解决方案
推荐阅读
- python - 在多线程 C++ 程序中嵌入 Python/C API
- java - 将强拆分为单独的字段 - Velocity 代码 Marketo Java
- python - Python串口数据读取
- angular - 24小时格式HH输入的ngx-timepicker-field问题
- c# - 无法在主机 PC 上构建的客户端 PC 上运行 dotnet .exe
- typescript - 如何在 Typescript 中键入检查扩展运算符?
- botframework - 原因:无法获取本地颁发者证书
- c# - ASP.NET MVC5 中的 AllowAnonymous 属性
- android-studio - 如何在 Android WebView 中动态加载默认 HTML5 视频缩略图?
- python - 您能否分享一些关于在使用多处理时处理列表的见解?(给出一个场景)