diff --git a/script/test/onewire.py b/script/test/onewire.py index 7250009..7b3ec37 100644 --- a/script/test/onewire.py +++ b/script/test/onewire.py @@ -1,7 +1,9 @@ +import traceback class Detector(ReadonlyRegisterBase): - def __init__(self): - self.name = None + def __init__(self, name): + ReadonlyRegisterBase.__init__(self, name) + self.id = None self.sn = None self.status = None self.type = None @@ -18,7 +20,7 @@ class Esera(TcpDevice): self.setMode(self.Mode.FullDuplex) self.detectors = [] for i in range(30): - self.detectors.append(Detector()) + self.detectors.append(Detector("Detector " + str(i+1))) def start(self): self.write("set,sys,run,1\n") @@ -31,17 +33,21 @@ class Esera(TcpDevice): def doInitialize(self): super(Esera, self).doInitialize() - - self.setState(State.Ready) #So can communicate - self.stop() - time.sleep(0.1) - self.flush() - self.detectors = [] - for i in range(30): - self.detectors.append(Detector()) - self.list() - time.sleep(0.1) - self.start() + try: + self.setState(State.Ready) #So can communicate + self.stop() + time.sleep(0.1) + self.flush() + self.detectors = [] + for i in range(30): + self.detectors.append(Detector()) + self.list() + time.sleep(0.1) + self.start() + except: + print >> sys.stderr, traceback.format_exc() + getLogger().log(traceback.format_exc()) + raise #def onByte(self, rx): # print rx @@ -56,7 +62,7 @@ class Esera(TcpDevice): print "Index = " , index if index < len(self.detectors): det = self.detectors[index] - det.name = tokens[1] + 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 @@ -64,8 +70,8 @@ class Esera(TcpDevice): tokens = msg.split("|") if len(tokens)>1: for det in self.detectors: - if det.name is not None and msg.startswith(det.name): - index = int(tokens[0][len(det.name+1):len(det.name)+2]) + if det.id is not None and msg.startswith(det.id): + index = int(tokens[0][len(det.id+1):len(det.id)+2]) print "i=" , i input = tokens[1] except: