订单流程修改--QThread事件循环导致的逻辑修改
This commit is contained in:
Generated
+2
@@ -8,3 +8,5 @@
|
||||
/dataSources.local.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
/go.imports.xml
|
||||
/MarsCodeWorkspaceAppSettings.xml
|
||||
|
||||
+3
-2
@@ -66,7 +66,8 @@ timeoutWarningMs=8000
|
||||
stateTimeoutMs=10000
|
||||
maxRecoveryRetries=1
|
||||
simulationStepMs=500
|
||||
usePlcErrorCode=false
|
||||
|
||||
[system]
|
||||
simulation=true
|
||||
productionEnabled=false
|
||||
simulation=false
|
||||
productionEnabled=true
|
||||
|
||||
@@ -129,6 +129,9 @@ bool ConfigManager::load(const QString &filePath)
|
||||
m_productionConfig.simulationStepMs =
|
||||
settings.value("production/simulationStepMs",
|
||||
m_productionConfig.simulationStepMs).toInt();
|
||||
m_productionConfig.usePlcErrorCode =
|
||||
settings.value("production/usePlcErrorCode",
|
||||
m_productionConfig.usePlcErrorCode).toBool();
|
||||
|
||||
m_simulationMode = settings.value("system/simulation", m_simulationMode).toBool();
|
||||
m_productionEnabled = settings.value("system/productionEnabled", m_productionEnabled).toBool();
|
||||
|
||||
@@ -21,6 +21,7 @@ struct ProductionConfig
|
||||
int stateTimeoutMs = 10000;
|
||||
int maxRecoveryRetries = 1;
|
||||
int simulationStepMs = 500;
|
||||
bool usePlcErrorCode = false;
|
||||
};
|
||||
|
||||
class ConfigManager
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "config/configmanager.h"
|
||||
#include "db/databasemanager.h"
|
||||
#include "modbus/modbustcpmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
@@ -14,7 +13,6 @@ int main(int argc, char *argv[])
|
||||
ConfigManager &configManager = ConfigManager::instance();
|
||||
configManager.load();
|
||||
DatabaseManager::instance().setConfig(configManager.databaseConfig());
|
||||
ModbusTcpManager::instance().setConfig(configManager.modbusConfig());
|
||||
|
||||
QString configError;
|
||||
if (!configManager.validate(&configError)) {
|
||||
|
||||
+313
-207
@@ -1,36 +1,31 @@
|
||||
#include "modbustcpmanager.h"
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QModbusDataUnit>
|
||||
#include <QModbusReply>
|
||||
#include <QModbusTcpClient>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
|
||||
ModbusTcpManager &ModbusTcpManager::instance()
|
||||
{
|
||||
static ModbusTcpManager manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
ModbusTcpManager::ModbusTcpManager()
|
||||
: m_config(ModbusConfig::defaultConfig()),
|
||||
m_client(nullptr)
|
||||
ModbusTcpManager::ModbusTcpManager(const ModbusConfig &config,
|
||||
QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_config(config)
|
||||
, m_client(nullptr)
|
||||
, m_reply(nullptr)
|
||||
, m_connectTimer(new QTimer(this))
|
||||
, m_hasCurrentRequest(false)
|
||||
, m_connecting(false)
|
||||
, m_aborting(false)
|
||||
, m_connectAttempts(0)
|
||||
{
|
||||
m_connectTimer->setSingleShot(true);
|
||||
connect(m_connectTimer, &QTimer::timeout,
|
||||
this, &ModbusTcpManager::onConnectTimeout);
|
||||
}
|
||||
|
||||
ModbusTcpManager::~ModbusTcpManager()
|
||||
{
|
||||
disconnectDevice();
|
||||
delete m_client;
|
||||
}
|
||||
|
||||
void ModbusTcpManager::setConfig(const ModbusConfig &config)
|
||||
{
|
||||
if (isConnected()) {
|
||||
disconnectDevice();
|
||||
}
|
||||
m_config = config;
|
||||
abortAll("Modbus manager is shutting down");
|
||||
}
|
||||
|
||||
ModbusConfig ModbusTcpManager::config() const
|
||||
@@ -38,206 +33,245 @@ ModbusConfig ModbusTcpManager::config() const
|
||||
return m_config;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::connectDevice(QString *error)
|
||||
void ModbusTcpManager::readCoil(
|
||||
int address,
|
||||
const std::function<void(bool, bool, const QString &)> &callback)
|
||||
{
|
||||
ensureClient();
|
||||
if (isConnected()) {
|
||||
return true;
|
||||
enqueue({QModbusDataUnit::Coils, address, 0, false,
|
||||
[callback](bool success, quint16 value, const QString &error) {
|
||||
if (callback) {
|
||||
callback(success, value != 0, error);
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
void ModbusTcpManager::readHoldingRegister(
|
||||
int address,
|
||||
const std::function<void(bool, quint16, const QString &)> &callback)
|
||||
{
|
||||
enqueue({QModbusDataUnit::HoldingRegisters, address, 0, false, callback});
|
||||
}
|
||||
|
||||
void ModbusTcpManager::writeCoil(
|
||||
int address, bool value,
|
||||
const std::function<void(bool, const QString &)> &callback)
|
||||
{
|
||||
enqueue({QModbusDataUnit::Coils, address,
|
||||
static_cast<quint16>(value ? 1 : 0), true,
|
||||
[callback](bool success, quint16, const QString &error) {
|
||||
if (callback) {
|
||||
callback(success, error);
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
void ModbusTcpManager::writeHoldingRegister(
|
||||
int address, quint16 value,
|
||||
const std::function<void(bool, const QString &)> &callback)
|
||||
{
|
||||
enqueue({QModbusDataUnit::HoldingRegisters, address, value, true,
|
||||
[callback](bool success, quint16, const QString &error) {
|
||||
if (callback) {
|
||||
callback(success, error);
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
void ModbusTcpManager::abortAll(const QString &reason)
|
||||
{
|
||||
if (m_aborting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_client->setConnectionParameter(QModbusDevice::NetworkAddressParameter, QVariant(m_config.host));
|
||||
m_client->setConnectionParameter(QModbusDevice::NetworkPortParameter, QVariant(m_config.port));
|
||||
const QString text = reason.isEmpty()
|
||||
? "Modbus request was canceled" : reason;
|
||||
|
||||
m_aborting = true;
|
||||
m_connectTimer->stop();
|
||||
m_connecting = false;
|
||||
|
||||
if (m_reply) {
|
||||
QModbusReply *reply = m_reply;
|
||||
m_reply = nullptr;
|
||||
reply->disconnect(this);
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
if (m_hasCurrentRequest) {
|
||||
const Completion callback = m_currentRequest.callback;
|
||||
m_currentRequest = Request();
|
||||
m_hasCurrentRequest = false;
|
||||
setError(text);
|
||||
if (callback) {
|
||||
callback(false, 0, text);
|
||||
}
|
||||
}
|
||||
|
||||
while (!m_requests.isEmpty()) {
|
||||
Request request = m_requests.dequeue();
|
||||
if (request.callback) {
|
||||
request.callback(false, 0, text);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_client
|
||||
&& m_client->state() != QModbusDevice::UnconnectedState) {
|
||||
m_client->disconnectDevice();
|
||||
}
|
||||
|
||||
m_aborting = false;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::isBusy() const
|
||||
{
|
||||
return m_hasCurrentRequest || !m_requests.isEmpty()
|
||||
|| m_connecting || m_reply;
|
||||
}
|
||||
|
||||
void ModbusTcpManager::enqueue(const Request &request)
|
||||
{
|
||||
if (m_aborting) {
|
||||
if (request.callback) {
|
||||
request.callback(false, 0, "Modbus request was canceled");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.address < 0) {
|
||||
if (request.callback) {
|
||||
request.callback(false, 0,
|
||||
"Modbus address must be greater than or equal to 0");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_requests.enqueue(request);
|
||||
startNext();
|
||||
}
|
||||
|
||||
void ModbusTcpManager::startNext()
|
||||
{
|
||||
if (m_aborting || m_hasCurrentRequest || m_requests.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentRequest = m_requests.dequeue();
|
||||
m_hasCurrentRequest = true;
|
||||
m_connectAttempts = 0;
|
||||
ensureConnected();
|
||||
}
|
||||
|
||||
void ModbusTcpManager::ensureConnected()
|
||||
{
|
||||
if (m_aborting || !m_hasCurrentRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
ensureClient();
|
||||
if (m_client->state() == QModbusDevice::ConnectedState) {
|
||||
startCurrentRequest();
|
||||
return;
|
||||
}
|
||||
if (m_connecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_client->setConnectionParameter(
|
||||
QModbusDevice::NetworkAddressParameter,
|
||||
QVariant(m_config.host));
|
||||
m_client->setConnectionParameter(
|
||||
QModbusDevice::NetworkPortParameter,
|
||||
QVariant(m_config.port));
|
||||
m_client->setTimeout(m_config.timeoutMs);
|
||||
m_client->setNumberOfRetries(m_config.retryCount);
|
||||
|
||||
++m_connectAttempts;
|
||||
m_connecting = true;
|
||||
if (!m_client->connectDevice()) {
|
||||
setError(m_client->errorString(), error);
|
||||
return false;
|
||||
handleConnectionFailure(m_client->errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
|
||||
QObject::connect(m_client, &QModbusClient::stateChanged, &loop, [&](QModbusDevice::State state) {
|
||||
if (state == QModbusDevice::ConnectedState || state == QModbusDevice::UnconnectedState) {
|
||||
loop.quit();
|
||||
}
|
||||
});
|
||||
QObject::connect(m_client, &QModbusClient::errorOccurred, &loop, [&](QModbusDevice::Error) {
|
||||
loop.quit();
|
||||
});
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
timer.start(m_config.timeoutMs);
|
||||
loop.exec();
|
||||
|
||||
if (!isConnected()) {
|
||||
QString text = m_client->errorString();
|
||||
if (text.isEmpty()) {
|
||||
text = "Modbus TCP connect timeout";
|
||||
}
|
||||
setError(text, error);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lastErrorText.clear();
|
||||
return true;
|
||||
m_connectTimer->start(qMax(1, m_config.timeoutMs));
|
||||
}
|
||||
|
||||
void ModbusTcpManager::disconnectDevice()
|
||||
void ModbusTcpManager::startCurrentRequest()
|
||||
{
|
||||
if (m_client) {
|
||||
if (m_aborting || !m_hasCurrentRequest || m_connecting || m_reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
QModbusDataUnit unit(
|
||||
static_cast<QModbusDataUnit::RegisterType>(
|
||||
m_currentRequest.registerType),
|
||||
m_currentRequest.address, 1);
|
||||
if (m_currentRequest.write) {
|
||||
unit.setValue(0, m_currentRequest.value);
|
||||
m_reply = m_client->sendWriteRequest(unit, m_config.serverAddress);
|
||||
} else {
|
||||
m_reply = m_client->sendReadRequest(unit, m_config.serverAddress);
|
||||
}
|
||||
|
||||
if (!m_reply) {
|
||||
finishCurrent(false, 0,
|
||||
m_client->errorString().isEmpty()
|
||||
? "Failed to create Modbus request"
|
||||
: m_client->errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_reply, &QModbusReply::finished,
|
||||
this, &ModbusTcpManager::onReplyFinished);
|
||||
}
|
||||
|
||||
void ModbusTcpManager::finishCurrent(bool success, quint16 value,
|
||||
const QString &error)
|
||||
{
|
||||
if (!m_hasCurrentRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Completion callback = m_currentRequest.callback;
|
||||
m_currentRequest = Request();
|
||||
m_hasCurrentRequest = false;
|
||||
if (!success) {
|
||||
setError(error);
|
||||
} else {
|
||||
m_lastErrorText.clear();
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(success, value, error);
|
||||
}
|
||||
if (!m_aborting) {
|
||||
startNext();
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusTcpManager::handleConnectionFailure(const QString &error)
|
||||
{
|
||||
if (m_aborting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_connectTimer->stop();
|
||||
m_connecting = false;
|
||||
|
||||
if (m_client
|
||||
&& m_client->state() != QModbusDevice::UnconnectedState) {
|
||||
m_client->disconnectDevice();
|
||||
}
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::isConnected() const
|
||||
{
|
||||
return m_client && m_client->state() == QModbusDevice::ConnectedState;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::readCoil(int address, bool *value, QString *error)
|
||||
{
|
||||
if (!value) {
|
||||
setError("Output value pointer is null", error);
|
||||
return false;
|
||||
const int attempts = qMax(1, m_config.reconnectAttempts + 1);
|
||||
if (m_connectAttempts < attempts) {
|
||||
QTimer::singleShot(
|
||||
qMax(0, m_config.reconnectDelayMs),
|
||||
this, &ModbusTcpManager::ensureConnected);
|
||||
return;
|
||||
}
|
||||
|
||||
quint16 rawValue = 0;
|
||||
if (!readSingleValue(QModbusDataUnit::Coils, address, &rawValue, error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = rawValue != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::readHoldingRegister(int address, quint16 *value, QString *error)
|
||||
{
|
||||
if (!value) {
|
||||
setError("Output value pointer is null", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return readSingleValue(QModbusDataUnit::HoldingRegisters, address, value, error);
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::writeCoil(int address, bool value, QString *error)
|
||||
{
|
||||
return writeSingleValue(QModbusDataUnit::Coils, address, value ? 1 : 0, error);
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::writeHoldingRegister(int address, quint16 value, QString *error)
|
||||
{
|
||||
return writeSingleValue(QModbusDataUnit::HoldingRegisters, address, value, error);
|
||||
}
|
||||
|
||||
QString ModbusTcpManager::lastErrorText() const
|
||||
{
|
||||
return m_lastErrorText;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::readSingleValue(int registerType, int address, quint16 *value, QString *error)
|
||||
{
|
||||
if (address < 0) {
|
||||
setError("Modbus address must be greater than or equal to 0", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!connectDevice(error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QModbusDataUnit unit(static_cast<QModbusDataUnit::RegisterType>(registerType), address, 1);
|
||||
QModbusReply *reply = m_client->sendReadRequest(unit, m_config.serverAddress);
|
||||
if (!reply) {
|
||||
setError(m_client->errorString(), error);
|
||||
return false;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
|
||||
QObject::connect(reply, &QModbusReply::finished, &loop, &QEventLoop::quit);
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
timer.start(m_config.timeoutMs);
|
||||
loop.exec();
|
||||
|
||||
if (!reply->isFinished()) {
|
||||
reply->deleteLater();
|
||||
setError("Modbus TCP read timeout", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reply->error() != QModbusDevice::NoError) {
|
||||
const QString text = reply->errorString();
|
||||
reply->deleteLater();
|
||||
setError(text, error);
|
||||
return false;
|
||||
}
|
||||
|
||||
const QModbusDataUnit result = reply->result();
|
||||
if (result.valueCount() < 1) {
|
||||
reply->deleteLater();
|
||||
setError("Modbus TCP read returned empty result", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = result.value(0);
|
||||
reply->deleteLater();
|
||||
m_lastErrorText.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModbusTcpManager::writeSingleValue(int registerType, int address, quint16 value, QString *error)
|
||||
{
|
||||
if (address < 0) {
|
||||
setError("Modbus address must be greater than or equal to 0", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!connectDevice(error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QModbusDataUnit unit(static_cast<QModbusDataUnit::RegisterType>(registerType), address, 1);
|
||||
unit.setValue(0, value);
|
||||
|
||||
QModbusReply *reply = m_client->sendWriteRequest(unit, m_config.serverAddress);
|
||||
if (!reply) {
|
||||
setError(m_client->errorString(), error);
|
||||
return false;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
|
||||
QObject::connect(reply, &QModbusReply::finished, &loop, &QEventLoop::quit);
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
|
||||
timer.start(m_config.timeoutMs);
|
||||
loop.exec();
|
||||
|
||||
if (!reply->isFinished()) {
|
||||
reply->deleteLater();
|
||||
setError("Modbus TCP write timeout", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reply->error() != QModbusDevice::NoError) {
|
||||
const QString text = reply->errorString();
|
||||
reply->deleteLater();
|
||||
setError(text, error);
|
||||
return false;
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
m_lastErrorText.clear();
|
||||
return true;
|
||||
finishCurrent(false, 0,
|
||||
error.isEmpty() ? "Failed to connect to PLC" : error);
|
||||
}
|
||||
|
||||
void ModbusTcpManager::ensureClient()
|
||||
@@ -246,13 +280,85 @@ void ModbusTcpManager::ensureClient()
|
||||
return;
|
||||
}
|
||||
|
||||
m_client = new QModbusTcpClient();
|
||||
m_client = new QModbusTcpClient(this);
|
||||
connect(m_client, &QModbusClient::stateChanged,
|
||||
this, &ModbusTcpManager::onStateChanged);
|
||||
connect(m_client, &QModbusClient::errorOccurred,
|
||||
this, &ModbusTcpManager::onErrorOccurred);
|
||||
}
|
||||
|
||||
void ModbusTcpManager::setError(const QString &text, QString *error)
|
||||
void ModbusTcpManager::setError(const QString &text)
|
||||
{
|
||||
m_lastErrorText = text;
|
||||
if (error) {
|
||||
*error = m_lastErrorText;
|
||||
}
|
||||
|
||||
void ModbusTcpManager::onStateChanged(QModbusDevice::State state)
|
||||
{
|
||||
if (m_aborting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == QModbusDevice::ConnectedState) {
|
||||
m_connectTimer->stop();
|
||||
m_connecting = false;
|
||||
startCurrentRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == QModbusDevice::UnconnectedState && m_connecting) {
|
||||
handleConnectionFailure(m_client ? m_client->errorString()
|
||||
: QString());
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusTcpManager::onErrorOccurred(QModbusDevice::Error error)
|
||||
{
|
||||
Q_UNUSED(error)
|
||||
if (m_aborting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_connecting) {
|
||||
handleConnectionFailure(m_client ? m_client->errorString()
|
||||
: QString());
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusTcpManager::onReplyFinished()
|
||||
{
|
||||
QModbusReply *reply = qobject_cast<QModbusReply *>(sender());
|
||||
if (!reply || reply != m_reply) {
|
||||
if (reply) {
|
||||
reply->deleteLater();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_reply = nullptr;
|
||||
const bool success = reply->error() == QModbusDevice::NoError;
|
||||
quint16 value = 0;
|
||||
QString error;
|
||||
if (!success) {
|
||||
error = reply->errorString();
|
||||
} else if (!m_currentRequest.write) {
|
||||
const QModbusDataUnit result = reply->result();
|
||||
if (result.valueCount() < 1) {
|
||||
error = "Modbus read returned an empty result";
|
||||
} else {
|
||||
value = result.value(0);
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
if (!error.isEmpty()) {
|
||||
finishCurrent(false, 0, error);
|
||||
return;
|
||||
}
|
||||
|
||||
finishCurrent(true, value, QString());
|
||||
}
|
||||
|
||||
void ModbusTcpManager::onConnectTimeout()
|
||||
{
|
||||
handleConnectionFailure("Modbus TCP connect timeout");
|
||||
}
|
||||
|
||||
+74
-21
@@ -3,43 +3,96 @@
|
||||
|
||||
#include "modbusconfig.h"
|
||||
|
||||
#include <QQueue>
|
||||
#include <QObject>
|
||||
#include <QModbusDevice>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <functional>
|
||||
|
||||
class QModbusTcpClient;
|
||||
class QModbusReply;
|
||||
class QTimer;
|
||||
|
||||
class ModbusTcpManager
|
||||
class ModbusTcpManager : public QObject
|
||||
{
|
||||
public:
|
||||
static ModbusTcpManager &instance();
|
||||
~ModbusTcpManager();
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using Completion = std::function<void(bool, quint16, const QString &)>;
|
||||
|
||||
explicit ModbusTcpManager(const ModbusConfig &config,
|
||||
QObject *parent = nullptr);
|
||||
~ModbusTcpManager() override;
|
||||
|
||||
void setConfig(const ModbusConfig &config);
|
||||
ModbusConfig config() const;
|
||||
|
||||
bool connectDevice(QString *error = nullptr);
|
||||
void disconnectDevice();
|
||||
bool isConnected() const;
|
||||
|
||||
bool readCoil(int address, bool *value, QString *error = nullptr);
|
||||
bool readHoldingRegister(int address, quint16 *value, QString *error = nullptr);
|
||||
bool writeCoil(int address, bool value, QString *error = nullptr);
|
||||
bool writeHoldingRegister(int address, quint16 value, QString *error = nullptr);
|
||||
|
||||
QString lastErrorText() const;
|
||||
void readCoil(int address,
|
||||
const std::function<void(bool, bool, const QString &)> &callback);
|
||||
void readHoldingRegister(
|
||||
int address,
|
||||
const std::function<void(bool, quint16, const QString &)> &callback);
|
||||
void writeCoil(int address, bool value,
|
||||
const std::function<void(bool, const QString &)> &callback);
|
||||
void writeHoldingRegister(
|
||||
int address, quint16 value,
|
||||
const std::function<void(bool, const QString &)> &callback);
|
||||
void abortAll(const QString &reason);
|
||||
bool isBusy() const;
|
||||
|
||||
private:
|
||||
ModbusTcpManager();
|
||||
ModbusTcpManager(const ModbusTcpManager &) = delete;
|
||||
ModbusTcpManager &operator=(const ModbusTcpManager &) = delete;
|
||||
struct Request
|
||||
{
|
||||
Request()
|
||||
: registerType(0)
|
||||
, address(-1)
|
||||
, value(0)
|
||||
, write(false)
|
||||
{
|
||||
}
|
||||
Request(int type, int requestAddress, quint16 requestValue,
|
||||
bool requestWrite, const Completion &requestCallback)
|
||||
: registerType(type)
|
||||
, address(requestAddress)
|
||||
, value(requestValue)
|
||||
, write(requestWrite)
|
||||
, callback(requestCallback)
|
||||
{
|
||||
}
|
||||
|
||||
bool readSingleValue(int registerType, int address, quint16 *value, QString *error);
|
||||
bool writeSingleValue(int registerType, int address, quint16 value, QString *error);
|
||||
int registerType;
|
||||
int address;
|
||||
quint16 value;
|
||||
bool write;
|
||||
Completion callback;
|
||||
};
|
||||
|
||||
void enqueue(const Request &request);
|
||||
void startNext();
|
||||
void ensureConnected();
|
||||
void startCurrentRequest();
|
||||
void finishCurrent(bool success, quint16 value, const QString &error);
|
||||
void handleConnectionFailure(const QString &error);
|
||||
void ensureClient();
|
||||
void setError(const QString &text, QString *error);
|
||||
void setError(const QString &text);
|
||||
|
||||
private slots:
|
||||
void onStateChanged(QModbusDevice::State state);
|
||||
void onErrorOccurred(QModbusDevice::Error error);
|
||||
void onReplyFinished();
|
||||
void onConnectTimeout();
|
||||
|
||||
private:
|
||||
ModbusConfig m_config;
|
||||
QModbusTcpClient *m_client;
|
||||
QModbusReply *m_reply;
|
||||
QTimer *m_connectTimer;
|
||||
QQueue<Request> m_requests;
|
||||
Request m_currentRequest;
|
||||
bool m_hasCurrentRequest;
|
||||
bool m_connecting;
|
||||
bool m_aborting;
|
||||
int m_connectAttempts;
|
||||
QString m_lastErrorText;
|
||||
};
|
||||
|
||||
|
||||
+19
-19
@@ -35,7 +35,7 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
, recoverButton(new QPushButton("Recover", this))
|
||||
, retryButton(new QPushButton("Retry", this))
|
||||
, markNgButton(new QPushButton("Mark NG", this))
|
||||
, stopButton(new QPushButton("Stop", this))
|
||||
, stopButton(new QPushButton("Terminate", this))
|
||||
, processBox(new QGroupBox("Process timing", this))
|
||||
, currentProcessLabel(new QLabel("-", processBox))
|
||||
, processElapsedLabel(new QLabel("00:00:00.000", processBox))
|
||||
@@ -54,6 +54,8 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
productionWorker->moveToThread(productionThread);
|
||||
connect(productionThread, &QThread::finished,
|
||||
productionWorker, &QObject::deleteLater);
|
||||
connect(productionWorker, &ProductionWorker::shutdownReady,
|
||||
productionThread, &QThread::quit, Qt::DirectConnection);
|
||||
|
||||
const QList<QLabel *> values = QList<QLabel *>()
|
||||
<< ui->planValue << ui->pendingValue << ui->frontValue
|
||||
@@ -184,15 +186,18 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
this, &DashboardPage::onTimeoutRecoveryRequired);
|
||||
connect(productionWorker, &ProductionWorker::recoveryCompleted,
|
||||
this, &DashboardPage::onRecoveryCompleted);
|
||||
connect(&DeviceService::instance(), &DeviceService::statusChanged,
|
||||
connect(productionWorker, &ProductionWorker::deviceStatusChanged,
|
||||
this, &DashboardPage::onDeviceStatusChanged);
|
||||
connect(productionWorker, &ProductionWorker::deviceCommunicationError,
|
||||
this, [this](const QString &error) {
|
||||
emit deviceCommunicationError(error);
|
||||
});
|
||||
|
||||
productionThread->start();
|
||||
QMetaObject::invokeMethod(productionWorker, "requestRestore",
|
||||
Qt::QueuedConnection);
|
||||
|
||||
loadOrderOptions();
|
||||
DeviceService::instance().startPolling();
|
||||
processRefreshTimer->setInterval(1000);
|
||||
connect(processRefreshTimer, &QTimer::timeout,
|
||||
this, &DashboardPage::refreshProcessRecords);
|
||||
@@ -203,7 +208,9 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
DashboardPage::~DashboardPage()
|
||||
{
|
||||
if (productionThread->isRunning()) {
|
||||
productionThread->quit();
|
||||
productionWorker->requestStopImmediate();
|
||||
QMetaObject::invokeMethod(productionWorker, "requestShutdown",
|
||||
Qt::QueuedConnection);
|
||||
productionThread->wait();
|
||||
}
|
||||
delete ui;
|
||||
@@ -285,6 +292,7 @@ void DashboardPage::pauseProduction()
|
||||
|
||||
void DashboardPage::stopProduction()
|
||||
{
|
||||
productionWorker->requestStopImmediate();
|
||||
QMetaObject::invokeMethod(productionWorker, "requestStop",
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
@@ -297,22 +305,10 @@ void DashboardPage::resetProduction()
|
||||
|
||||
void DashboardPage::clearAlarm()
|
||||
{
|
||||
QString error;
|
||||
if (!DeviceService::instance().clearAlarm(&error)) {
|
||||
QMessageBox::warning(this, "Clear alarm failed", error);
|
||||
emit logRequested("Alarm log", "Dashboard", "Clear alarm",
|
||||
error, "Failed");
|
||||
return;
|
||||
}
|
||||
if (!ProductionRepository().clearActiveAlarms(
|
||||
QString(), "OPERATOR", &error)) {
|
||||
QMessageBox::warning(this, "Clear alarm failed", error);
|
||||
emit logRequested("Alarm log", "Dashboard", "Clear alarm",
|
||||
error, "Failed");
|
||||
return;
|
||||
}
|
||||
QMetaObject::invokeMethod(productionWorker, "requestClearAlarm",
|
||||
Qt::QueuedConnection);
|
||||
emit logRequested("Alarm log", "Dashboard", "Clear alarm",
|
||||
"PLC alarm clear command completed", "Success");
|
||||
"PLC alarm clear command requested", "Pending");
|
||||
}
|
||||
|
||||
void DashboardPage::onOrderChanged(int)
|
||||
@@ -446,11 +442,14 @@ void DashboardPage::updateRecoveryButtons()
|
||||
|| state == ProductionService::ManualConfirm;
|
||||
const bool running = state != ProductionService::Idle
|
||||
&& state != ProductionService::Completed;
|
||||
const bool terminating = state == ProductionService::Terminating;
|
||||
recoverButton->setVisible(recoveryRequired);
|
||||
retryButton->setVisible(recoveryRequired);
|
||||
markNgButton->setVisible(recoveryRequired
|
||||
&& productionWorkpiece.id > 0);
|
||||
stopButton->setVisible(running);
|
||||
stopButton->setEnabled(!terminating);
|
||||
stopButton->setText(terminating ? "Terminating..." : "Terminate");
|
||||
recoverButton->setText(state == ProductionService::ManualConfirm
|
||||
? "Continue" : "Recover");
|
||||
}
|
||||
@@ -553,6 +552,7 @@ void DashboardPage::updateCurrentProcessDuration(int elapsedMs)
|
||||
|
||||
void DashboardPage::onDeviceStatusChanged(const DeviceStatus &status)
|
||||
{
|
||||
emit deviceStatusChanged(status);
|
||||
deviceStatusLabel->setText(
|
||||
QString("PLC: %1 | Robot: %2 | Safety door: %3 | E-stop: %4")
|
||||
.arg(status.plcConnected ? "ONLINE" : "OFFLINE")
|
||||
|
||||
@@ -30,6 +30,8 @@ public:
|
||||
signals:
|
||||
void systemStateChanged(const QString &state);
|
||||
void currentStepChanged(const QString &step);
|
||||
void deviceStatusChanged(const DeviceStatus &status);
|
||||
void deviceCommunicationError(const QString &error);
|
||||
void logRequested(const QString &type, const QString &module, const QString &action,
|
||||
const QString &content, const QString &status);
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "devicepage.h"
|
||||
#include "ui_devicepage.h"
|
||||
|
||||
#include "../services/deviceservice.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
@@ -17,11 +15,6 @@ DevicePage::DevicePage(QWidget *parent)
|
||||
ui->setupUi(this);
|
||||
|
||||
setupTable();
|
||||
connect(&DeviceService::instance(), &DeviceService::statusChanged,
|
||||
this, &DevicePage::updateStatus);
|
||||
connect(&DeviceService::instance(), &DeviceService::communicationError,
|
||||
this, &DevicePage::handleCommunicationError);
|
||||
DeviceService::instance().startPolling();
|
||||
}
|
||||
|
||||
void DevicePage::setupTable()
|
||||
@@ -100,6 +93,5 @@ void DevicePage::handleCommunicationError(const QString &error)
|
||||
|
||||
DevicePage::~DevicePage()
|
||||
{
|
||||
DeviceService::instance().stopPolling();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public:
|
||||
explicit DevicePage(QWidget *parent = nullptr);
|
||||
~DevicePage();
|
||||
|
||||
private slots:
|
||||
public slots:
|
||||
void updateStatus(const DeviceStatus &status);
|
||||
void handleCommunicationError(const QString &error);
|
||||
|
||||
|
||||
+672
-218
File diff suppressed because it is too large
Load Diff
+56
-17
@@ -3,7 +3,10 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <functional>
|
||||
|
||||
struct DeviceStatus
|
||||
{
|
||||
@@ -26,6 +29,12 @@ class DeviceService : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using OperationCallback = std::function<void(bool, const QString &)>;
|
||||
using StatusCallback =
|
||||
std::function<void(bool, const DeviceStatus &, const QString &)>;
|
||||
using ActionCallback =
|
||||
std::function<void(bool, bool, const QString &)>;
|
||||
|
||||
enum ProductionAction
|
||||
{
|
||||
RackPick,
|
||||
@@ -38,38 +47,68 @@ public:
|
||||
RackPlace
|
||||
};
|
||||
|
||||
static DeviceService &instance();
|
||||
explicit DeviceService(QObject *parent = nullptr);
|
||||
|
||||
void startPolling();
|
||||
void stopPolling();
|
||||
bool isPolling() const;
|
||||
|
||||
bool readStatus(DeviceStatus *status, QString *error = nullptr);
|
||||
bool start(QString *error = nullptr);
|
||||
bool pause(QString *error = nullptr);
|
||||
bool reset(QString *error = nullptr);
|
||||
bool clearAlarm(QString *error = nullptr);
|
||||
bool setInspectionMode(const QString &mode, QString *error = nullptr);
|
||||
bool executeProductionAction(ProductionAction action, int trayNo,
|
||||
int slotNo, QString *error = nullptr);
|
||||
void requestStatus(const StatusCallback &callback);
|
||||
void start(const OperationCallback &callback);
|
||||
void pause(const OperationCallback &callback);
|
||||
void reset(const OperationCallback &callback);
|
||||
void clearAlarm(const OperationCallback &callback);
|
||||
void setInspectionMode(const QString &mode,
|
||||
const OperationCallback &callback);
|
||||
void terminate(const OperationCallback &callback);
|
||||
void beginProductionAction(ProductionAction action, int trayNo,
|
||||
int slotNo, const OperationCallback &callback);
|
||||
void pollProductionAction(const ActionCallback &callback);
|
||||
void cancelProductionAction(const OperationCallback &callback);
|
||||
bool productionActionActive() const;
|
||||
bool productionActionBusy() const;
|
||||
|
||||
signals:
|
||||
void statusChanged(const DeviceStatus &status);
|
||||
void communicationError(const QString &error);
|
||||
|
||||
private:
|
||||
explicit DeviceService(QObject *parent = nullptr);
|
||||
DeviceService(const DeviceService &) = delete;
|
||||
DeviceService &operator=(const DeviceService &) = delete;
|
||||
|
||||
void pollStatus();
|
||||
DeviceStatus simulatedStatus() const;
|
||||
bool connectWithRetry(QString *error);
|
||||
bool readStatusOnce(DeviceStatus *status, QString *error);
|
||||
bool executeCommand(int commandAddress, int feedbackAddress, QString *error);
|
||||
bool waitForFeedback(int address, QString *error);
|
||||
void readStatusStep(int index, const DeviceStatus &status);
|
||||
void finishStatusRequest(bool success, const DeviceStatus &status,
|
||||
const QString &error);
|
||||
void executeCommand(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void writeCommandAndWaitFeedback(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void pollFeedback(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void clearSignals(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback);
|
||||
void clearActionSignals(const OperationCallback &callback);
|
||||
void clearNextTerminationSignal();
|
||||
void finishTermination(bool success, const QString &error);
|
||||
void finishActionPoll(bool completed, const ActionCallback &callback);
|
||||
|
||||
QTimer *m_pollTimer;
|
||||
class ModbusTcpManager *m_modbus;
|
||||
bool m_statusRequestPending;
|
||||
QList<StatusCallback> m_statusCallbacks;
|
||||
bool m_controlRequestPending;
|
||||
bool m_productionActionActive;
|
||||
bool m_productionActionBusy;
|
||||
int m_productionCommandAddress;
|
||||
int m_productionFeedbackAddress;
|
||||
bool m_terminationActive;
|
||||
QList<QPair<int, int>> m_terminationSignals;
|
||||
int m_terminationSignalIndex;
|
||||
OperationCallback m_terminationCallback;
|
||||
int m_controlCommandAddress;
|
||||
int m_controlFeedbackAddress;
|
||||
};
|
||||
|
||||
#endif // DEVICESERVICE_H
|
||||
|
||||
+712
-187
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
#include <atomic>
|
||||
|
||||
class QTimer;
|
||||
|
||||
@@ -39,7 +40,8 @@ public:
|
||||
TimeoutPaused,
|
||||
RecoveryChecking,
|
||||
ManualConfirm,
|
||||
Retrying
|
||||
Retrying,
|
||||
Terminating
|
||||
};
|
||||
Q_ENUM(State)
|
||||
|
||||
@@ -58,13 +60,19 @@ public:
|
||||
bool resume(QString *error = nullptr);
|
||||
bool stop(QString *error = nullptr);
|
||||
bool reset(QString *error = nullptr);
|
||||
bool clearAlarm(QString *error = nullptr);
|
||||
bool recover(QString *error = nullptr);
|
||||
bool retry(QString *error = nullptr);
|
||||
bool markCurrentWorkpieceNg(QString *error = nullptr);
|
||||
bool restoreActiveRun(QString *error = nullptr);
|
||||
void shutdown(const DeviceService::OperationCallback &callback);
|
||||
void setExternalStopFlag(std::atomic_bool *flag);
|
||||
void requestStopImmediate();
|
||||
|
||||
signals:
|
||||
void stateChanged(ProductionService::State state, const QString &name);
|
||||
void deviceStatusChanged(const DeviceStatus &status);
|
||||
void deviceCommunicationError(const QString &error);
|
||||
void currentWorkpieceChanged(int workpieceId, const QString &barcode);
|
||||
void currentWorkpieceSnapshotChanged(const Workpiece &workpiece);
|
||||
void currentPositionChanged(int trayNo, int slotNo);
|
||||
@@ -99,6 +107,11 @@ private:
|
||||
void tickProduction();
|
||||
bool processProductionStep(State state, QString *error);
|
||||
bool recoverFromPlcStep(QString *error);
|
||||
bool processProductionAction(DeviceService::ProductionAction action,
|
||||
bool *completed, QString *error);
|
||||
void cancelPendingProductionAction(
|
||||
const DeviceService::OperationCallback &callback);
|
||||
void tryDeferredActionCancel();
|
||||
bool executeCurrentAction(DeviceService::ProductionAction action,
|
||||
const QString &nextProcessStep,
|
||||
State nextState, QString *error);
|
||||
@@ -118,14 +131,18 @@ private:
|
||||
bool isTimedState(State state) const;
|
||||
QString stateNameForState(State state) const;
|
||||
QString processStepForState(State state) const;
|
||||
State stateForProcessStep(const QString &processStep) const;
|
||||
QString runStateForState(State state) const;
|
||||
State stateFromName(const QString &name) const;
|
||||
void persistAlarm(const QString &code, const QString &message);
|
||||
void persistDeviceStatus(const DeviceStatus &status);
|
||||
void fail(const QString &error);
|
||||
void finishShutdown(bool success, const QString &error);
|
||||
bool isActive() const;
|
||||
bool stopRequested() const;
|
||||
|
||||
QTimer *m_timer;
|
||||
DeviceService *m_deviceService;
|
||||
QElapsedTimer m_stateTimer;
|
||||
QElapsedTimer m_processTimer;
|
||||
QElapsedTimer m_heartbeatTimer;
|
||||
@@ -141,10 +158,28 @@ private:
|
||||
int m_currentTrayNo;
|
||||
int m_currentSlotNo;
|
||||
int m_frontRawResult;
|
||||
bool m_actionPending;
|
||||
bool m_actionStarting;
|
||||
bool m_actionPollPending;
|
||||
bool m_actionCompleted;
|
||||
QString m_actionError;
|
||||
bool m_actionCancelRequested;
|
||||
DeviceService::OperationCallback m_deferredCancelCallback;
|
||||
bool m_inspectionStatusPending;
|
||||
bool m_inspectionStatusReady;
|
||||
QString m_inspectionStatusError;
|
||||
bool m_starting;
|
||||
bool m_plcStarted;
|
||||
bool m_tickRunning;
|
||||
DeviceService::ProductionAction m_pendingAction;
|
||||
QString m_inspectionMode;
|
||||
QString m_frontResultState;
|
||||
QString m_currentProcessStep;
|
||||
QString m_lastError;
|
||||
std::atomic_bool m_stopRequested;
|
||||
std::atomic_bool *m_externalStopRequested;
|
||||
bool m_shutdownRequested;
|
||||
DeviceService::OperationCallback m_shutdownCallback;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ProductionService::State)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
ProductionWorker::ProductionWorker(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_service(nullptr)
|
||||
, m_stopRequested(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -13,8 +14,13 @@ void ProductionWorker::ensureService()
|
||||
}
|
||||
|
||||
m_service = new ProductionService(this);
|
||||
m_service->setExternalStopFlag(&m_stopRequested);
|
||||
connect(m_service, &ProductionService::stateChanged,
|
||||
this, &ProductionWorker::stateChanged);
|
||||
connect(m_service, &ProductionService::deviceStatusChanged,
|
||||
this, &ProductionWorker::deviceStatusChanged);
|
||||
connect(m_service, &ProductionService::deviceCommunicationError,
|
||||
this, &ProductionWorker::deviceCommunicationError);
|
||||
connect(m_service, &ProductionService::currentWorkpieceChanged,
|
||||
this, &ProductionWorker::currentWorkpieceChanged);
|
||||
connect(m_service, &ProductionService::currentWorkpieceSnapshotChanged,
|
||||
@@ -37,6 +43,11 @@ void ProductionWorker::ensureService()
|
||||
this, &ProductionWorker::recoveryCompleted);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestStopImmediate()
|
||||
{
|
||||
m_stopRequested.store(true);
|
||||
}
|
||||
|
||||
void ProductionWorker::reportFailure(bool success, const QString &error)
|
||||
{
|
||||
if (!success && !error.isEmpty()) {
|
||||
@@ -79,6 +90,13 @@ void ProductionWorker::requestReset()
|
||||
reportFailure(m_service->reset(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestClearAlarm()
|
||||
{
|
||||
ensureService();
|
||||
QString error;
|
||||
reportFailure(m_service->clearAlarm(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestRecover()
|
||||
{
|
||||
ensureService();
|
||||
@@ -106,3 +124,16 @@ void ProductionWorker::requestRestore()
|
||||
QString error;
|
||||
reportFailure(m_service->restoreActiveRun(&error), error);
|
||||
}
|
||||
|
||||
void ProductionWorker::requestShutdown()
|
||||
{
|
||||
ensureService();
|
||||
m_service->shutdown(
|
||||
[this](bool success, const QString &error) {
|
||||
if (!success) {
|
||||
reportFailure(false, error);
|
||||
return;
|
||||
}
|
||||
emit shutdownReady();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "productionservice.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <atomic>
|
||||
|
||||
class ProductionWorker : public QObject
|
||||
{
|
||||
@@ -11,6 +12,7 @@ class ProductionWorker : public QObject
|
||||
|
||||
public:
|
||||
explicit ProductionWorker(QObject *parent = nullptr);
|
||||
void requestStopImmediate();
|
||||
|
||||
public slots:
|
||||
void requestStart(int orderId);
|
||||
@@ -18,13 +20,17 @@ public slots:
|
||||
void requestResume();
|
||||
void requestStop();
|
||||
void requestReset();
|
||||
void requestClearAlarm();
|
||||
void requestRecover();
|
||||
void requestRetry();
|
||||
void requestMarkNg();
|
||||
void requestRestore();
|
||||
void requestShutdown();
|
||||
|
||||
signals:
|
||||
void stateChanged(ProductionService::State state, const QString &name);
|
||||
void deviceStatusChanged(const DeviceStatus &status);
|
||||
void deviceCommunicationError(const QString &error);
|
||||
void currentWorkpieceChanged(int workpieceId, const QString &barcode);
|
||||
void currentWorkpieceSnapshotChanged(const Workpiece &workpiece);
|
||||
void currentPositionChanged(int trayNo, int slotNo);
|
||||
@@ -35,12 +41,14 @@ signals:
|
||||
void timeoutWarning(const QString &state, int elapsedMs, int timeoutMs);
|
||||
void timeoutRecoveryRequired(const QString &state, const QString &message);
|
||||
void recoveryCompleted(const QString &mode);
|
||||
void shutdownReady();
|
||||
|
||||
private:
|
||||
void ensureService();
|
||||
void reportFailure(bool success, const QString &error);
|
||||
|
||||
ProductionService *m_service;
|
||||
std::atomic_bool m_stopRequested;
|
||||
};
|
||||
|
||||
#endif // PRODUCTIONWORKER_H
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.11.0, 2026-08-19T20:22:02. -->
|
||||
<!-- Written by QtCreator 4.11.0, 2026-08-22T19:38:39. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@@ -131,6 +131,10 @@ void Widget::setupMainArea(QVBoxLayout *rootLayout)
|
||||
connect(dashboardPage, &DashboardPage::currentStepChanged, this, [this](const QString &step) {
|
||||
currentStepLabel->setText("工序:" + step);
|
||||
});
|
||||
connect(dashboardPage, &DashboardPage::deviceStatusChanged,
|
||||
devicePage, &DevicePage::updateStatus);
|
||||
connect(dashboardPage, &DashboardPage::deviceCommunicationError,
|
||||
devicePage, &DevicePage::handleCommunicationError);
|
||||
connect(dashboardPage, &DashboardPage::logRequested, this, &Widget::appendLog);
|
||||
connect(orderPage, &OrderPage::logRequested, this, &Widget::appendLog);
|
||||
connect(rackPage, &RackPage::logRequested, this, &Widget::appendLog);
|
||||
|
||||
Reference in New Issue
Block a user