From c427654dd881a9dec1ca3689522da5115f2405c2 Mon Sep 17 00:00:00 2001 From: "jinxuesong@163.com" Date: Sat, 22 Jun 2024 17:36:22 +0800 Subject: [PATCH 1/2] ready for toolbar --- mainwindow.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 16 +++++++ mainwindow.ui | 2 +- 3 files changed, 137 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 39a54bb..333a4e0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -191,7 +191,9 @@ void MainWindow::on_image_tree_currentChanged(const QModelIndex& current) //QModelIndex index = current.sibling(current.row(), 0); // 获取当前item的子节点index note:子节点只有一行的情况下 QStandardItemModel *model = (QStandardItemModel*)ui->treeView->model(); // 根据index获取当前item QModelIndex index = ui->treeView->currentIndex(); + m_nCurrentIndex = index; QStandardItem *item = model->itemFromIndex(index); + m_pCurrentItem = item; QVariant var = item->data(); if(item) @@ -375,5 +377,123 @@ void MainWindow::slotTreeMenuNew() } } } +} + +void MainWindow::on_comboBoxSerialPortName_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxSerialPortName->currentData(); + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setNPort(currentData.toInt()); + } + } +} + +void MainWindow::on_comboBoxSerialPortBaud_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxSerialPortBaud->currentData(); + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setNBaud(currentData.toInt()); + } + } +} + +void MainWindow::on_comboBoxSerialPortDataBits_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxSerialPortDataBits->currentData(); + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setNDatabits(currentData.toInt()); + } + } +} + +void MainWindow::on_comboBoxSerialPortParity_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxSerialPortParity->currentData(); + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setNParity(currentData.toInt()); + } + } +} + +void MainWindow::on_comboBoxSerialPortStopBits_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxSerialPortStopBits->currentData(); + + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setNStopbits(currentData.toInt()); + } + } } + +void MainWindow::on_lineEditRS232DeviceID_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("RS232")){ + RS232 *pRS232 = var.value(); + pRS232->setStrID(ui->lineEditRS232DeviceID->text()); + } + } +} + +void MainWindow::on_lineEditEthernetID_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("Ethernet")){ + Ethernet* pEthernet = var.value(); + pEthernet->setStrID(ui->lineEditEthernetID->text()); + } + } +} + diff --git a/mainwindow.h b/mainwindow.h index 0f34308..ee8d9de 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,6 +37,8 @@ private: Description m_description; QString m_strXMLFilename; + QStandardItem *m_pCurrentItem; + QModelIndex m_nCurrentIndex; private slots: void OpenXMLFile(); @@ -45,6 +47,20 @@ private slots: void slotActionTriggered(const QPoint& pos); void slotTreeMenuNew(); + void on_comboBoxSerialPortName_currentIndexChanged(int index); + + void on_comboBoxSerialPortBaud_currentIndexChanged(int index); + + void on_comboBoxSerialPortDataBits_currentIndexChanged(int index); + + void on_comboBoxSerialPortParity_currentIndexChanged(int index); + + void on_comboBoxSerialPortStopBits_currentIndexChanged(int index); + + void on_lineEditRS232DeviceID_editingFinished(); + + void on_lineEditEthernetID_editingFinished(); + private: void insterTreeNode(QString str,QStandardItem *parent); void InitTreeView(); diff --git a/mainwindow.ui b/mainwindow.ui index 2c3b49a..b70b753 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -315,7 +315,7 @@ 0 0 800 - 21 + 25 -- Gitee From 9a4b33e157158f6128f454d3151edc27e19941b7 Mon Sep 17 00:00:00 2001 From: "jinxuesong@163.com" Date: Sat, 22 Jun 2024 22:19:54 +0800 Subject: [PATCH 2/2] finish! --- delay.cpp | 1 + ethernet.cpp | 6 +- mainwindow.cpp | 298 +++++++++++++++++++++++++++++++++++++++-- mainwindow.h | 35 +++++ mainwindow.ui | 9 +- newoperationdialog.cpp | 6 + newoperationdialog.h | 3 + rs232.cpp | 14 +- snap.cpp | 1 + step.cpp | 1 + wordopcontrolled.cpp | 32 ++++- wordopcontrolled.h | 2 +- 12 files changed, 383 insertions(+), 25 deletions(-) diff --git a/delay.cpp b/delay.cpp index 7f738a4..f444321 100644 --- a/delay.cpp +++ b/delay.cpp @@ -3,6 +3,7 @@ Delay::Delay(QObject *parent) : Operation{parent} + ,m_nDuration(0) {} void Delay::run() diff --git a/ethernet.cpp b/ethernet.cpp index fa7da68..d38989c 100644 --- a/ethernet.cpp +++ b/ethernet.cpp @@ -2,7 +2,11 @@ Ethernet::Ethernet(QObject *parent) : Device{parent} -{} + , m_strIP("192.168.1.1") + , m_nPort(1000) +{ + +} QString Ethernet::strIP() const { diff --git a/mainwindow.cpp b/mainwindow.cpp index 333a4e0..268e182 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,9 +9,17 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + // 创建工具栏 + m_pToolBar = new QToolBar(this); + m_pToolBar->addAction(ui->actionOpenFile); + m_pToolBar->addAction(ui->actionSaveFile); + // 添加工具栏到主界面。 + this->addToolBar(m_pToolBar); + connect(ui->actionOpenFile,&QAction::triggered,this,&MainWindow::OpenXMLFile); connect(ui->actionSaveFile,&QAction::triggered,this,&MainWindow::SaveXMLFile); + connect(ui->actionRun,&QAction::triggered,this,&MainWindow::RunXMLFile); // 槽函数连接 connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::on_image_tree_currentChanged); @@ -109,8 +117,6 @@ void MainWindow::OpenXMLFile(){ m_description.clear(); m_description.ReadXML(fileName); InitTreeView(); - m_description.run(); - } else { m_strXMLFilename = ""; m_labelInformation->setText(QStringLiteral("No Selected File!")); @@ -121,6 +127,10 @@ void MainWindow::SaveXMLFile(){ m_description.writeXML(m_strXMLFilename); } +void MainWindow::RunXMLFile(){ + m_description.run(); +} + void MainWindow::insterTreeNode(QString str,QStandardItem *parent) { QStandardItem *item = new QStandardItem; @@ -337,9 +347,6 @@ void MainWindow::slotActionTriggered(const QPoint& pos) //删除右键 void MainWindow::slotTreeMenuNew() { - //QModelIndexList selectedIndex = ui->treeView->selectionModel()->selectedIndexes(); - //QModelIndex index = selectedIndex.first(); - //m_pTreeStandardModel->removeRow(index.row(),index.parent()); QVariant var; QStandardItemModel *model = (QStandardItemModel*)ui->treeView->model(); // 根据index获取当前item if(model != NULL){ @@ -356,6 +363,7 @@ void MainWindow::slotTreeMenuNew() var.setValue(QVariant::fromValue(pDevice)); itemDevice->setData(var); item->appendRow(itemDevice); + m_description.AddDevice(pDevice); } }else if(tagName == QStringLiteral("Steps")){ QStandardItem* itemStep = new QStandardItem; @@ -364,16 +372,20 @@ void MainWindow::slotTreeMenuNew() var.setValue(QVariant::fromValue(pStep)); itemStep->setData(var); item->appendRow(itemStep); + m_description.AddStep(pStep); }else if(tagName == QStringLiteral("Step")){ NewOperationDialog* pDialog = new NewOperationDialog(this); int result = pDialog->exec(); - if(result==QDialog::Accepted){ + if(result == QDialog::Accepted){ QStandardItem* itemOperation = new QStandardItem; itemOperation->setText(pDialog->m_strOperationName); - Device* pDevice = (Device*)ObjectFactory::createObject(pDialog->m_strOperationName.toLatin1()); - var.setValue(QVariant::fromValue(pDevice)); + Operation* pOperation = (Operation*)ObjectFactory::createObject(pDialog->m_strOperationName.toLatin1()); + var.setValue(QVariant::fromValue(pOperation)); itemOperation->setData(var); item->appendRow(itemOperation); + QVariant var = m_pCurrentItem->data(); + Step* pStep = var.value(); + pStep->AddOperation(pOperation); } } } @@ -486,9 +498,8 @@ void MainWindow::on_lineEditEthernetID_editingFinished() QVariant var = m_pCurrentItem->data(); if(m_pCurrentItem) { - // 处理代码 - int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 - QString text = m_pCurrentItem->text(); // 获取item的文本 + int indexCurrentItem = m_nCurrentIndex.row() ; + QString text = m_pCurrentItem->text(); if(text == QStringLiteral("Ethernet")){ Ethernet* pEthernet = var.value(); @@ -497,3 +508,268 @@ void MainWindow::on_lineEditEthernetID_editingFinished() } } +void MainWindow::on_lineEditEthernetIP_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + int indexCurrentItem = m_nCurrentIndex.row() ; + QString text = m_pCurrentItem->text(); + + if(text == QStringLiteral("Ethernet")){ + Ethernet* pEthernet = var.value(); + pEthernet->setStrIP(ui->lineEditEthernetIP->text()); + } + } +} + +void MainWindow::on_lineEditEthernetPort_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + int indexCurrentItem = m_nCurrentIndex.row() ; + QString text = m_pCurrentItem->text(); + + if(text == QStringLiteral("Ethernet")){ + Ethernet* pEthernet = var.value(); + pEthernet->setNPort(ui->lineEditEthernetPort->text().toInt()); + } + } +} + +void MainWindow::on_lineEditDuration_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + int indexCurrentItem = m_nCurrentIndex.row() ; + QString text = m_pCurrentItem->text(); + + if(text == QStringLiteral("Delay")){ + Delay* pDelay = var.value(); + pDelay->setNDuration(ui->lineEditDuration->text().toInt()); + } + } +} + + +void MainWindow::on_comboBoxCameras_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxCameras->currentData(); + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("Snap")){ + Snap *pSnap = var.value(); + pSnap->setNCameraNum(currentData.toInt()); + } + } +} + + +void MainWindow::on_lineEditCameraDeviceID_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("Snap")){ + Snap *pSnap = var.value(); + pSnap->setStrDeviceID(ui->lineEditCameraDeviceID->text()); + } + } +} + + +void MainWindow::on_comboBoxLEDChannel_currentIndexChanged(int index) +{ + QVariant currentData = ui->comboBoxLEDChannel->currentData(); + + if(m_pCurrentItem) + { + QVariant var = m_pCurrentItem->data(); + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("WordopControlLED")){ + WordopControlLED *pWordopControlLED = var.value(); + pWordopControlLED->setNChannel(currentData.toInt()); + } + } +} + + +void MainWindow::on_lineEditLEDValue_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("WordopControlLED")){ + WordopControlLED *pWordopControlLED = var.value(); + pWordopControlLED->setNValue(ui->lineEditLEDValue->text().toInt()); + } + } +} + + +void MainWindow::on_lineEditWordopControlLEDDeviceID_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("WordopControlLED")){ + WordopControlLED *pWordopControlLED = var.value(); + pWordopControlLED->setStrDeviceID(ui->lineEditWordopControlLEDDeviceID->text()); + } + } +} + + +void MainWindow::on_lineEditMoveJoint1_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[0] = ui->lineEditMoveJoint1->text().toDouble(); + } + } +} + + +void MainWindow::on_lineEditMoveJoint2_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[1] = ui->lineEditMoveJoint2->text().toDouble(); + } + } +} + + +void MainWindow::on_lineEditMoveJoint3_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[2] = ui->lineEditMoveJoint3->text().toDouble(); + } + } +} + + +void MainWindow::on_lineEditMoveJoint4_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[3] = ui->lineEditMoveJoint4->text().toDouble(); + } + } +} + +void MainWindow::on_lineEditMoveJoint5_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[4] = ui->lineEditMoveJoint5->text().toDouble(); + } + } +} + +void MainWindow::on_lineEditMoveJoint6_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->dblJointAngles()[5] = ui->lineEditMoveJoint6->text().toDouble(); + } + } +} + +void MainWindow::on_lineEditMoveJointDeviceID_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("MoveJoint")){ + MoveJoint *pMoveJoint = var.value(); + pMoveJoint->setStrDeviceID(ui->lineEditMoveJointDeviceID->text()); + } + } +} + +void MainWindow::on_lineEditStep_editingFinished() +{ + QVariant var = m_pCurrentItem->data(); + if(m_pCurrentItem) + { + // 处理代码 + int indexCurrentItem = m_nCurrentIndex.row() ; // 获取item的行号 + QString text = m_pCurrentItem->text(); // 获取item的文本 + + if(text == QStringLiteral("Step")){ + Step *pStep = var.value(); + pStep->setStrID(ui->lineEditStep->text()); + } + } +} + diff --git a/mainwindow.h b/mainwindow.h index ee8d9de..5508492 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "description.h" #include "rs232.h" #include "ethernet.h" @@ -33,6 +34,7 @@ public: ~MainWindow(); private: + QToolBar *m_pToolBar{nullptr}; QLabel *m_labelInformation; Description m_description; @@ -43,6 +45,7 @@ private: private slots: void OpenXMLFile(); void SaveXMLFile(); + void RunXMLFile(); void on_image_tree_currentChanged(const QModelIndex& current); void slotActionTriggered(const QPoint& pos); void slotTreeMenuNew(); @@ -61,6 +64,38 @@ private slots: void on_lineEditEthernetID_editingFinished(); + void on_lineEditEthernetIP_editingFinished(); + + void on_lineEditEthernetPort_editingFinished(); + + void on_lineEditDuration_editingFinished(); + + void on_comboBoxCameras_currentIndexChanged(int index); + + void on_lineEditCameraDeviceID_editingFinished(); + + void on_comboBoxLEDChannel_currentIndexChanged(int index); + + void on_lineEditLEDValue_editingFinished(); + + void on_lineEditWordopControlLEDDeviceID_editingFinished(); + + void on_lineEditMoveJoint1_editingFinished(); + + void on_lineEditMoveJoint2_editingFinished(); + + void on_lineEditMoveJoint3_editingFinished(); + + void on_lineEditMoveJoint4_editingFinished(); + + void on_lineEditMoveJoint5_editingFinished(); + + void on_lineEditMoveJoint6_editingFinished(); + + void on_lineEditMoveJointDeviceID_editingFinished(); + + void on_lineEditStep_editingFinished(); + private: void insterTreeNode(QString str,QStandardItem *parent); void InitTreeView(); diff --git a/mainwindow.ui b/mainwindow.ui index b70b753..efdea17 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -31,7 +31,7 @@ - 0 + 7 @@ -324,6 +324,8 @@ + + @@ -344,6 +346,11 @@ Save + + + Run + + diff --git a/newoperationdialog.cpp b/newoperationdialog.cpp index ef02bf8..8d11109 100644 --- a/newoperationdialog.cpp +++ b/newoperationdialog.cpp @@ -24,3 +24,9 @@ void NewOperationDialog::InitOperationName(){ m_strOperationName = QStringLiteral("Delay"); } + +void NewOperationDialog::on_comboBoxOperationName_currentIndexChanged(int index) +{ + m_strOperationName = ui->comboBoxOperationName->currentText(); +} + diff --git a/newoperationdialog.h b/newoperationdialog.h index 8f6d305..cfebd3a 100644 --- a/newoperationdialog.h +++ b/newoperationdialog.h @@ -21,6 +21,9 @@ private: public: QString m_strOperationName; +private slots: + void on_comboBoxOperationName_currentIndexChanged(int index); + private: void InitOperationName(); }; diff --git a/rs232.cpp b/rs232.cpp index 2c50c4d..264464b 100644 --- a/rs232.cpp +++ b/rs232.cpp @@ -3,10 +3,14 @@ static constexpr std::chrono::seconds kWriteTimeout = std::chrono::seconds{5}; RS232::RS232(QObject *parent) - : Device{parent}, - m_timer(new QTimer(this)), - //! [1] - m_serial(new QSerialPort(this)) + : Device{parent} + , m_nPort(1) + , m_nBaud(9600) + , m_nParity(0) + , m_nDatabits(8) + , m_nStopbits(1) + , m_timer(new QTimer(this)) + , m_serial(new QSerialPort(this)) { connect(m_serial, &QSerialPort::errorOccurred, this, &RS232::handleError); connect(m_timer, &QTimer::timeout, this, &RS232::handleWriteTimeout); @@ -123,7 +127,7 @@ void RS232::openSerialPort() m_serial->setParity(QSerialPort::NoParity); m_serial->setStopBits(QSerialPort::OneStop); m_serial->setFlowControl(QSerialPort::NoFlowControl);*/ - m_serial->setPortName("COM4"); + m_serial->setPortName("COM1"); m_serial->setBaudRate(9600); m_serial->setDataBits(QSerialPort::Data8); m_serial->setParity(QSerialPort::NoParity); diff --git a/snap.cpp b/snap.cpp index a6bcbb8..f6efd7a 100644 --- a/snap.cpp +++ b/snap.cpp @@ -2,6 +2,7 @@ Snap::Snap(QObject *parent) : Operation{parent} + , m_nCameraNum(1) {} int Snap::nCameraNum() const diff --git a/step.cpp b/step.cpp index 9242238..dea3f26 100644 --- a/step.cpp +++ b/step.cpp @@ -3,6 +3,7 @@ Step::Step(QObject *parent) : QObject{parent} , m_pParent(parent) + , m_strID("-1") {} QList Step::pOperations() const diff --git a/wordopcontrolled.cpp b/wordopcontrolled.cpp index 829e5d4..cff2d08 100644 --- a/wordopcontrolled.cpp +++ b/wordopcontrolled.cpp @@ -4,7 +4,11 @@ WordopControlLED::WordopControlLED(QObject *parent) : Operation{parent} , m_pDescription((Description*)parent) -{} + , m_nChannel(0) + , m_nValue(100) +{ + +} int WordopControlLED::nChannel() const { @@ -26,7 +30,7 @@ void WordopControlLED::setNValue(int newNValue) m_nValue = newNValue; } -void WordopControlLED::ReadCMD(){ +void WordopControlLED::PrepareCMD(){ m_nWordopCMD.identifier = 0x40; m_nWordopCMD.len = 0x05; m_nWordopCMD.code = 0x01; @@ -69,7 +73,22 @@ void WordopControlLED::ChkSum(WORDOPCMD& wordopcmd){ QByteArray WordopControlLED::ConvertCMD2Bytes(WORDOPCMD& wordopcmd){ QByteArray bytes; - + bytes.append(wordopcmd.identifier); + bytes.append(wordopcmd.len); + bytes.append(wordopcmd.code); + bytes.append(wordopcmd.id); + bytes.append(wordopcmd.wordopSubCmd.cmd); + bytes.append(wordopcmd.wordopSubCmd.channel); + bytes.append(wordopcmd.wordopSubCmd.data); + if(wordopcmd.pWordopSubCmds != NULL){ + int count = sizeof(wordopcmd.pWordopSubCmds) / sizeof(WORDOPSUBCMD); + for(int i = 0;i < count;i++){ + bytes.append(wordopcmd.pWordopSubCmds[i].cmd); + bytes.append(wordopcmd.pWordopSubCmds[i].channel); + bytes.append(wordopcmd.pWordopSubCmds[i].data); + } + } + bytes.append(wordopcmd.chksum); return bytes; } @@ -80,8 +99,9 @@ void WordopControlLED::run(){ Device* pDevice = m_pDescription->FindDeviceById(m_strDeviceID); QString message = QString("ControlLED : channel = %1 and value = %2.").arg(m_nChannel).arg(m_nValue); - //pDevice->writeData(ConvertCMD2Bytes(m_nWordopCMD)); - pDevice->writeData(message.toLatin1()); + PrepareCMD(); + pDevice->writeData(ConvertCMD2Bytes(m_nWordopCMD)); + //pDevice->writeData(message.toLatin1()); } QString WordopControlLED::getClassName(){ @@ -90,7 +110,7 @@ QString WordopControlLED::getClassName(){ void WordopControlLED::writeXML(QXmlStreamWriter& writer){ // 鍐欏叆褰撳墠鎿嶄綔鐨勪俊鎭 - writer.writeStartElement("ControlLED"); + writer.writeStartElement("WordopControlLED"); writer.writeAttribute("device", m_strDeviceID); writer.writeTextElement("channel", QString::number(m_nChannel)); writer.writeTextElement("value", QString::number(m_nValue)); diff --git a/wordopcontrolled.h b/wordopcontrolled.h index 958b237..f173a18 100644 --- a/wordopcontrolled.h +++ b/wordopcontrolled.h @@ -48,7 +48,7 @@ private: private: QByteArray ConvertCMD2Bytes(WORDOPCMD& wordopcmd); - void ReadCMD(); + void PrepareCMD(); void ChkSum(WORDOPCMD& wordopcmd); public: -- Gitee