diff --git a/src/RegisterDatapoint.py b/src/RegisterDatapoint.py index 80450fe..ecaf80f 100644 --- a/src/RegisterDatapoint.py +++ b/src/RegisterDatapoint.py @@ -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): diff --git a/src/master.py b/src/master.py index 6405407..4e55f50 100644 --- a/src/master.py +++ b/src/master.py @@ -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)