I added a LoopingCall that ran every second as follows
from twisted.internet.task import LoopingCall
lc = LoopingCall(get_MCA_Data)
lc.start(1.0)
The get_MCA_Data function collects data from an external device and puts it into the Datastore as follows (I am only using Holding Registers hence the first argument 3)
store.setValues(3,0,list(fields))
where fields contains the data I want to put into the store.
Now my question.
I am pretty sure that I have generated the fields in the ugliest way possible.
Single WORD ints were easy but I needed LONG ints so I used the BinaryPayloadBuilder and specifically the add_32bit_uint function, but the output of the build() function wouldn't work in the setValues function so I created payload as follows
payload = builder.__str__()
fields = struct.unpack('16H',payload)
and used list(fields) in setValues()
Surely there is a much nicer way that this to deal with LONG and FLOAT?
I am also not sure exactly how to deal with data sent to the server.
I could just read from the datastore into my variable on the same LoopingCall which would not be as responsive as I may need.
Is there a way of accessing a Callback when data is changed in the datastore?