def requestFilelist(self, filename=None, overwrite=False): filelist = [] resp = self.request(u"\xda\x00\x04\x05") if resp == None: return filelist, False num_files = RDLaser.toNumber(resp) for i in range(0, num_files): resp = self.request(u"\xe8\x01" + RDLaser.fromNumber(i + 1, 2)) if resp == None: break filename_ = resp[:-1].upper() ''' fileno = RDLaser.toNumber(resp[:2], 2) if i+1 != fileno: raise ValueError("Reported filenumber does not match iterator") ''' filelist.append(filename_) if filename is not None and filename.upper() == filename_[:-1]: while not daemon: print "Duplicate Filename %s, overwrite?" % filename inp = raw_input("[Y/N] ") if inp.lower() == "y": overwrite = True break elif inp.lower() == "n": break if overwrite: self.send(u"\xe8\x00" + RDLaser.fromNumber(i + 1, 2) + RDLaser.fromNumber(i + 1, 2)) return filelist, True return filelist, False if filename is not None: self.send(u"\xe8\x02\xe7\x01" + filename + u"\x00") return filelist, True
def callback(self, addr, data): # HANDSHAKE, MODEL, STATE? if data == self.HANDSHAKE: self.send(addr, u"\xda\x01\x05\x7e\x06\x28\x41\x4a\x10") #STATE #elif data == u"\x02\x73\xd4\x89\x8d\x89": # ssend(addr, "d4098d8989c98d810b".decode("HEX")) elif data == u"\xda\x00\x00\x60": self.respond(addr, data, 65535) # Filelist request elif data == u"\xda\x00\x04\x05": self.sendFilelist(addr) elif data[:2] == u"\xe8\x00": self.deleteFile(RDLaser.toNumber(data[2:], 2)) #elif data[:2] == u"\xe8\x04": # self.calculateTime(RDLaser.toNumber(data[2:], 2)) elif data[0] == u"\xe5": self.sendFile(RDLaser.toNumber(data[1:], 2)) # System info request elif data[2:-1] == u"\xda\x00\x04": self.sendSystemInfo(addr, ord(data[-1])) # Model number query elif data == RDLaser.MAINBOARD_VERSION: self.send( addr, u"\xda\x01\x05\x7f" + RDLaser.values[RDLaser.MAINBOARD_VERSION] + u"\x00") # Specific codes (deprecated) elif data.encode("hex") in self.responses: self.send(addr, self.responses[data.encode("hex")]) # Generic answer ### # Query is as following: # 0x89 0xXX 0xDA 0x00 0xYY 0xZZ # Answers are in following format: # 0xDA 0x01 0xYY 0xZZ ... # so each request [4:6] must match response [2:4] # Rest of the answer (...) does not noticably change anything as far as tested ### elif data[:2] == u"\xda\x00": try: self.respond(addr, data, RDLaser.values[data]) except: self.respond(addr, data, 0)
def readSystemInfo(self, opt): data = self.request(opt) if data is None: return None else: val = RDLaser.toNumber(data[-5:]) try: RDLaser.values[opt] = val except: pass return val
def calculateTime(self, fileno): self.init() return RDLaser.toNumber( self.request(u"\xe8\x04" + RDLaser.fromNumber(fileno, 2)))
def moveAxis(self, axis, nm=10000, speed=100000): self.send(u"\xc9\x02" + RDLaser.fromNumber(speed)) return self.send(u"\xd9" + chr(axis) + u"\x02" + RDLaser.toNumber(nm))