bool ReceiveData::serialPortConnect() { serialPort->setPortName(SerialPortSettingModel::getInstance()->getPortName()); qDebug() << serialPort->portName(); serialPort->setBaudRate(SerialPortSettingModel::getInstance()->getBaudRate()); qDebug() << serialPort->baudRate(); serialPort->setDataBits(QSerialPort::Data8); serialPort->setParity(QSerialPort::NoParity); serialPort->setStopBits(QSerialPort::OneStop); serialPort->setFlowControl(QSerialPort::NoFlowControl); if(serialPort->open(QIODevice::ReadWrite)) { connect(serialPort, SIGNAL(readyRead()), this, SLOT(serialReceived())); qDebug() << "Opened"; return true; } else { return false; qDebug() << "Could not open"; } }
/*----------------------------------------------------------------------------*/ MeasureWindow::MeasureWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MeasureWindow) { m_created = false; ui->setupUi(this); ui->profileCombo->addItems(config->profileList()); ui->profileCombo->setCurrentIndex(config->profileIndex()); m_created = true; m_newMeasure = true; onProfileChanged(config->profileIndex()); connect(database, SIGNAL(dbError(QString)), this, SLOT(onDatabaseError())); connect(controller, SIGNAL(cmdSendError()), this, SLOT(onCmdSendError())); connect(controller, SIGNAL(cmdSendOk()), this, SLOT(onCmdSendOk())); connect(controller, SIGNAL(currentStretch(double)), this, SLOT(onCurrentStretch(double))); connect(controller, SIGNAL(endOfMeasuring()), this, SLOT(onEndOfMeasuring())); connect(controller, SIGNAL(measure(double,double,int)), this, SLOT(onMeasure(double,double,int))); connect(controller, SIGNAL(nextCasseteRequest()), this, SLOT(onNextCasseteRequest())); connect(controller, SIGNAL(noParticle()), this, SLOT(onNoParticle())); connect(controller, SIGNAL(serialReceived(QString)), this, SLOT(onSerialReceived(QString))); connect(controller, SIGNAL(statusChanged(int)), this, SLOT(onStatusChanged(int))); connect(controller, SIGNAL(sizeReceived(double)), this, SLOT(onSizeReceived(double))); connect(session, SIGNAL(sessionChanged()), this, SLOT(onSessionChanged())); connect(session, SIGNAL(measureListChanged()), this, SLOT(onMeasureListChanged())); ui->sessionBox->setSession(session); measureModel = new MeasureModel(this); ui->measureTable->setModel(measureModel); //connect(session, SIGNAL(measureListChanged()), measureModel, SLOT(update())); histogrammPlotter = new HistogrammPlotter(); // ui->currentHPlotWidget->setPlotter(histogrammPlotter); curvePlotter = new CurvePlotter(); curvePlotter->x.setShowValues(false); curvePlotter->x.setText(tr("[s]")); curvePlotter->x.setDecimals(0); curvePlotter->x.setSteps(3); curvePlotter->x.setMax(3000); curvePlotter->y.setShowValues(true); curvePlotter->y.setText(tr("[N]")); curvePlotter->y.setDecimals(1); curvePlotter->setFiled(false); curvePlotter->setPointSize(4); curvePlotter->setStyle(AxisPlotter::StrokeStyle); ui->currentValuePlotWidget->setPlotter(curvePlotter); intervalCount = 6; controller->start(); }
WindowUSART::WindowUSART(QWidget *parent) : QMainWindow(parent), ui(new Ui::WindowUSART) { ui->setupUi(this); serial = new QSerialPort(this); serial->setPortName("ttyUSB0"); serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::TwoStop); serial->setFlowControl(QSerialPort::NoFlowControl); serial->open(QIODevice::ReadWrite); if( serial->isOpen() == false ) { ui->textBrowser->append("GOWNO"); } connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived())); palette = new QPalette(); palette->setColor(ui->Sensor1->foregroundRole(),Qt::transparent); }
QString str; foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) { str=serialPortInfo.portName(); ui->comboBox_2->addItem(str); } ui->textEdit->setText(str); serial->setPortName("COM3"); serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); serial->open(QIODevice::ReadWrite); serial->write("resp8080\n"); createMenus(); connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived())); connect(timer,SIGNAL(timeout()),this,SLOT(timeIsOut())); } MainWindow::~MainWindow() { vBox->close(); vBox2->close(); delete ui; delete vBox; delete vBox2; serial->close(); }
void ReceiveData::serialPortDisconnect() { serialPort->close(); disconnect(serialPort, SIGNAL(readyRead()), this, SLOT(serialReceived())); }
/*----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { QApplication a(argc, argv); a.addLibraryPath(a.applicationDirPath() + "/plugins"); config = new DDAConfig(&a); if(config->fileExists() && config->isError()) { QMessageBox::critical(NULL, QObject::tr("Error load config"), config->message()); } translator = new Translator(&a); QString locale; locale = config->settings().localeName; if(locale.isEmpty()) locale = QLocale::system().name(); if(!translator->load("dda-messages.xml") && !translator->load("dda-messages.xml", QDir::currentPath()) && !translator->load("dda-messages.xml", QLibraryInfo::location(QLibraryInfo::TranslationsPath)) && locale != "C") { QString error = QString("Error load language file '%1': %2").arg("dda-messages.xml").arg(translator->errorString()); QMessageBox::critical(NULL, "Error translation", error); if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = "C"; config->setSettings(s); } } else { if(!translator->setLang(locale)) { QString error = QString("Error set language: %1").arg(translator->errorString()); QMessageBox::critical(NULL, "Error translation", error); if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = "C"; config->setSettings(s); } } else if(config->settings().localeName.isEmpty()) { DDASettings s = config->settings(); s.localeName = QLocale::system().name(); config->setSettings(s); } } a.installTranslator(translator); database = new DDADatabase(&a); if(database->isError()) { QMessageBox::critical(NULL, QObject::tr("Error open database"), database->message()); } QStringList profiles = config->profileList(); /* if(profiles.size() > 1) { ProfileSelectDialog dlg; if(dlg.exec() != QDialog::Accepted || dlg.selectedProfile() < 0 || dlg.selectedProfile() > profiles.size()) return 1; config->setProfileIndex(dlg.selectedProfile()); } else */ if(profiles.isEmpty()) { DDAProfile profile; config->defaultProfle(&profile); EditProfileDialog dlg; dlg.setProfile(profile); if(dlg.exec() != QDialog::Accepted) return 1; config->addProfile(dlg.profile()); config->setProfileIndex(0); } int defaultProfile = getOptValue("profile", 'p', -1).toInt(); if(defaultProfile > 0) config->setProfileIndex(defaultProfile - 1); session = new DDAMeasureSession(&a); if(getOptSwitch("demo", 'd') || getOptSwitch("demo-mode", 'D')) controller = new DemoController(&a); else controller = new DDAController(&a); QObject::connect(controller, SIGNAL(measure(double,double,int)), session, SLOT(addMeasure(double,double,int))); QObject::connect(controller, SIGNAL(serialReceived(QString)), session, SLOT(setSerial(QString))); QObject::connect(controller, SIGNAL(endOfMeasuring()), session, SLOT(onEndOfMeasuring())); QObject::connect(controller, SIGNAL(noParticle()), session, SLOT(onNoParticle())); QObject::connect(controller, SIGNAL(measure(double,double,int)), database, SLOT(measure(double,double,int))); QObject::connect(controller, SIGNAL(serialReceived(QString)), database, SLOT(setSerial(QString))); QObject::connect(controller, SIGNAL(endOfMeasuring()), database, SLOT(onEndOfMeasuring())); QObject::connect(controller, SIGNAL(noParticle()), database, SLOT(onNoParticle())); MeasureWindow w; w.show(); //w.showMaximized(); return a.exec(); }