|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
#include "VisionController.h"
|
|
|
|
|
|
|
|
|
|
QString absolutePath = "\\..\\runner17\\config\\";
|
|
|
|
|
VisionController::VisionController(QWidget *parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
{
|
|
|
|
|
@ -36,22 +37,40 @@ VisionController::VisionController(QWidget *parent)
|
|
|
|
|
connect(m_tcpServerPtr, &TcpServer::sgReceived, this, &VisionController::receivedData);
|
|
|
|
|
connect(m_tcpServerPtr, &TcpServer::sgDisconnected, this, &VisionController::onDisconnected);
|
|
|
|
|
m_ioControllerPtr = new IOController();
|
|
|
|
|
unsigned int serialNum = 2;
|
|
|
|
|
if (!m_ioControllerPtr->controllerInitialization(serialNum))
|
|
|
|
|
unsigned int comlNum=0;
|
|
|
|
|
if (!readComSetting(path, comlNum))
|
|
|
|
|
{
|
|
|
|
|
QString showMsg = QString("串口Com%1初始化失败").arg(serialNum);
|
|
|
|
|
QString showMsg = QString("未能读取到Com配置文件");
|
|
|
|
|
ui.textLog->appendPlainText(showMsg);
|
|
|
|
|
}
|
|
|
|
|
if (!m_ioControllerPtr->controllerInitialization(comlNum))
|
|
|
|
|
{
|
|
|
|
|
QString showMsg = QString("串口Com%1初始化失败").arg(comlNum);
|
|
|
|
|
ui.textLog->appendPlainText(showMsg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString showMsg = QString("串口Com%1初始化成功").arg(serialNum);
|
|
|
|
|
QString showMsg = QString("串口Com%1初始化成功").arg(comlNum);
|
|
|
|
|
ui.textLog->appendPlainText(showMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VisionController::~VisionController()
|
|
|
|
|
{
|
|
|
|
|
if (m_ioControllerPtr)
|
|
|
|
|
{
|
|
|
|
|
delete m_ioControllerPtr;
|
|
|
|
|
//m_ioControllerPtr = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_tcpServerPtr)
|
|
|
|
|
{
|
|
|
|
|
delete m_tcpServerPtr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool VisionController::readServerConfig(QString path, QString& serverIP, quint16& port)
|
|
|
|
|
{
|
|
|
|
|
QString filePath = path + "\\..\\config\\tcpServer.json";
|
|
|
|
|
//QString filePath = path + "\\..\\config\\tcpServer.json";
|
|
|
|
|
QString filePath = path + absolutePath + "tcpServer.json";
|
|
|
|
|
QFile jsonFile(filePath);
|
|
|
|
|
if (!jsonFile.exists())
|
|
|
|
|
{
|
|
|
|
|
@ -82,7 +101,8 @@ bool VisionController::readServerConfig(QString path, QString& serverIP, quint16
|
|
|
|
|
}
|
|
|
|
|
bool VisionController::writeServerConfig(QString path, QString serverIP, quint16 serverPort)
|
|
|
|
|
{
|
|
|
|
|
QString filePath = path + "\\..\\config\\tcpServer.json";
|
|
|
|
|
//QString filePath = path + "\\..\\config\\tcpServer.json";
|
|
|
|
|
QString filePath = path + absolutePath + "tcpServer.json";
|
|
|
|
|
QFile jsonFile(filePath);
|
|
|
|
|
if (!jsonFile.open(QIODevice::WriteOnly))
|
|
|
|
|
{
|
|
|
|
|
@ -100,20 +120,35 @@ bool VisionController::writeServerConfig(QString path, QString serverIP, quint16
|
|
|
|
|
jsonFile.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
VisionController::~VisionController()
|
|
|
|
|
bool VisionController::readComSetting(QString path, unsigned int& comNum)
|
|
|
|
|
{
|
|
|
|
|
if (m_ioControllerPtr)
|
|
|
|
|
QString filePath = path + absolutePath + "comSetting.json";
|
|
|
|
|
QFile comSettingFile(filePath);
|
|
|
|
|
if (!comSettingFile.exists())
|
|
|
|
|
{
|
|
|
|
|
delete m_ioControllerPtr;
|
|
|
|
|
//m_ioControllerPtr = nullptr;
|
|
|
|
|
qDebug() << "文件:" << filePath << "不存在!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_tcpServerPtr)
|
|
|
|
|
if (!comSettingFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
|
|
{
|
|
|
|
|
delete m_tcpServerPtr;
|
|
|
|
|
qDebug() << "文件:" << filePath << "打开失败!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QByteArray dataArray = comSettingFile.readAll();
|
|
|
|
|
comSettingFile.close();
|
|
|
|
|
QJsonParseError jsonError;
|
|
|
|
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(dataArray, &jsonError);
|
|
|
|
|
if (jsonError.error != QJsonParseError::NoError)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "文件:" << filePath << "格式错误!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QJsonObject jsonObject = jsonDocument.object();
|
|
|
|
|
comNum = jsonObject.value("Com").toInt();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void VisionController::onButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
QString strObj = sender()->objectName();
|
|
|
|
|
|