question

Mike Casey avatar image
Mike Casey asked

Modbus writing register and reading it again over single connection? Dirty Read

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


Modbus TCP
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

0 Answers

Related Resources