import traceback class Detector(ReadonlyRegisterBase): def __init__(self, name): ReadonlyRegisterBase.__init__(self, name) self.id = None self.sn = None self.status = None self.type = None self.inputs = [] class Esera(TcpDevice): def __init__(self, name, server, timeout = 1000, retries = 1): TcpDevice.__init__(self, name, server) self.setMode(self.Mode.FullDuplex) self.detectors = [] def start(self): self.write("set,sys,run,1\n") def stop(self): self.write("set,sys,run,0\n") def list(self): self.write("get,owb,listall1\n") def doInitialize(self): super(Esera, self).doInitialize() 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("Detector " + str(i+1))) 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 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: 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 #count = 1 #while (True): # print onewire.waitString("\n", 1000)# # # print count # count = count + 1 add_device(Esera("onewire", "129.129.126.83:5000"), force = True)