Прошу прощения, не все успел описать, пришлось уехать. Хочу получить данные по modbus. Уже немного переписал код, но ошибка осталась.
from pymodbus.client.sync import ModbusSerialClient
from pymodbus.exceptions import ModbusIOException
unit = 1
client = ModbusSerialClient(method='rtu', port='COM3', parity='N', baudrate=9600, bytesize=8, stopbits=1, timeout=1, strict=False)
reply = client.write_register(5, 2002, unit=unit)
if isinstance(reply, ModbusIOException):
print(reply)
while True:
values = client.read_holding_registers(address=59, count=1, unit=unit)
# or client.read_holding_registers(...)
if isinstance(values, ModbusIOException):
print(values)
else:
# here if values is not an ModbusIOException
print("Values:", values)
if values[0] == 0xFFFF:
print("Error detected")
elif values[0] == 2002:
print("Data ready")
result = client.read_holding_registers(address=50, count=9, unit=unit)
if isinstance(result, ModbusIOException):
print("Could not read result")
print("Maybe client.read_holding_registers?")
else:
print("Got a result:", result)
Получаю ошибку:
Values: ReadHoldingRegistersResponse (1)
Traceback (most recent call last):
File "winox1.py", line 18, in <module>
if values[0] == 0xFFFF:
TypeError: 'ReadHoldingRegistersResponse' object is not subscriptable