【发布时间】:2021-12-30 10:33:58
【问题描述】:
我正在尝试与具有 RS485 modbus 接口的电表 (Orno WE-517) 通信。此串行接口连接到 Elfin EW11 modbus 到 Wifi 转换器。
使用 pymodbus,我可以连接到适配器,但我无法从仪表中读取任何内容。 这是我的代码:
from pymodbus.client.sync import ModbusTcpClient
from pprint import pprint
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s '
'%(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusTcpClient('192.168.0.18', 502)
if not client.connect():
print('Error connecting')
exit()
print('holding register')
result = client.read_holding_registers(28,1)
response = client.execute(result)
pprint(vars(response))
client.close()
这是脚本的输出:
python3 modBus.py
2021-12-30 10:46:44,112 MainThread DEBUG sync :216 Connection to Modbus server established. Socket ('192.168.0.10', 47763)
holding register
2021-12-30 10:46:44,113 MainThread DEBUG transaction :140 Current transaction state - IDLE
2021-12-30 10:46:44,114 MainThread DEBUG transaction :145 Running transaction 1
2021-12-30 10:46:44,114 MainThread DEBUG transaction :273 SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0x0 0x1c 0x0 0x1
2021-12-30 10:46:44,115 MainThread DEBUG sync :76 New Transaction state 'SENDING'
2021-12-30 10:46:44,115 MainThread DEBUG transaction :287 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2021-12-30 10:46:44,216 MainThread DEBUG transaction :375 Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2021-12-30 10:46:44,217 MainThread DEBUG transaction :297 RECV: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x3e 0xf0
2021-12-30 10:46:44,218 MainThread DEBUG socket_framer :147 Processing: 0x0 0x1 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x3e 0xf0
2021-12-30 10:46:44,218 MainThread DEBUG factory :266 Factory Response[ReadHoldingRegistersResponse: 3]
2021-12-30 10:46:44,219 MainThread DEBUG transaction :454 Adding transaction 1
2021-12-30 10:46:44,220 MainThread DEBUG transaction :465 Getting transaction 1
2021-12-30 10:46:44,220 MainThread DEBUG transaction :224 Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
2021-12-30 10:46:44,221 MainThread DEBUG transaction :140 Current transaction state - TRANSACTION_COMPLETE
2021-12-30 10:46:44,221 MainThread DEBUG transaction :145 Running transaction 2
2021-12-30 10:46:44,222 MainThread DEBUG transaction :273 SEND: 0x0 0x2 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x3e 0xf0
2021-12-30 10:46:44,222 MainThread DEBUG sync :76 New Transaction state 'SENDING'
2021-12-30 10:46:44,223 MainThread DEBUG transaction :287 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2021-12-30 10:46:47,227 MainThread DEBUG transaction :303 Transaction failed. (Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received))
2021-12-30 10:46:47,228 MainThread DEBUG socket_framer :147 Processing:
2021-12-30 10:46:47,228 MainThread DEBUG transaction :465 Getting transaction 2
2021-12-30 10:46:47,229 MainThread DEBUG transaction :224 Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
{'fcode': 3,
'message': '[Input/Output] Modbus Error: [Invalid Message] No response '
'received, expected at least 8 bytes (0 received)',
'string': '[Input/Output] Modbus Error: [Invalid Message] No response '
'received, expected at least 8 bytes (0 received)'}
如您所见,pymodbus 管理连接、发送请求和接收响应。 但我无法从该响应中找到做某事的方法。
有人有什么想法可以帮助我吗?
提前,非常感谢您的帮助:)
【问题讨论】:
标签: pymodbus