订单流程添加修改

This commit is contained in:
lidg
2026-08-20 11:22:55 +08:00
parent 0c4fd6844c
commit 4e99071ce1
31 changed files with 1359 additions and 241 deletions
+129 -9
View File
@@ -11,6 +11,51 @@ namespace {
const int FeedbackPollIntervalMs = 50;
bool actionAddresses(DeviceService::ProductionAction action,
const ModbusAddressMap &addresses,
int *commandAddress, int *feedbackAddress)
{
if (!commandAddress || !feedbackAddress) {
return false;
}
switch (action) {
case DeviceService::RackPick:
*commandAddress = addresses.rackPickCommand;
*feedbackAddress = addresses.rackPickFeedback;
return true;
case DeviceService::FrontLoad:
*commandAddress = addresses.frontLoadCommand;
*feedbackAddress = addresses.frontLoadFeedback;
return true;
case DeviceService::Inspect:
*commandAddress = addresses.inspectionCommand;
*feedbackAddress = addresses.inspectionFeedback;
return true;
case DeviceService::FrontUnload:
*commandAddress = addresses.frontUnloadCommand;
*feedbackAddress = addresses.frontUnloadFeedback;
return true;
case DeviceService::Flip:
*commandAddress = addresses.flipCommand;
*feedbackAddress = addresses.flipFeedback;
return true;
case DeviceService::BackLoad:
*commandAddress = addresses.backLoadCommand;
*feedbackAddress = addresses.backLoadFeedback;
return true;
case DeviceService::BackUnload:
*commandAddress = addresses.backUnloadCommand;
*feedbackAddress = addresses.backUnloadFeedback;
return true;
case DeviceService::RackPlace:
*commandAddress = addresses.rackPlaceCommand;
*feedbackAddress = addresses.rackPlaceFeedback;
return true;
}
return false;
}
}
DeviceService &DeviceService::instance()
@@ -188,6 +233,75 @@ bool DeviceService::clearAlarm(QString *error)
return executeCommand(addresses.clearAlarmCommand, addresses.clearAlarmFeedback, error);
}
bool DeviceService::setInspectionMode(const QString &mode, QString *error)
{
if (mode != "BEFORE_PLATING" && mode != "AFTER_PLATING") {
if (error) {
*error = "Inspection mode must be BEFORE_PLATING or AFTER_PLATING";
}
return false;
}
if (ConfigManager::instance().simulationMode()) {
return true;
}
if (!ConfigManager::instance().productionEnabled()) {
if (error) {
*error = "Production control is disabled by configuration";
}
return false;
}
const bool afterPlating = mode == "AFTER_PLATING";
const ModbusAddressMap &addresses = ModbusTcpManager::instance().config().addressMap;
if (!ModbusTcpManager::instance().writeCoil(
addresses.inspectionMode, afterPlating, error)) {
return false;
}
return true;
}
bool DeviceService::executeProductionAction(ProductionAction action,
int trayNo, int slotNo,
QString *error)
{
if (ConfigManager::instance().simulationMode()) {
return true;
}
if (!ConfigManager::instance().productionEnabled()) {
if (error) {
*error = "Production control is disabled by configuration";
}
return false;
}
if (trayNo <= 0 || slotNo < 1 || slotNo > 49) {
if (error) {
*error = "PLC tray or slot position is invalid";
}
return false;
}
const ModbusAddressMap &addresses = ModbusTcpManager::instance().config().addressMap;
if (action == RackPick || action == RackPlace) {
ModbusTcpManager &modbus = ModbusTcpManager::instance();
if (!modbus.writeHoldingRegister(
addresses.trayNumber, static_cast<quint16>(trayNo), error)
|| !modbus.writeHoldingRegister(
addresses.slotNumber, static_cast<quint16>(slotNo), error)) {
return false;
}
}
int commandAddress = -1;
int feedbackAddress = -1;
if (!actionAddresses(action, addresses, &commandAddress, &feedbackAddress)) {
if (error) {
*error = "Unknown PLC production action";
}
return false;
}
return executeCommand(commandAddress, feedbackAddress, error);
}
bool DeviceService::connectWithRetry(QString *error)
{
ModbusTcpManager &modbus = ModbusTcpManager::instance();
@@ -260,17 +374,22 @@ bool DeviceService::executeCommand(int commandAddress, int feedbackAddress, QStr
continue;
}
QThread::msleep(qMax(1, config.commandPulseMs));
if (!modbus.writeCoil(commandAddress, false, &lastError)) {
if (!waitForFeedback(feedbackAddress, &lastError)) {
modbus.writeCoil(commandAddress, false);
modbus.disconnectDevice();
continue;
}
if (waitForFeedback(feedbackAddress, &lastError)) {
return true;
if (!modbus.writeCoil(commandAddress, false, &lastError)) {
modbus.disconnectDevice();
continue;
}
if (!modbus.writeCoil(feedbackAddress, false, &lastError)) {
modbus.disconnectDevice();
continue;
}
modbus.disconnectDevice();
return true;
}
if (error) {
@@ -282,11 +401,12 @@ bool DeviceService::executeCommand(int commandAddress, int feedbackAddress, QStr
bool DeviceService::waitForFeedback(int address, QString *error)
{
ModbusTcpManager &modbus = ModbusTcpManager::instance();
const int timeoutMs = qMax(1, modbus.config().feedbackTimeoutMs);
QElapsedTimer timer;
timer.start();
// const int timeoutMs = qMax(1, modbus.config().feedbackTimeoutMs);
// QElapsedTimer timer;
// timer.start();
while (timer.elapsed() < timeoutMs) {
//while (timer.elapsed() < timeoutMs) {
while (true) {
bool feedback = false;
if (!modbus.readCoil(address, &feedback, error)) {
return false;