Example #1
0
    def Toggle(self):
        '''
        打开关闭串口
        '''
        if self.frm_left_btn["text"] == "Open":
            try:
                self.currentStrCom = self.frm_left_listbox.get(
                    self.frm_left_listbox.curselection())
                if platform.system() == "Windows":
                    self.port = self.currentStrCom.split(":")[0]
                elif platform.system() == "Linux":
                    self.port = self.currentStrCom
                self.baudrate = self.frm_left_combobox_baudrate.get()
                self.parity = self.frm_left_combobox_parity.get()
                self.databit = self.frm_left_combobox_databit.get()
                self.stopbit = self.frm_left_combobox_stopbit.get()
                self.ser = SerialHelper.SerialHelper(Port=self.port,
                                                     BaudRate=self.baudrate,
                                                     ByteSize=self.databit,
                                                     Parity=self.parity,
                                                     Stopbits=self.stopbit)
                self.ser.start()
                if self.ser.alive:
                    self.frm_status_label[
                        "text"] = "Open [{0}] Successful!".format(
                            self.currentStrCom)
                    self.frm_status_label["fg"] = "#66CD00"
                    self.frm_left_btn["text"] = "Close"
                    self.frm_left_btn["bg"] = "#F08080"

                    self.thread_read = threading.Thread(target=self.SerialRead)
                    self.thread_read.setDaemon(True)
                    self.thread_read.start()

            except Exception as e:
                logging.error(e)
                try:
                    self.frm_status_label[
                        "text"] = "Open [{0}] Failed!".format(
                            self.currentStrCom)
                    self.frm_status_label["fg"] = "#DC143C"
                except Exception as ex:
                    logging.error(ex)

        elif self.frm_left_btn["text"] == "Close":
            try:
                self.ser.stop()
                self.receive_count = 0
            except Exception as e:
                logging.error(e)
            self.frm_left_btn["text"] = "Open"
            self.frm_left_btn["bg"] = "#008B8B"
            self.frm_status_label["text"] = "Close Serial Successful!"
            self.frm_status_label["fg"] = "#8DEEEE"
Example #2
0
 def getport(self, *args, **kwargs):
     self.serialInstant = sh.SerialHelper(*args, **kwargs)
     self.serialInstant.start()
Example #3
0
def getport(*args, **kwargs):
    serialInstant = sh.SerialHelper(*args, **kwargs)
    serialInstant.start()
    return serialInstant