diff --git a/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.cpp b/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.cpp new file mode 100644 index 0000000..f98d38e --- /dev/null +++ b/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.cpp @@ -0,0 +1,68 @@ +#include "BCIManager.h" +#include +#include +#include + +BCIManager::BCIManager(QObject *parent) + : QObject{parent} +{ + + +} + +bool BCIManager::startLinkerPrograme() +{ + QString strPath = QApplication::applicationDirPath().append("/cmd.txt"); + + QFile file(strPath); + if (!file.open(QIODevice::ReadOnly)) + { + qDebug() << file.errorString(); + return false; + } + QString strContent; + QTextStream in(&file); + while (!in.atEnd()) + { + strContent = in.readLine(); + if(!strContent.isEmpty()) + { + break; + } + } + if(strContent.isEmpty()) + { + qDebug() << "cmd is empty"; + return false; + } + + //启动进程 + //QString strCmd = QApplication::applicationDirPath().append("/BCILinker/SunnyLinkTool/") + strContent; + + QString strCmd = QString("./") + strContent; + + qDebug() << strCmd; + if(nullptr == m_pCmd) + { + m_pCmd = new QProcess(this); + connect(m_pCmd, &QProcess::readyReadStandardOutput, this, &BCIManager::slotLinkerProgrameReadyReadStandardOutput); + connect(m_pCmd, &QProcess::readyReadStandardError, this, &BCIManager::slotLinkerProgrameReadyReadStandardError); + } + m_pCmd->start(strCmd); +} + +void BCIManager::slotLinkerProgrameReadyReadStandardOutput() +{ + if(m_pCmd) + { + qDebug() << m_pCmd->readAllStandardOutput(); + } +} + +void BCIManager::slotLinkerProgrameReadyReadStandardError() +{ + if(m_pCmd) + { + qDebug() << m_pCmd->readAllStandardError(); + } +} diff --git a/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.h b/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.h new file mode 100644 index 0000000..6d7e3e1 --- /dev/null +++ b/ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.h @@ -0,0 +1,40 @@ +#ifndef BCIMANAGER_H +#define BCIMANAGER_H + +#include +#include +#include "QmlTcpSocket/TcpSocket.h" + +class BCIManager : public QObject +{ + Q_OBJECT +public: + explicit BCIManager(QObject *parent = nullptr); + + static BCIManager &getInstance() + { + static BCIManager instance; + return instance; + } + + static void registerQMLType() + { + qmlRegisterType("TcpSocket", 2, 0, "TcpSocket"); + } + //启动Linker工具 + bool startLinkerPrograme(); + +private slots: + //Linker程序的标准输出 + void slotLinkerProgrameReadyReadStandardOutput(); + //Linker程序的错误输出 + void slotLinkerProgrameReadyReadStandardError(); + +signals: + + +private: + QProcess *m_pCmd = nullptr; +}; + +#endif // BCIMANAGER_H