Reading register sometimes but mostly gives error. 'ModbusIOException' object has no attribute 'registers' .
There are similar issues posted before but those didnt helped me out in figuring out what causing this problem. Is it problem with my code or device
Versions
- Python: 3.7
- OS: Windows/Raspbian
- Pymodbus: 2.2
- Modbus Hardware (if used): Baykee Solar Inverter
Pymodbus Specific
- Server: tcp/rtu/ascii - sync/async
- Client: tcp/rtu/ascii - sync/async
Using RTU , rs485 to USB converter. No idea about sync or async
Description
I am trying to read data from registers in Modbus using pymodbus2.2 python. Everything works fine but problem i am facing is while reading registers i get error 7 out of 10 times average and 3 times read successfully. Thats makes almost 20,30sec difference between two readings which is not gonna help in real time monitoring I have a working piece of code. Baudrate parity is as provided by my inverter manufacturers.
Code and Logs
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.constants import Defaults
Defaults.RetryOnEmpty = True
Defaults.Timeout = 5
Defaults.Retries = 5
client = ModbusClient(method='rtu', port='COM4', timeout=2, stopbits = 1,
bytesize = 8, parity='N', baudrate= 2400)
if(client.connect()):
print('Connected to Device Successfully')
else:
print('Connection failed')
while True:
try:
print ('Requesting Data From Registers..')
hh = client.read_holding_registers(address=211, count=11, unit=1);
#print (hh.registers)
markAmount1 = int(h15.registers[3]/10)
print(f'{markAmount1:016b}') #printing in binary
print(f'{markAmount1:016b}')
print('Database updated successfully')
except Exception as mbe:
print ("[2ERROR] %s" % mbe)
print ("[2ERROR] %s" % hh)
continue
########################OUTPUT & Errors#########################
Connected to Device Successfully
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
0000000000000110
0000000000000110
Database updated successfully
Execution time for this ieration:3.2803220748901367 seconds
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
0000000000000110
0000000000000110
Database updated successfully
Execution time for this ieration:3.0476126670837402 seconds
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
[2ERROR] 'ModbusIOException' object has no attribute 'registers'
Requesting Data From Registers..
Output:
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.