load registers

This commit is contained in:
2019-07-14 00:37:27 +02:00
parent c1bb481cac
commit a251015a33
2 changed files with 23 additions and 4 deletions

View File

@ -135,6 +135,28 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
self.lastContact = datetime.datetime.now()
def loadRegisterList(registerList):
# Load, check and auto-update registers file
with open(registerList, 'rb') as f:
datapoints = pickle.load(f)
RegisterDatapoint.checkRegisterList(datapoints, reset=True)
newDatapoints = []
for dp in datapoints:
ndp = type(dp)()
for k,v in dp.__dict__.items():
ndp.__dict__[k] = v
newDatapoints.append(ndp)
RegisterDatapoint.checkRegisterList(newDatapoints, reset=True)
with open(registerList, 'wb') as f:
pickle.dump(newDatapoints, f)
def checkRegisterList(registers, reset=False):
for r in registers:
if not isinstance(r, AbstractModbusDatapoint):

View File

@ -35,10 +35,7 @@ if __name__ == "__main__":
logger.debug('infrastructure prepared')
datapoints = None
with open(config.registerFile, 'rb') as f:
datapoints = pickle.load(f)
RegisterDatapoint.checkRegisterList(datapoints, reset=True)
datapoints = RegisterDatapoint.loadRegisterList(config.registerFile)
logger.debug('datapoints read')
cp = CommunicationProcessor.CommunicationProcessor(config, queue, pubQueue)