Hey guys, I am usresure this is just my understanding of modbus (pymodbus), but I am curious to know why I can write a register but if I read it again the value appears incorrect:
Code:
def stop_charging_and_export_solar(): print ("Stopping Battery Charging") client.write_register(2701,int(0)) def start_charging(): print ("Starting Battery Charging") client.write_register(2701,int(100)) --- inside main method -- stop_charging_and_export_solar() result = client.read_holding_registers(2701) print (result.registers[0]) start_charging() result = client.read_holding_registers(2701) print (result.registers[0])
This prints the following
Stopping Battery Charging
0
Starting Battery Charging
0
And if I run it again it prints
Stopping Battery Charging
100
Starting Battery Charging
100
I am guessing this is something connection related like registers are only written when connection is closed? What am I missing and how do I get around it?
Background is I am trying to optimise export/import from grid based on spot price and as a result my program runs in an infinite loop polling the price every minute.
Thanks