Capture::Capture(QWidget *parent) : QWidget(parent), ui(new Ui::Capture) { ui->setupUi(this); //initialize ///111 take_photo_flag = 0; ///111 num = 0; send_frame_flag = 0; //capture = NULL; //timer = new QTimer(this); photos = new Photos(); this->first_open_cam_flag = 0; this->open_cam_flag=0; timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(update())); //initialize socketbind port 63636 send_socket = new QUdpSocket(this); send_socket->bind(63636, QUdpSocket::ShareAddress); //enable button ui->close_pushButton->setDisabled(true); //ui->image_close_pushButton->setDisabled(false); ui->take_photo_pushButton->setDisabled(true); //this->setWindowFlags(Qt::Tool | Qt::X11BypassWindowManagerHint); this->setWindowFlags(Qt::FramelessWindowHint); ui->video_label->setStyleSheet ("background-color: #000000;color: #ffffff;"); //C_translateLanguage();//set the content of button this->picNum = 0; //serial_port this->serial_open_flag = 0; struct PortSettings myComSetting = {BAUD4800,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,10}; myCom = new Posix_QextSerialPort("/dev/ttyUSB0",myComSetting,QextSerialBase::Polling); //myCom->open(QIODevice::ReadWrite); readTimer = new QTimer(this); readTimer->start(10); connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom())); connect(send_socket, SIGNAL(readyRead()), this, SLOT(readData())); connect(ui->open_pushButton,SIGNAL(clicked()),this,SLOT(openCapture())); connect(ui->close_pushButton,SIGNAL(clicked()),this,SLOT(closeCapture())); connect(timer,SIGNAL(timeout()),this,SLOT(readFrame())); connect(ui->image_open_pushButton, SIGNAL(clicked()), this, SLOT(openPhotos())); connect(ui->image_close_pushButton, SIGNAL(clicked()), this, SLOT(closePhotos())); connect(photos, SIGNAL(closeImage()), this, SLOT(closePhotos())); connect(ui->take_photo_pushButton, SIGNAL(clicked()), this, SLOT(takePhotos())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); struct PortSettings myComSettings = {BAUD115200,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,500}; myCom = new Posix_QextSerialPort("/dev/ttyO0",myComSettings,QextSerialBase::Polling); //Polling:轮询 myCom->open(QIODevice::ReadWrite); readTimer = new QTimer(this); readTimer->start(100); connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom())); }
MQSerial::MQSerial(QWidget *parent) : QMainWindow(parent), ui(new Ui::MQSerial) { ui->setupUi(this); open_button_state=false; receivenum =0; sendnum=0; prm_table[0]=19; prm_table[1]=3; prm_table[2]=0; prm_table[3]=0; ui->pushButton_3->setEnabled(false); ui->pushButton_2->setEnabled(false); myCom = new Posix_QextSerialPort("/dev/ttyS0"); // myCom = new Win_QextSerialPort("\\\\.\\com11", QextSerialBase::EventDriven); connect(myCom,SIGNAL(readyRead()),this,SLOT(readMyCom())); readTimer = new QTimer(this); readTimer->start(100); //设置延时为100ms connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom())); // for(int i=0;comm.getcomm(i,"value")!="nokey"&&comm.getcomm(i,"value")!="Cannot open regedit!";i++) // { // ui->comboBox->addItem(comm.getcomm(i,"value")); // } }
//打开串口 void MainWindow::on_button_open_clicked() { QString portName = ui->comboBox->currentText(); myCom = new Win_QextSerialPort(portName,QextSerialBase::EventDriven); if(myCom ->open(QIODevice::ReadWrite) == false){ QMessageBox::information(NULL, "星海坊主", "打开串口失败!"); return; } myCom->setBaudRate(BAUD115200); myCom->setDataBits(DATA_8); myCom->setParity(PAR_NONE); myCom->setStopBits(STOP_1); myCom->setFlowControl(FLOW_OFF); myCom->setTimeout(1000); connect(myCom,SIGNAL(readyRead()),this,SLOT(readMyCom())); isMyComOpen = true; ui->button_close->setEnabled(true); ui->button_open->setEnabled(false); }
//初始化 void MainWindow::startInit() { setActionsEnabled(false); ui->delayspinBox->setEnabled(false); ui->sendmsgBtn->setEnabled(false); ui->sendMsgLineEdit->setEnabled(false); ui->obocheckBox->setEnabled(false); ui->actionAdd->setEnabled(true); //初始化读取定时器计时间隔 timerdly = TIMER_INTERVAL; //初始化连续发送计时器计时间隔 obotimerdly = OBO_TIMER_INTERVAL; //设置读取计时器 timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(readMyCom())); //设置连续发送计时器 obotimer = new QTimer(this); connect(obotimer, SIGNAL(timeout()), this, SLOT(sendMsg())); }
int Capture::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: openCapture(); break; case 1: closeCapture(); break; case 2: readFrame(); break; case 3: openPhotos(); break; case 4: closePhotos(); break; case 5: takePhotos(); break; case 6: readData(); break; case 7: on_serial_btn_clicked(); break; case 8: on_image_close_pushButton_clicked(); break; case 9: paintEvent((*reinterpret_cast< QPaintEvent*(*)>(_a[1]))); break; case 10: readMyCom(); break; default: ; } _id -= 11; } return _id; }
//打开串口 void MainWindow::on_actionOpen_triggered() { QString portName = ui->portNameComboBox->currentText(); //获取串口名 #ifdef Q_OS_LINUX myCom = new QextSerialPort("/dev/" + portName); #elif defined (Q_OS_WIN) myCom = new QextSerialPort(portName); #endif connect(myCom, SIGNAL(readyRead()), this, SLOT(readMyCom())); //设置波特率 myCom->setBaudRate((BaudRateType)ui->baudRateComboBox->currentText().toInt()); //设置数据位 myCom->setDataBits((DataBitsType)ui->dataBitsComboBox->currentText().toInt()); //设置校验 switch(ui->parityComboBox->currentIndex()){ case 0: myCom->setParity(PAR_NONE); break; case 1: myCom->setParity(PAR_ODD); break; case 2: myCom->setParity(PAR_EVEN); break; default: myCom->setParity(PAR_NONE); qDebug("set to default : PAR_NONE"); break; } //设置停止位 switch(ui->stopBitsComboBox->currentIndex()){ case 0: myCom->setStopBits(STOP_1); break; case 1: #ifdef Q_OS_WIN myCom->setStopBits(STOP_1_5); #endif break; case 2: myCom->setStopBits(STOP_2); break; default: myCom->setStopBits(STOP_1); qDebug("set to default : STOP_1"); break; } //设置数据流控制 myCom->setFlowControl(FLOW_OFF); //设置延时 myCom->setTimeout(TIME_OUT); if(myCom->open(QIODevice::ReadWrite)){ QMessageBox::information(this, tr("打开成功"), tr("已成功打开串口") + portName, QMessageBox::Ok); //界面控制 ui->sendmsgBtn->setEnabled(true); setComboBoxEnabled(false); ui->sendMsgLineEdit->setEnabled(true); ui->actionOpen->setEnabled(false); ui->sendMsgLineEdit->setFocus(); ui->obocheckBox->setEnabled(true); ui->actionAdd->setEnabled(false); setActionsEnabled(true); }else{ QMessageBox::critical(this, tr("打开失败"), tr("未能打开串口 ") + portName + tr("\n该串口设备不存在或已被占用"), QMessageBox::Ok); return; } ui->statusBar->showMessage(tr("打开串口成功")); }
//点击打开串口按钮 void MainWindow::on_openMyComBtn_clicked() //打开串口按钮 按下 槽函数 { //portName = ui->portNameComboBox->currentText(); //获取串口名 myCom = new Win_QextSerialPort(portName, QextSerialBase::EventDriven); //定义串口对象,并传递参数,在构造函数中对其初始化 bool openFlag = myCom -> open(QIODevice::ReadWrite); //以可读写方式打开串口,必须先打开串口再对相关参数做设置 if(FALSE == openFlag) { QMessageBox::warning(this, tr("Warning"), tr("串口不存在或已被占用!"), QMessageBox::Yes); return; } /* if(ui->baudRateComboBox->currentText() == tr("9600")) //设置波特率 myCom->setBaudRate(BAUD9600); else if(ui->baudRateComboBox->currentText() == tr("115200")) myCom->setBaudRate(BAUD115200); */ if(baudRateName == "BAUD9600") myCom->setBaudRate(BAUD9600); else if(baudRateName == "BAUD115200") myCom->setBaudRate(BAUD115200); /* if(ui->dataBitsComboBox->currentText() == tr("8")) //设置数据位数 myCom->setDataBits(DATA_8); else if(ui->dataBitsComboBox->currentText() == tr("7")) myCom->setDataBits(DATA_7); */ if(databitsName == "DATA_8") myCom->setDataBits(DATA_8); else if(databitsName == "DATA_7") myCom->setDataBits(DATA_7); /* if(ui->parityComboBox->currentText() == tr("无校验")) //设置校验位 myCom->setParity(PAR_NONE); else if(ui->parityComboBox->currentText() == tr("奇校验")) myCom->setParity(PAR_ODD); else if(ui->parityComboBox->currentText() == tr("偶校验")) myCom->setParity(PAR_EVEN); */ if(parityName == "NONE") myCom->setParity(PAR_NONE); else if(parityName == "ODD") myCom->setParity(PAR_ODD); else if(parityName == "EVEN") myCom->setParity(PAR_EVEN); /* if(ui->stopBitsComboBox->currentText() == tr("1")) //设置停止位 myCom->setStopBits(STOP_1); else if(ui->stopBitsComboBox->currentText() == tr("2")) myCom->setStopBits(STOP_2); */ if(stopbitsName == "STOP_1") myCom->setStopBits(STOP_1); else if(stopbitsName == "STOP_2") myCom->setStopBits(STOP_2); myCom->setFlowControl(FLOW_OFF); //设置数据流控,这里直接设置为无数据流控 myCom->setTimeout(500); //设置延时 connect(myCom, SIGNAL(readyRead()), this, SLOT(readMyCom())); //信号关联槽,当串口缓冲区有数据时,进行串口读操作 ui->openMyComBtn->setEnabled(false); //打开串口后,“打开串口“按钮不可用 ui->closeMyComBtn->setEnabled(true); //打开串口后,”关闭串口“按钮可用 ui->sendMsgBtn->setEnabled(true); //打开串口后,”发送数据“按钮可用 //ui->baudRateComboBox->setEnabled(false); //当开启串口后,不能再修改相关参数 //ui->dataBitsComboBox->setEnabled(false); //ui->parityComboBox->setEnabled(false); //ui->stopBitsComboBox->setEnabled(false); //ui->portNameComboBox->setEnabled(false); HEXSendSelect->setEnabled(false); HEXDisplaySelect->setEnabled(false); comMenu->setEnabled(false); ui->pauseBtn->setEnabled(true); ui->comStatusLabel->setEnabled(true); }
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent) { showMaximized(); setWindowTitle("TDLAS"); customPlot=new QCustomPlot(); customPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignCenter); customPlot_gas=new QCustomPlot(); customPlot_gas->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); PB_start=new QPushButton("开始"); PB_stop=new QPushButton("中止"); PB_quit=new QPushButton("退出"); PB_stop->setEnabled(false); LB_signalLength=new QLabel("输入信号长度:"); LB_firLength=new QLabel("FIR滤波器长度:"); LB_spendTime=new QLabel("信号处理耗时(s):"); LB_maxPos=new QLabel("最大峰值:"); LB_status=new QLabel("状态:"); countLabel=new QLabel("计数:"); LB_signalLength_value=new QLabel(); LB_firLength_value=new QLabel(); LB_spendTime_value=new QLabel(); LB_maxPos_value=new QLabel(); LB_status_value=new QLabel(); countLabel_value=new QLabel(); CB_mode=new QCheckBox("Raw Mode"); modeCombo=new QComboBox(); modeCombo->addItem("包络"); modeCombo->addItem("CO"); modeCombo->addItem("CO2"); modeCombo->addItem("C2H2"); //工具栏 QToolBar *toolBar=new QToolBar(this); toolBar->setMovable(false); addToolBar(Qt::TopToolBarArea,toolBar); toolBar->addSeparator(); toolBar->addSeparator(); toolBar->addWidget(modeCombo); toolBar->addSeparator(); toolBar->addWidget(CB_mode); toolBar->addSeparator(); toolBar->addWidget(PB_start); toolBar->addSeparator(); toolBar->addWidget(PB_stop); toolBar->addSeparator(); toolBar->addWidget(PB_quit); QGroupBox *groupBox=new QGroupBox(); QGridLayout *grid=new QGridLayout(groupBox); grid->addWidget(LB_signalLength,0,0); grid->addWidget(LB_firLength,1,0); grid->addWidget(LB_spendTime,2,0); grid->addWidget(LB_maxPos,3,0); grid->addWidget(LB_status,4,0); grid->addWidget(LB_signalLength_value,0,1); grid->addWidget(LB_firLength_value,1,1); grid->addWidget(LB_spendTime_value,2,1); grid->addWidget(LB_maxPos_value,3,1); grid->addWidget(LB_status_value,4,1); grid->addWidget(countLabel,5,0); grid->addWidget(countLabel_value,5,1); QVBoxLayout *vLayout=new QVBoxLayout(); vLayout->addWidget(customPlot,1); vLayout->addWidget(customPlot_gas,1); //布局类 QWidget *mainW=new QWidget(this); setCentralWidget(mainW); QHBoxLayout *layout=new QHBoxLayout(mainW); layout->addWidget(groupBox,1); layout->addLayout(vLayout,5); connect(PB_quit,SIGNAL(clicked()),this,SLOT(PB_quit_clicked())); connect(PB_start,SIGNAL(clicked()),this,SLOT(PB_start_clicked())); connect(PB_stop,SIGNAL(clicked()),this,SLOT(PB_stop_clicked())); connect(modeCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(modeCombo_indexChanged(int))); //成员变量 END_LENGTH=END_100003; _mode=MODE_VALUE_1; myCom=NULL; myCom = new Posix_QextSerialPort("/dev/ttyAMA0",QextSerialBase::Polling); myCom->setBaudRate(BAUD9600); myCom->setDataBits(DATA_8); myCom->setParity(PAR_NONE); myCom->setStopBits(STOP_1); myCom->setFlowControl(FLOW_OFF); myCom->setTimeout(10); timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(readMyCom())); timer->setInterval(500); thread=new Thread(this); connect(thread,SIGNAL(checkCorrect(Msg*)),this,SLOT(spi_recvOver(Msg*))); connect(thread,SIGNAL(checkCorrect120003(Msg*)),this,SLOT(spi_recvOver120003(Msg*))); isTransing=true; thread->start(); }