load registers
This commit is contained in:
@ -135,6 +135,28 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
|
|||||||
self.lastContact = datetime.datetime.now()
|
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):
|
def checkRegisterList(registers, reset=False):
|
||||||
for r in registers:
|
for r in registers:
|
||||||
if not isinstance(r, AbstractModbusDatapoint):
|
if not isinstance(r, AbstractModbusDatapoint):
|
||||||
|
@ -35,10 +35,7 @@ if __name__ == "__main__":
|
|||||||
logger.debug('infrastructure prepared')
|
logger.debug('infrastructure prepared')
|
||||||
|
|
||||||
|
|
||||||
datapoints = None
|
datapoints = RegisterDatapoint.loadRegisterList(config.registerFile)
|
||||||
with open(config.registerFile, 'rb') as f:
|
|
||||||
datapoints = pickle.load(f)
|
|
||||||
RegisterDatapoint.checkRegisterList(datapoints, reset=True)
|
|
||||||
logger.debug('datapoints read')
|
logger.debug('datapoints read')
|
||||||
|
|
||||||
cp = CommunicationProcessor.CommunicationProcessor(config, queue, pubQueue)
|
cp = CommunicationProcessor.CommunicationProcessor(config, queue, pubQueue)
|
||||||
|
Reference in New Issue
Block a user