我在 Linkit MK7688 上使用 PyModbus,它使用 MAX485 连接到 Arduino UNO。以下是我写入线圈的代码。
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
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 = ModbusClient(method='rtu', port='/dev/ttyS1', timeout=2000, baudrate=9600)
client.debug=True
print(client)
response = client.write_coil(1, True, unit=1)
我正在尝试在 Modbus 上没有任何连接的情况下进行此操作。在此设置中,我关闭了 Arduino,并且不希望写入请求得到响应。但是,在调试日志中,我看到事务已完成。这是错误的,因为我不应该收到任何.write_coil()
. 如果某处发生环回,我如何检测它?
感谢您的回复。
2018-06-26 03:56:53,331 MainThread DEBUG sync :405 Serial client intialising
2018-06-26 03:56:53,337 MainThread DEBUG sync :42 Initializing...
ModbusSerialClient(rtu baud[9600])
2018-06-26 03:56:53,344 MainThread DEBUG transaction :107 Current transaction state - IDLE
2018-06-26 03:56:53,347 MainThread DEBUG transaction :111 Running transaction 1
2018-06-26 03:56:53,350 MainThread DEBUG transaction :201 SEND: 0x1 0x5 0x0 0x1 0xff 0x0 0xdd 0xfa
2018-06-26 03:56:53,352 MainThread DEBUG sync :77 New Transaction state 'SENDING'
2018-06-26 03:56:53,358 MainThread DEBUG transaction :204 Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2018-06-26 03:56:53,371 MainThread DEBUG sync :554 Finished reading socket....
2018-06-26 03:56:53,374 MainThread DEBUG sync :554 Finished reading socket....
2018-06-26 03:56:53,376 MainThread DEBUG transaction :279 Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2018-06-26 03:56:53,379 MainThread DEBUG transaction :209 RECV: 0x1 0x5 0x0 0x1 0xff 0x0 0xdd 0xfa
2018-06-26 03:56:53,382 MainThread DEBUG rtu_framer :175 Getting Frame - 0x5 0x0 0x1 0xff 0x0
2018-06-26 03:56:53,385 MainThread DEBUG factory :246 Factory Response[WriteSingleCoilResponse: 5]
2018-06-26 03:56:53,388 MainThread DEBUG rtu_framer :110 Frame advanced, resetting header!!
2018-06-26 03:56:53,390 MainThread DEBUG transaction :410 Adding transaction 1
2018-06-26 03:56:53,393 MainThread DEBUG transaction :420 Getting transaction 1
2018-06-26 03:56:53,397 MainThread DEBUG transaction :175 Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'