我在使用minimalmodbus库时遇到问题。从设备没有响应主设备的请求,我想请求读取。我使用的是Raspberry Pi 3 Model B+,带有Python 3.10.1,它是2.0版本的minimalmodbus库。我使用Arduino Mega作为从属设备,我也使用迷你适配器串行转换器USB到RS485是Arduino的转换器模块RS485。
import serial
import minimalmodbus
instrument = minimalmodbus.Instrument('COM6',1)
instrument.serial.baudrate = 9600
instrument.serial.timeout = 10
instrument.clear_buffers_before_each_transaction = True
instrument.debug = True
temperature = instrument.read_register(1,1)
print(temperature)
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 01 03 00 01 00 01 D5 CA (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port COM6
MinimalModbus debug mode. No sleep required before write. Time since previous read: 87898406.00 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: (0 bytes), roundtrip time:10.0 ms. Timeout for reading: 0 ms.
我在Win10 python 3.7.9上遇到了类似的问题。当我写时
import minimalmodbus
instrument = minimalmodbus.Instrument('COM3', 2)
instrument.serial.baudrate = 9600
instrument.clear_buffers_before_each_transaction = True
reg_0 = instrument.read_register(0, 0)
reg_1 = instrument.read_register(1, 0)
print(reg_0)
print(reg_1)
instrument.serial.close()
我有错误消息";minimalmodbus。无响应错误:与仪器无通信(无应答(";。但是,当我写时
import minimalmodbus
instrument = minimalmodbus.Instrument('COM3', 2)
instrument.serial.baudrate = 9600
instrument.clear_buffers_before_each_transaction = True
instrument.debug = True
reg_0 = instrument.read_register(0, 0)
reg_1 = instrument.read_register(1, 0)
print(reg_0)
print(reg_1)
instrument.serial.close()
一切正常。我把阿杜伊诺·乌诺当作奴隶。在ModbusPoll中,两个寄存器读取正确的
Upd。当我使用结构";尝试除了"所有工作正常
import minimalmodbus
instrument = minimalmodbus.Instrument('COM3', 2)
instrument.serial.baudrate = 9600
instrument.clear_buffers_before_each_transaction = True
try:
reg_0 = instrument.read_register(0, 0)
except minimalmodbus.NoResponseError:
reg_0 = instrument.read_register(0, 0)
reg_1 = instrument.read_register(1, 0)
print(reg_0)
print(reg_1)
instrument.serial.close()