class Detector(ReadonlyRegisterBase): def __init__(self): self.name = None self.sn = None self.status = None self.type = None self.det1 = None self.det2 = None self.det3 = None self.det4 = None class Esera(TcpDevice): def __init__(self, name, server, timeout = 1000, retries = 1): TcpDevice.__init__(self, name, server) self.setMode(self.Mode.FullDuplex) self.detectors = [] for i in range(30): self.detectors.append(Detector()) 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() 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() #def onByte(self, rx): # print rx def onString(self, msg): try: if msg[:3] == "LST": tokens = msg.split() #LST|1_OWD1|3AF361270000009E|S_0|DS2413| if tokens[1] > 1: int index = int(tokens[1].split("_")[1][3:]) print "Index = " , index if index < len(self.detectors): det = self.detectors[index] det.name = tokens[1] def.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 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)