11/26
This commit is contained in:
parent
2ea5d0b7eb
commit
caa9a4f9df
68
ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.cpp
Normal file
68
ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "BCIManager.h"
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
40
ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.h
Normal file
40
ZBD_IIIDL_S_Project/Src/TrainManager/BCIManager.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef BCIMANAGER_H
|
||||
#define BCIMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#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<QMLTcpSockets::TcpSocket>("TcpSocket", 2, 0, "TcpSocket");
|
||||
}
|
||||
//启动Linker工具
|
||||
bool startLinkerPrograme();
|
||||
|
||||
private slots:
|
||||
//Linker程序的标准输出
|
||||
void slotLinkerProgrameReadyReadStandardOutput();
|
||||
//Linker程序的错误输出
|
||||
void slotLinkerProgrameReadyReadStandardError();
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
private:
|
||||
QProcess *m_pCmd = nullptr;
|
||||
};
|
||||
|
||||
#endif // BCIMANAGER_H
|
Loading…
x
Reference in New Issue
Block a user