class GettingUartData_Thread(QtCore.QThread): def __init__(self,uart,parent=None): super(self.__class__, self).__init__(parent) self.stoped = False self.mutex = QtCore.QMutex() self.uart = uart self.getwrong_message = None def run(self): ccddata = None with QtCore.QMutexLocker(self.mutex): self.stoped = False try: self.uart.open() except SerialException,e: self.getwrong_message = e self.emit(QtCore.SIGNAL("UartData"), ccddata,self.getwrong_message) while True: if self.stoped == True: return try: ccddata = self.uart.GetData() except SerialException,e : self.getwrong_message = e self.emit(QtCore.SIGNAL("UartData"), ccddata,self.getwrong_message) self.emit(QtCore.SIGNAL("UartData"), ccddata,self.getwrong_message)
def run(self): ccddata = None with QtCore.QMutexLocker(self.mutex): self.stoped = False try: self.uart.open() except SerialException,e: self.getwrong_message = e self.emit(QtCore.SIGNAL("UartData"), ccddata,self.getwrong_message)
def AddingData_Stop(self): self.ProgressBar_Open("请稍候","串口关闭中...") self.adddata.stop() for x in range(100): self.ProgressBar_SetValue(x) sleep(0.001) if self.adddata.isStop(): self.disconnect(self.adddata, QtCore.SIGNAL("UartData"), self.AddingData) self.adddata.stop() self.adddata.quit() self.adddata.wait() self.adddata.deleteLater() self.ProgressBar_SetValue(100) self.ProgressBar_Stop()
def AddingData_Start(self): string = self.pushButton_collect.text( ) if string == u'开始采集': self.ReScanUart() if not self.uart.freeport: pass else: self.pushButton_collect.setText(u'关闭采集') #打开端口 for x in self.uart.freeport: if str(self.comboBox_com.currentText()) in x: self.uart.setPort(x[0]) self.uart.setBaudrate(self.comboBox_baudrate.currentText()) #清空 #self.CleanData() #串口数据线程 self.adddata = GettingUartData_Thread(self.uart) #采集串口数据 self.connect(self.adddata, QtCore.SIGNAL("UartData"), self.AddingData) self.adddata.start() self.textBrowser.append(u"<font color=green><b>采集</b> 已 <b>开始</b>!</font>") #禁止修改 self.comboBox_com.setDisabled(True) self.comboBox_baudrate.setDisabled(True) else: #停止收集 self.AddingData_Stop() self.textBrowser.append(u"<font color=green><b>采集</b> 已 <b>停止</b>!</font>") self.pushButton_collect.setText(u'开始采集') #打开修改 self.comboBox_com.setDisabled(False) self.comboBox_baudrate.setDisabled(False)
def OpenFile(self): filename = QtGui.QFileDialog.getOpenFileNames( self, caption=u'打开文件', directory = os.getcwd(), filter = u"数据库文件(*.db);;All files (*.*)", selectedFilter = u"数据库文件(*.db)" ) for x in filename: if x in self.ShowDataFileName: id2 = self.ShowDataFileName.index(x) self.ShowData[id2][0].show() else: try: data = cPickle.load(open(x,'r')) #图像初始化 except cPickle.UnpicklingError : QtGui.QMessageBox.warning(self,u"文件出错",u"文件出错!请检查!") continue #添加菜单栏 a = review_widget() if not self.ShowData: self.showdata_menu = self.menubar.addMenu(u'已打开文件') action = self.showdata_menu.addAction(x) self.connect(action,QtCore.SIGNAL("triggered()"),a.show) a.setWindowTitle(x) (manager,plots,curves) = Plot_Start_New(a,PLOT_DEFINE,COLORS,0,5,-5,200) plot = plots[0] for key, curve in curves.iteritems(): xdata = data["t"] ydata = data[key] x, y = get_peak_data(xdata, ydata, 0, 12, 1000, 1/DT) curve.set_data(x, y) plot.replot() #完成后设置 a.gridLayout.addWidget(plot) #图表 文件 self.ShowData.append((a,plot,curves,data)) #设置窗口名 self.ShowDataFileName.append(x) #设置 车辆设置 ''' a.label_angle_p.setText(str(data['angle_p'])) a.label_angle_i.setText(str(data['angle_i'])) a.label_angle_d.setText(str(data['angle_d'])) a.label_speed_up_p.setText(str(data['speed_up_p'])) a.label_speed_up_i.setText(str(data['speed_up_i'])) a.label_spped_up_d.setText(str(data['speed_up_d'])) a.label_speed_curve.setText(str(data['speed_curve'])) a.label_speed_straight.setText(str(data['speed_straight'])) a.label_k_ccd.setText(str(data['k_ccd'])) a.label_k_different.setText(str(data['k_different'])) a.label_light_time.setText(str(data['light_time'])) a.label_different_len.setText(str(data['different_len'])) a.label_different_size.setText(str(data['different_size'])) ''' a.show()
def __init__(self,parent=None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) # Ui_Form.setupUi ''' #最小化&关闭 self.minibutton = QtGui.QToolButton(self) self.minibutton.setGeometry(self.width()-45,5,20,20) self.closebutton = QtGui.QToolButton(self) self.closebutton.setGeometry(self.width()-25,5,20,20) ''' #加入设置窗口 #setting_ui = UI_Settings() #self.setting = QtGui.QWidget() #setting_ui.setupUi(self.setting) #新建窗口 self.ShowData = [] self.SD_data = [] #打开的窗体 self.open_widget = [] #显示文件的路径 self.ShowDataFileName = [] #设置lineedit self.lineEdit.selectAll() self.lineEdit.setFocus() #curves曲线 名字:曲线 self.curves = {} #图像管理器 self.manager = PlotManager(self) #data 数据 double型 t self.data = {u"t":array("d")} for name in sum(PLOT_DEFINE, []): self.data[name] = array("d") self.data['tn'] = 0 self.data['xmax'] = 0 self.data['xmin'] = 0 self.progressbar = [] #车辆设置数据 self.data['angle_p'] = 0 self.data['angle_i'] = 0 self.data['angle_d'] = 0 self.data['speed_up_p'] = 0 self.data['speed_up_i'] = 0 self.data['speed_up_d'] = 0 self.data['speed_curve'] = 0 self.data['speed_straight'] = 0 self.data['k_ccd'] = 0 self.data['k_different'] = 0 self.data['light_time'] = 0 self.data['different_len'] = 0 self.data['different_size'] = 0 #主图表 self.plots = [] #副图标 self.plots_extra = [] #图表设置 (self.manager,self.plots,self.curves) = Plot_Start_New(self,PLOT_DEFINE,COLORS,0,5,-5,200) for plot in self.plots: self.left_layout1.addWidget(plot) #self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys()) #添加设置窗口 self.setting_widget = setting_widget(self) self.open_widget.append(self.setting_widget) #连接 self.connect(self.pushButton_collect, QtCore.SIGNAL("clicked()"), self.AddingData_Start) self.connect(self.action_open,QtCore.SIGNAL("triggered()"),self.OpenFile) self.connect(self.action_save,QtCore.SIGNAL("triggered()"),self.SaveFile) self.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),lambda:self.Line2Brower(self.lineEdit)) #self.connect(self.lineEdit_2,QtCore.SIGNAL("returnPressed()"),lambda:self.Line2Brower(self.lineEdit_2)) self.connect(self.checkBox_x, QtCore.SIGNAL("clicked()"), self.Flx) self.connect(self.checkBox_y, QtCore.SIGNAL("clicked()"), self.Auto) #self.connect(self.pushButton_car_setting,QtCore.SIGNAL("clicked()"),self.Settings) self.connect(self.pushButton_com,QtCore.SIGNAL("clicked()"), self.ReScanUart) self.connect(self.about_qt,QtCore.SIGNAL("triggered()"), lambda:QtGui.QMessageBox.aboutQt(self)) self.connect(self.action_car,QtCore.SIGNAL("triggered()"),self.setting_widget.show) self.connect(self.pushButton_cleandata, QtCore.SIGNAL("clicked()"),self.CleanData) #self.connect(self.pushButton_run,QtCore.SIGNAL("clicked()"),self.CarStartRun) #------------------------------------------------------小车设置连接---------------------------------------------------------------------------- # self.connect(self.setting_widget.pushButton_Stop, QtCore.SIGNAL("clicked()"),lambda :self.SetAngleP(20)) self.connect(self.setting_widget.pushButton_Stop, QtCore.SIGNAL("clicked()"),self.CarStopRun) self.connect(self.setting_widget.apply, QtCore.SIGNAL("clicked()"),self.SettingApply) self.connect(self.setting_widget.pushButton_Start, QtCore.SIGNAL("clicked()"),self.CarStartRun) #进度条 msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "", "", QtGui.QMessageBox.NoButton,parent = self ) msgBox.setStandardButtons( QtGui.QMessageBox.NoButton ) l = msgBox.layout() self.progressbar.append(msgBox) l.itemAtPosition( l.rowCount() - 1, 0 ).widget().hide() progress = QtGui.QProgressBar() self.progressbar.append(progress) progress.setValue(0) l.addWidget(progress,l.rowCount(), 0, 1, l.columnCount(), Qt.AlignCenter ) #--------------------------------------------------添加图像窗口------------------------------------------------------------------------------- self.ccd_realshow = [] t = 0 t_past = 0 ccd_realshow = show_realdata_widget() data = {} data[u't'] = 0 data[u't_past'] = 0 temp_d = array('d') for i in range(128): temp_d.append(0) ccd_realshow.setWindowTitle(u"图像显示") ccd_realshow.setGeometry(200,200,400,400) for x in range(3): (memger,plots,curves) = Plot_Start_New( ccd_realshow, ( (u'CCD图像%d'%(x+1), u'CCD图像%d左'%(x+1), u'CCD图像%d中'%(x+1), u'CCD图像%d右'%(x+1), ), ), ('white','red','green','blue'),0,128,0,255 ) temp_data = data.copy() temp_data[u'CCD图像%d'%(x+1)] = temp_d[:] temp_data[u'CCD图像%d左'%(x+1)] = temp_d[:] temp_data[u'CCD图像%d中'%(x+1)] = temp_d[:] temp_data[u'CCD图像%d右'%(x+1)] = temp_d[:] self.ccd_realshow.append([u'CCD图像%d'%(x+1),ccd_realshow,plots,curves,temp_data]) for plot in plots: ccd_realshow.gridLayout.addWidget(plot) for x in self.ccd_realshow: for y in x[2]: y.hide() ccd_realshow.checkBox_ccd1.setChecked(0) ccd_realshow.checkBox_ccd2.setChecked(0) ccd_realshow.checkBox_ccd3.setChecked(0) self.connect(ccd_realshow.checkBox_ccd1, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(0,x)) self.connect(ccd_realshow.checkBox_ccd2, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(1,x)) self.connect(ccd_realshow.checkBox_ccd3, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(2,x)) self.connect(self.setting_widget.checkBox_ccd1,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd1.setChecked) self.connect(self.setting_widget.checkBox_ccd2,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd2.setChecked) self.connect(self.setting_widget.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd3.setChecked) self.connect(ccd_realshow.checkBox_ccd1,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd1.setChecked) self.connect(ccd_realshow.checkBox_ccd2,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd2.setChecked) self.connect(ccd_realshow.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd3.setChecked) self.connect(self.setting_widget.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd3.setChecked) self.connect(self.setting_widget.pushButton_real_data_Show,QtCore.SIGNAL("clicked()"),ccd_realshow.show) self.connect(ccd_realshow.pushButton_single, QtCore.SIGNAL("clicked()"),self.SdRunSingle) self.connect(ccd_realshow.pushButton_back, QtCore.SIGNAL("clicked()"),self.SdRunSingleBack) #--------------------------------------------------添加图像窗口------------------------------------------------------------------------------- self.connect(self.action_sd_open,QtCore.SIGNAL("triggered()"),self.OpenSDFile) #定时显示 self.startTimer(40)
def isStop(self): with QtCore.QMutexLocker(self.mutex): return self.stoped
def stop(self): with QtCore.QMutexLocker(self.mutex): self.uart.close() self.getwrong_message = None self.stoped = True
def __init__(self,uart,parent=None): super(self.__class__, self).__init__(parent) self.stoped = False self.mutex = QtCore.QMutex() self.uart = uart self.getwrong_message = None