def On_StartStop( self, event, idx): global device if device.propCom.isOpen() == False: self.widgets[idx].startBtn.SetValue(False) if logger.ask("No Propeller attached. Rescan ports?", "Error" ): device.propCom.start() if self.widgets[idx].startBtn.GetValue(): if self.widgets[idx].runForTimer is not None: device.channels[idx].start() for t in self.widgets[idx].progressTimers: t.start() self.widgets[idx].runForTimer.start() else: device.channels[idx].start() self.widgets[idx].progressBar.SetValue(0) else: device.channels[idx].stop() self.widgets[idx].timerText.SetLabel("000:00:00") self.widgets[idx].timerText.Enable(False) self.widgets[idx].progressBar.SetValue(0) for t in self.widgets[idx].progressTimers: t.cancel() self.widgets[idx].progressTimers = [] if self.widgets[idx].runForTimer is not None: self.widgets[idx].runForTimer.cancel() self.widgets[idx].runForTimer = None
def On_StartStop(self, event, idx): global device if device.propCom.isOpen() == False: self.widgets[idx].startBtn.SetValue(False) if logger.ask("No Propeller attached. Rescan ports?", "Error"): device.propCom.start() if self.widgets[idx].startBtn.GetValue(): if self.widgets[idx].runForTimer is not None: device.channels[idx].start() for t in self.widgets[idx].progressTimers: t.start() self.widgets[idx].runForTimer.start() else: device.channels[idx].start() self.widgets[idx].progressBar.SetValue(0) else: device.channels[idx].stop() self.widgets[idx].timerText.SetLabel("000:00:00") self.widgets[idx].timerText.Enable(False) self.widgets[idx].progressBar.SetValue(0) for t in self.widgets[idx].progressTimers: t.cancel() self.widgets[idx].progressTimers = [] if self.widgets[idx].runForTimer is not None: self.widgets[idx].runForTimer.cancel() self.widgets[idx].runForTimer = None
def openFirstProp(self, openFunc): # store old version callback. if "version" in self.callbacks: oldVerCallback = self.callbacks["version"] else: oldVerCallback = None opened = [False] # whether or not a valid port has been opened. retry = True # whether or not function will retry opening com = serial.Serial() # print "Baud Rate:" + str(self.com.baudrate) com.baudrate = self.com.baudrate # print "Baud Rate:" + str(com.baudrate) # print com.BAUDRATES # print com.getSettingsDict() while opened[0] == False and retry == True: # cycle through all available ports sending <version>, and waiting for response. ports = serial.tools.list_ports.comports() for p in ports: logger.log("Testing port", p[0], logger.INFO) com.port = p[0] ID = 0 try: com.open() def verHandler(propCom, ver): logger.log("Response on port", com.port, logger.INFO) if opened[0] == False: opened[0] = True com.close() # make sure com is closed first openFunc(propCom, com.port) # open new port return 0 ID = self.register("version", verHandler) self.comlock.acquire(True) # block until lock taken com.write("<version>") self.comlock.release() # release comlock for others! time.sleep(DEFAULTTIMEOUT) resp = com.read(com.inWaiting()) parsed = self.parse(resp) except (serial.serialutil.SerialException, ValueError, serial.serialutil.SerialTimeoutException) as err: logger.log("Error with port", com.port, logger.WARNING) com.close() finally: com.close() # make sure to close com port. try: # catch exceptions from invalid ID self.deregister("version", ID) except KeyError: logger.log("Can't Deregister version handler", "ID does not exist", logger.WARNING) time.sleep(0.1) if opened[0] == False: retry = logger.ask("No Propeller detected. retry?", logger.QUESTION) if oldVerCallback is not None: self.callbacks["version"] = oldVerCallback else: del self.callbacks["version"]
def On_Light(self, event, idx): global device if device.propCom.isOpen() == False: for w in self.widgets[idx].lights: w.SetValue(False) if logger.ask("No Propeller attached. Rescan ports?", "Error"): device.propCom.start() else: bitmask = 0 for w in self.widgets[idx].lights[::-1]: bitmask = bitmask << 1 if w.GetValue(): bitmask = bitmask | 1 device.digitals.setValue(bitmask)
def askSave(self): if logger.ask("Save Graph Data?", logger.QUESTION): self.OnSave(None)
def openFirstProp(self, openFunc): # store old version callback. if "version" in self.callbacks: oldVerCallback = self.callbacks["version"] else: oldVerCallback = None del self.callbacks["version"] opened = [False] # whether or not a valid port has been opened. retry = True # whether or not function will retry opening com = serial.Serial() com.baudrate = self.com.baudrate while opened[0] == False and retry == True: # cycle through all available ports sending <version>, and waiting for response. ports = serial.tools.list_ports.comports() for p in ports: logger.log("Testing port", p[0], logger.INFO) com.port = p[0] ID = 0 try: com.open() def verHandler(propCom, ver): logger.log("Response on port", com.port, logger.INFO) if opened[0] == False: opened[0] = True com.close() #make sure com is closed first openFunc(propCom, com.port) #open new port return 0 ID = self.register("version", verHandler) verStr = chr(3) + chr(1) + EOP + chr(7) self.comlock.acquire(True) #block until lock taken com.write(verStr) self.comlock.release() #release comlock for others! time.sleep(logger.options["timeout"]) resp = com.read(com.inWaiting()) if logger.options["log_parsing"]: logger.write(resp) parsed = self.parse(EOP + " " + resp) except (serial.serialutil.SerialException, ValueError, serial.serialutil.SerialTimeoutException) as err: logger.log("Error with port", com.port, logger.WARNING) com.close() finally: com.close() # make sure to close com port. try: # catch exceptions from invalid ID self.deregister("version", ID) except KeyError: logger.log("Can't Deregister version handler", "ID does not exist", logger.WARNING) time.sleep(0.1) if opened[0] == False: retry = logger.ask("No Propeller detected. retry?", logger.QUESTION) if oldVerCallback is not None: self.callbacks["version"] = oldVerCallback else: del self.callbacks["version"]