Exemple #1
0
 def openfile_dialog(self):
     try:
         self.file, _ = QFileDialog.getOpenFileName(self, 'Open', 'C:\'',
                                                    "Excel(*.xlsx *.xls)")
         print(self.file)
         if self.file:
             # Enable the Button
             self.pushButton_ok.setEnabled(True)
     except FileNotFoundError:
         QMessageBox.Critical(self, 'File Not Found',
                              'Selected File Could Not Be Found!',
                              QMessageBox.Ok, QMessageBox.Ok)
     except Exception as e:
         QMessageBox.Critical(self, 'Exception!', str(e), QMessageBox.Ok,
                              QMessageBox.Ok)
Exemple #2
0
    def open_close(self, btn_sta):
        if btn_sta == True:
            try:
                input('输入参数 COM 115200')
                print(int(self.comboBox_2.currentText()))
                self.ser = serial.Serial(self.comboBox.currentText(),
                                         int(self.comboBox_2.currentText()),
                                         timeout=0.1)
            except:
                QMessageBox.Critical(self, 'pycom', '没有可用的串口或者当前的串口被占用')
                return None
            #字符间隔超时设置
            self.ser.interCharTimeout = 0.001

            #1ms的测试周期
            self.timer.start(2)
            self.pushButton_2.setText('关闭串口')
            print('打开!')
        else:
            self.timer_send.stop()
            self.timer.stop()
            try:
                #关闭串口
                self.ser.close()
            except:
                QMessageBox.critical(self, 'pycom', '关闭串口失败')
                return None
            self.ser = None
            self.pushButton_2.setText('打开串口')
            print('关闭')