From b2a5e923cb5c46ed045e45d969cd3ef736b200dc Mon Sep 17 00:00:00 2001 From: gac-S_Changer Date: Mon, 13 Mar 2017 17:52:09 +0100 Subject: [PATCH] Closedown --- script/test/onewire.py | 70 +++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/script/test/onewire.py b/script/test/onewire.py index 089f90c..b95f0ae 100644 --- a/script/test/onewire.py +++ b/script/test/onewire.py @@ -7,9 +7,19 @@ class Detector(ReadonlyRegisterBase): self.sn = None self.status = None self.type = None - self.inputs = [] - + self.set_inputs({}) + + def set_inputs(self, inputs): + self.inputs = inputs + self.setCache(inputs.values(), None) + if (len(self.take()) == 0): + self.setState(State.Offline) + else: + self.setState(State.Ready) + def set_input(self, index, val): + self.inputs[index] = val + self.set_inputs(self.inputs) class Esera(TcpDevice): def __init__(self, name, server, timeout = 1000, retries = 1): @@ -26,6 +36,9 @@ class Esera(TcpDevice): def list(self): self.write("get,owb,listall1\n") + def req_events(self): + self.write("EVT\n") + def doInitialize(self): super(Esera, self).doInitialize() try: @@ -37,40 +50,44 @@ class Esera(TcpDevice): for i in range(30): self.detectors.append(Detector("Detector " + str(i+1))) self.list() - time.sleep(0.1) + time.sleep(0.5) self.start() except: print >> sys.stderr, traceback.format_exc() getLogger().log(traceback.format_exc()) raise + def doUpdate(self): + SET SYS DIO + #def onByte(self, rx): # print rx def onString(self, msg): tokens = msg.split("|") - try: - if msg[:3] == "LST": - #LST|1_OWD1|3AF361270000009E|S_0|DS2413| - if tokens[1] > 1: - index = int(tokens[1].split("_")[1][3:]) - 1 - if index < len(self.detectors): - det = self.detectors[index] - det.id = tokens[1] - det.sn= tokens[2] if len(tokens)>2 else None - det.status = int(tokens[3][2:]) if len(tokens)>3 else None - det.type = tokens[4] if len(tokens)>4 else None - else: - if len(tokens)>1: + if len(tokens)>1: + try: + if msg[:3] == "LST": + #LST|1_OWD1|3AF361270000009E|S_0|DS2413| + if tokens[1] > 1: + index = int(tokens[1].split("_")[1][3:]) - 1 + if index < len(self.detectors): + det = self.detectors[index] + det.id = tokens[1] + det.sn= tokens[2] if len(tokens)>2 else None + det.status = int(tokens[3][2:]) if len(tokens)>3 else None + det.type = tokens[4] if len(tokens)>4 else None + if det.status!= 0: + det.set_inputs({}) + else: for det in self.detectors: - if det.id is not None and msg.startswith(det.id): - index = int(tokens[0][len(det.id)+1:len(det.id)+2]) - 1 - if index < len(det.inputs): - det.inputs[index] = int(tokens[1]) - except: - print >> sys.stderr, traceback.format_exc() - getLogger().log(traceback.format_exc()) - print msg + if det.id is not None and msg.startswith(det.id): + det_id = int(tokens[0][len(det.id)+1:]) + det.set_input(det_id, int(tokens[1])) + except: + print >> sys.stderr, traceback.format_exc() + getLogger().log(traceback.format_exc()) + print msg @@ -87,4 +104,7 @@ class Esera(TcpDevice): -add_device(Esera("onewire", "129.129.126.83:5000"), force = True) \ No newline at end of file +add_device(Esera("onewire", "129.129.126.83:5000"), force = True) +add_device(onewire.detectors[0], force = True) +add_device(onewire.detectors[1], force = True) +add_device(onewire.detectors[2], force = True)