diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/common/common.pri b/common/common.pri index 81ad04d..a7c8280 100644 --- a/common/common.pri +++ b/common/common.pri @@ -3,8 +3,10 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QLogUtil.h HEADERS += $$PWD/utils/UDPClientUtil.h +HEADERS += $$PWD/utils/QSerialPortUtil.h SOURCES += $$PWD/utils/SettingConfig.cpp SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp SOURCES += $$PWD/utils/UDPClientUtil.cpp +SOURCES += $$PWD/utils/QSerialPortUtil.cpp diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/common/common.pri b/common/common.pri index 81ad04d..a7c8280 100644 --- a/common/common.pri +++ b/common/common.pri @@ -3,8 +3,10 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QLogUtil.h HEADERS += $$PWD/utils/UDPClientUtil.h +HEADERS += $$PWD/utils/QSerialPortUtil.h SOURCES += $$PWD/utils/SettingConfig.cpp SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp SOURCES += $$PWD/utils/UDPClientUtil.cpp +SOURCES += $$PWD/utils/QSerialPortUtil.cpp diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 64da0f7..4285566 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,5 +1,6 @@ #include "QSerialPortUtil.h" +#include #include #include #include @@ -20,17 +21,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); + qDebug() << open; if (open == true) { // 绑定信号与槽 - connect(&serial, &QSerialPort::readyRead, - this, &QSerialPortUtil::readData); + connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); // mock data received per second // QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &QSerialPortUtil::mockReceivData); +// connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } } diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/common/common.pri b/common/common.pri index 81ad04d..a7c8280 100644 --- a/common/common.pri +++ b/common/common.pri @@ -3,8 +3,10 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QLogUtil.h HEADERS += $$PWD/utils/UDPClientUtil.h +HEADERS += $$PWD/utils/QSerialPortUtil.h SOURCES += $$PWD/utils/SettingConfig.cpp SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp SOURCES += $$PWD/utils/UDPClientUtil.cpp +SOURCES += $$PWD/utils/QSerialPortUtil.cpp diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 64da0f7..4285566 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,5 +1,6 @@ #include "QSerialPortUtil.h" +#include #include #include #include @@ -20,17 +21,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); + qDebug() << open; if (open == true) { // 绑定信号与槽 - connect(&serial, &QSerialPort::readyRead, - this, &QSerialPortUtil::readData); + connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); // mock data received per second // QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &QSerialPortUtil::mockReceivData); +// connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } } diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index f71cd39..6170e0f 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,11 +18,14 @@ } void SettingConfig::init() { -// NET_TYPE = getProperty("net", "type").toString(); + NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); + PORT_NAME = getProperty("com", "portName").toString(); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/common/common.pri b/common/common.pri index 81ad04d..a7c8280 100644 --- a/common/common.pri +++ b/common/common.pri @@ -3,8 +3,10 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QLogUtil.h HEADERS += $$PWD/utils/UDPClientUtil.h +HEADERS += $$PWD/utils/QSerialPortUtil.h SOURCES += $$PWD/utils/SettingConfig.cpp SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp SOURCES += $$PWD/utils/UDPClientUtil.cpp +SOURCES += $$PWD/utils/QSerialPortUtil.cpp diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 64da0f7..4285566 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,5 +1,6 @@ #include "QSerialPortUtil.h" +#include #include #include #include @@ -20,17 +21,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); + qDebug() << open; if (open == true) { // 绑定信号与槽 - connect(&serial, &QSerialPort::readyRead, - this, &QSerialPortUtil::readData); + connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); // mock data received per second // QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &QSerialPortUtil::mockReceivData); +// connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } } diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index f71cd39..6170e0f 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,11 +18,14 @@ } void SettingConfig::init() { -// NET_TYPE = getProperty("net", "type").toString(); + NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); + PORT_NAME = getProperty("com", "portName").toString(); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index a774ba7..ab36884 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -33,6 +33,9 @@ quint16 DEVICE_PORT; quint16 LISTEN_PORT; + QString PORT_NAME; + int BAUD_RATE; + quint8 CHANNEL_COUNT; quint8 SKIP_HEADER; quint16 MAX_COUNT; diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index 52e9a2c..e2f04a5 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -17,27 +17,44 @@ PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil = new QSerialPortUtil(this); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } PhaseDevice::~PhaseDevice() { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, - this, &PhaseDevice::dataReceivedHandler); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + } } void PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - clientUtil->sendData(startCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(startCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(startCmd.toLocal8Bit()); + } + } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - clientUtil->sendData(stopCmd.toLocal8Bit()); + if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { + clientUtil->sendData(stopCmd.toLocal8Bit()); + } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + serialUtil->sendData(stopCmd.toLocal8Bit()); + } } void PhaseDevice::dataReceivedHandler(QByteArray data) diff --git a/PhaseDevice.h b/PhaseDevice.h index 0950f54..3e53fd0 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -4,6 +4,7 @@ #include #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" +#include "common/utils/QSerialPortUtil.h" #include "protocol/PhaseProtocolBM.h" #include "DataProcessAlgorithm.h" @@ -20,6 +21,7 @@ void afterFramePhase(PhaseDataDto * phaseData); private: UDPClientUtil * clientUtil; + QSerialPortUtil * serialUtil; QByteArray dataBuff; diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index d247f1b..8aa03da 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -1,4 +1,4 @@ -QT += core gui network +QT += core gui network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport @@ -42,4 +42,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -RC_ICONS = PhaseMeasure.ico +#RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 99a2108..b238709 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -108,8 +108,7 @@ void PhaseWindow::initDeivce() { device = new PhaseDevice(this); - connect(device, &PhaseDevice::sendDataToDraw, - this, &PhaseWindow::drawPhaseDataOnPage); + connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData) diff --git a/common/common.pri b/common/common.pri index 81ad04d..a7c8280 100644 --- a/common/common.pri +++ b/common/common.pri @@ -3,8 +3,10 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QLogUtil.h HEADERS += $$PWD/utils/UDPClientUtil.h +HEADERS += $$PWD/utils/QSerialPortUtil.h SOURCES += $$PWD/utils/SettingConfig.cpp SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp SOURCES += $$PWD/utils/UDPClientUtil.cpp +SOURCES += $$PWD/utils/QSerialPortUtil.cpp diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 64da0f7..4285566 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,5 +1,6 @@ #include "QSerialPortUtil.h" +#include #include #include #include @@ -20,17 +21,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); + qDebug() << open; if (open == true) { // 绑定信号与槽 - connect(&serial, &QSerialPort::readyRead, - this, &QSerialPortUtil::readData); + connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); // mock data received per second // QTimer * timer = new QTimer(this); -// connect(timer, &QTimer::timeout, -// this, &QSerialPortUtil::mockReceivData); +// connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } } diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index f71cd39..6170e0f 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,11 +18,14 @@ } void SettingConfig::init() { -// NET_TYPE = getProperty("net", "type").toString(); + NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); + PORT_NAME = getProperty("com", "portName").toString(); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index a774ba7..ab36884 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -33,6 +33,9 @@ quint16 DEVICE_PORT; quint16 LISTEN_PORT; + QString PORT_NAME; + int BAUD_RATE; + quint8 CHANNEL_COUNT; quint8 SKIP_HEADER; quint16 MAX_COUNT; diff --git a/conf/config.ini b/conf/config.ini index c6be4d2..377091c 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,8 +1,13 @@ [net] +type="serial" deviceHost="192.168.1.20" devicePort=233 listenPort=243 +[com] +portName="COM1" +baudRate=115200 + [dev] channelCount=16 skipHeader=5