load registers
This commit is contained in:
@ -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):
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user