i am setting up a ModbusServer with pymodbus. i read a datalist over Serial port an write it into datastore of the server. so i can see data f.e. in ModbusPoll
now i want write back datapoints f.e. dp 1, value 10 function 16 on my modbus server
is there any callback or method to catch which address and value hast changed?
Many Thanks
class CustomDataBlock(ModbusSparseDataBlock):
def setValues(self, address, value):
super(CustomDataBlock, self).setValues(address, value)
print("wrote {} to {}".format(value, address))
def setValuesInternal(self, address, value):
ModbusSparseDataBlock.setValues(CustomDataBlock, self).setValues(address, value)
def updating_writer(context):
context[0].setValuesInternal(16, 0, valueDataAct) #update Datastore with Serial values
def run_updating_server():
block = CustomDataBlock([0]*378)
store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
context = ModbusServerContext(slaves=store, single=True)
time = 1 #in seconds
loop = LoopingCall(f=updating_writer, context=(context))
loop.start(time, now=False)
StartTcpServer(context, address=('0.0.0.0', 502))
if __name__ == "__main__":
run_updating_server()