def onconfigure(self, e): if hasattr(e, "conf") and e.conf is not None: self.__conf = e.conf else: raise knitlib.exceptions.InputException("Conf dict is missing") conf = self.__conf if self.__port is "": self.__port = conf.get("port", "/dev/ttyUSB0") try: os.mkdir(self.__folder) except OSError: # Exception thrown meaning the folder already exists logging.warning("PDD temp folder already exists") # Copying the image file to temp folder. try: shutil.copy(conf.get("file_url"), self.__folder) except IOError: logging.error("Error when copying file url") self.__emu = PDDemulator(self.__folder)
def initEmulator(self): self.emu = PDDemulator(self.getConfig().imgdir) self.emu.listeners.append(PDDListener(self)) #self.emu = lambda: 1 self.setEmulatorStarted(False)
return True def onfinish(self, e): # TODO: remove and cleanup dir at self.__folder self.__emu.close() @staticmethod def supported_config_features(): return {"$schema": "http://json-schema.org/schema#", "type": "object"} if __name__ == "__main__": if len(sys.argv) < 3: print 'Usage: %s basedir serialdevice' % sys.argv[0] sys.exit() print 'Preparing . . . Please Wait' emu = PDDemulator(sys.argv[1]) # TODO: fix usb port hardcoding emu.open(cport=sys.argv[2]) print 'Emulator Ready!' try: while 1: emu.handleRequests() except (KeyboardInterrupt): pass emu.close()