feat(production): 修改订单清除按钮功能---除了清除报警、也复位状态,让订单能继续执行
This commit is contained in:
@@ -100,6 +100,7 @@ void DeviceService::startPolling()
|
||||
DeviceService::~DeviceService()
|
||||
{
|
||||
m_pollTimer->stop();
|
||||
++m_resetGeneration;
|
||||
m_terminationActive = true;
|
||||
m_terminationCallback = OperationCallback();
|
||||
++m_visionGeneration;
|
||||
@@ -446,6 +447,7 @@ void DeviceService::terminate(const OperationCallback &callback)
|
||||
}
|
||||
|
||||
m_terminationActive = true;
|
||||
++m_resetGeneration;
|
||||
m_terminationCallback = callback;
|
||||
m_terminationSignals.clear();
|
||||
m_terminationSignalIndex = 0;
|
||||
@@ -478,6 +480,97 @@ void DeviceService::terminate(const OperationCallback &callback)
|
||||
clearNextTerminationSignal();
|
||||
}
|
||||
|
||||
void DeviceService::resetProductionSignals(const OperationCallback &callback)
|
||||
{
|
||||
if (m_terminationActive) {
|
||||
if (callback) callback(false, "PLC termination or reset is already in progress");
|
||||
return;
|
||||
}
|
||||
const bool simulation = ConfigManager::instance().simulationMode();
|
||||
if (!simulation && !ConfigManager::instance().productionEnabled()) {
|
||||
if (callback) callback(false, "Production control is disabled by configuration");
|
||||
return;
|
||||
}
|
||||
const ModbusAddressMap addresses = m_modbus->config().addressMap;
|
||||
const VisionConfig vision = ConfigManager::instance().visionConfig();
|
||||
if (addresses.clearAlarmCommand < 0 || addresses.clearAlarmCommand > 65535) {
|
||||
if (callback) callback(false, "Invalid clear-alarm coil address");
|
||||
return;
|
||||
}
|
||||
QList<int> resetSignals;
|
||||
const ProductionAction actions[] = {PhotoMoveAction, RackPick, FrontLoad, Inspect,
|
||||
FrontUnload, Flip, ReverseFlip, BackLoad, BackUnload, RackPlace};
|
||||
for (const ProductionAction action : actions) {
|
||||
int command = -1;
|
||||
int feedback = -1;
|
||||
actionAddresses(action, addresses, vision, &command, &feedback);
|
||||
for (const int address : {command, feedback}) {
|
||||
if (!resetSignals.contains(address)) resetSignals.append(address);
|
||||
}
|
||||
}
|
||||
if (!resetSignals.contains(vision.comparisonPickCoil)) resetSignals.append(vision.comparisonPickCoil);
|
||||
for (const int address : resetSignals) {
|
||||
if (address < 0 || address > 65535 || address == addresses.clearAlarmCommand) {
|
||||
if (callback) callback(false, QString("Invalid production reset coil M%1").arg(address));
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_terminationActive = true;
|
||||
m_terminationCallback = callback;
|
||||
const quint64 generation = ++m_resetGeneration;
|
||||
++m_visionGeneration;
|
||||
m_pollTimer->stop();
|
||||
m_resetSignals = resetSignals;
|
||||
m_resetSignalIndex = 0;
|
||||
m_modbus->abortAll("PLC production reset requested");
|
||||
m_statusRequestPending = false;
|
||||
m_controlRequestPending = false;
|
||||
m_productionActionActive = false;
|
||||
m_productionActionBusy = false;
|
||||
if (simulation) {
|
||||
finishTermination(true, QString());
|
||||
return;
|
||||
}
|
||||
m_modbus->writeCoil(addresses.clearAlarmCommand, true,
|
||||
[this, generation, addresses](bool success, const QString &error) {
|
||||
if (generation != m_resetGeneration || !m_terminationActive) return;
|
||||
if (!success) {
|
||||
finishTermination(false, QString("Clear alarm M%1 failed: %2")
|
||||
.arg(addresses.clearAlarmCommand).arg(error));
|
||||
return;
|
||||
}
|
||||
clearNextResetSignal(generation);
|
||||
});
|
||||
}
|
||||
|
||||
void DeviceService::clearNextResetSignal(quint64 generation)
|
||||
{
|
||||
if (generation != m_resetGeneration || !m_terminationActive) return;
|
||||
if (m_resetSignalIndex >= m_resetSignals.size()) {
|
||||
finishTermination(true, QString());
|
||||
return;
|
||||
}
|
||||
const int address = m_resetSignals.at(m_resetSignalIndex++);
|
||||
m_modbus->writeCoil(address, false,
|
||||
[this, generation, address](bool written, const QString &error) {
|
||||
if (generation != m_resetGeneration || !m_terminationActive) return;
|
||||
if (!written) {
|
||||
finishTermination(false, QString("Reset M%1 failed: %2").arg(address).arg(error));
|
||||
return;
|
||||
}
|
||||
m_modbus->readCoil(address,
|
||||
[this, generation, address](bool read, bool value, const QString &readError) {
|
||||
if (generation != m_resetGeneration || !m_terminationActive) return;
|
||||
if (!read || value) {
|
||||
finishTermination(false, QString("Reset M%1 not confirmed: %2")
|
||||
.arg(address).arg(read ? "coil remains set" : readError));
|
||||
return;
|
||||
}
|
||||
clearNextResetSignal(generation);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void DeviceService::clearNextTerminationSignal()
|
||||
{
|
||||
if (!m_terminationActive) {
|
||||
@@ -517,10 +610,13 @@ void DeviceService::finishTermination(bool success, const QString &error)
|
||||
}
|
||||
|
||||
const OperationCallback callback = m_terminationCallback;
|
||||
++m_resetGeneration;
|
||||
m_terminationCallback = OperationCallback();
|
||||
m_terminationActive = false;
|
||||
m_terminationSignals.clear();
|
||||
m_terminationSignalIndex = 0;
|
||||
m_resetSignals.clear();
|
||||
m_resetSignalIndex = 0;
|
||||
m_controlRequestPending = false;
|
||||
m_productionActionActive = false;
|
||||
m_productionActionBusy = false;
|
||||
|
||||
Reference in New Issue
Block a user