fix(Tray): 托盘传感器显示修改

This commit is contained in:
lidg
2026-11-09 18:16:54 +08:00
parent a8b2b31ce7
commit c248954b87
14 changed files with 170 additions and 51 deletions
+1
View File
@@ -1,3 +1,4 @@
/tests/
/build/
/docs/
*.vision-state.json
+6
View File
@@ -21,6 +21,12 @@ reconnectAttempts=2
; Coils
clearAlarmCommand=815
plcRunning=817
trayPresent1=820
trayPresent2=821
trayPresent3=822
trayPresent4=823
trayPresent5=824
trayPresent6=825
safetyDoorClosed=826
safetyDoor1Closed=827
safetyDoor2Closed=828
+6
View File
@@ -86,6 +86,12 @@ bool ConfigManager::load(const QString &filePath)
ModbusAddressMap &addresses = m_modbusConfig.addressMap;
addresses.clearAlarmCommand = settings.value("modbus/clearAlarmCommand", addresses.clearAlarmCommand).toInt();
addresses.plcRunning = settings.value("modbus/plcRunning", addresses.plcRunning).toInt();
addresses.trayPresent1 = settings.value("modbus/trayPresent1", addresses.trayPresent1).toInt();
addresses.trayPresent2 = settings.value("modbus/trayPresent2", addresses.trayPresent2).toInt();
addresses.trayPresent3 = settings.value("modbus/trayPresent3", addresses.trayPresent3).toInt();
addresses.trayPresent4 = settings.value("modbus/trayPresent4", addresses.trayPresent4).toInt();
addresses.trayPresent5 = settings.value("modbus/trayPresent5", addresses.trayPresent5).toInt();
addresses.trayPresent6 = settings.value("modbus/trayPresent6", addresses.trayPresent6).toInt();
addresses.plcReady = settings.value("modbus/plcReady", addresses.plcReady).toInt();
addresses.robotIdle = settings.value("modbus/robotIdle", addresses.robotIdle).toInt();
addresses.robotRunning = settings.value("modbus/robotRunning", addresses.robotRunning).toInt();
+6
View File
@@ -18,6 +18,12 @@ bool ModbusAddressMap::isValid(QString *error) const
const QList<QPair<QString, int> > coilAddresses = QList<QPair<QString, int> >()
<< qMakePair(QString("clearAlarmCommand"), clearAlarmCommand)
<< qMakePair(QString("plcRunning"), plcRunning)
<< qMakePair(QString("trayPresent1"), trayPresent1)
<< qMakePair(QString("trayPresent2"), trayPresent2)
<< qMakePair(QString("trayPresent3"), trayPresent3)
<< qMakePair(QString("trayPresent4"), trayPresent4)
<< qMakePair(QString("trayPresent5"), trayPresent5)
<< qMakePair(QString("trayPresent6"), trayPresent6)
<< qMakePair(QString("plcReady"), plcReady)
<< qMakePair(QString("robotIdle"), robotIdle)
<< qMakePair(QString("robotRunning"), robotRunning)
+6
View File
@@ -8,6 +8,12 @@ struct ModbusAddressMap
int clearAlarmCommand = 3;
int plcRunning = 817;
int trayPresent1 = 820;
int trayPresent2 = 821;
int trayPresent3 = 822;
int trayPresent4 = 823;
int trayPresent5 = 824;
int trayPresent6 = 825;
int safetyDoorClosed = 826;
int safetyDoor1Closed = 827;
int safetyDoor2Closed = 828;
+15 -4
View File
@@ -1152,6 +1152,7 @@ void DashboardPage::updateCurrentProcessDuration(int elapsedMs)
void DashboardPage::onDeviceStatusChanged(const DeviceStatus &status)
{
deviceStatus = status;
emit deviceStatusChanged(status);
const bool offline = !status.statusValid || !status.plcConnected;
const QString plcText = offline ? "离线"
@@ -1254,14 +1255,24 @@ void DashboardPage::updateRackSummary()
}
const Tray &tray = trays.at(index);
const QString status = tray.present ? tray.status : "离位";
const bool sensorAvailable = deviceStatus.statusValid
&& deviceStatus.plcConnected;
const bool present = !sensorAvailable || deviceStatus.trayPresent[index];
if (!present) {
updateStatusCell(cell,
QString("托盘 %1\n不在位:0/49").arg(index + 1),
"#90a4ae",
highlightedTrayIds.contains(tray.id));
continue;
}
const QString status = tray.status;
const QString statusText = status == "OK" ? "已完成"
: status == "NG" ? "有 NG"
: status == "PROCESSING" ? "加工中"
: status == "PENDING" ? "待检测"
: tray.present ? "在位" : "离位";
const QString color = !tray.present ? "#90a4ae"
: status == "NG" ? "#d32f2f"
: "有托盘";
const QString color = status == "NG" ? "#d32f2f"
: status == "PROCESSING" ? "#1e88e5"
: status == "OK" ? "#2e7d32" : "#78909c";
updateStatusCell(cell,
+1
View File
@@ -113,6 +113,7 @@ private:
int currentOrderId;
bool currentOrderStartable;
bool currentOrderResumable;
DeviceStatus deviceStatus;
Workpiece productionWorkpiece;
int productionTrayNo;
int productionSlotNo;
+27 -2
View File
@@ -4,6 +4,7 @@
#include "squaretraybutton.h"
#include "uihelpers.h"
#include "../services/deviceservice.h"
#include "../services/trayservice.h"
#include <QAbstractButton>
@@ -14,6 +15,19 @@
#include <QSizePolicy>
#include <QtGlobal>
namespace {
QString displayTrayStatus(const QString &status)
{
if (status == "OK") return "已完成";
if (status == "NG") return "有 NG";
if (status == "PROCESSING") return "加工中";
if (status == "PENDING") return "待检测";
return "有托盘";
}
}
RackPage::RackPage(QWidget *parent)
: QWidget(parent)
, ui(new Ui::RackPage)
@@ -106,6 +120,15 @@ void RackPage::refresh()
loadTrays();
}
void RackPage::updateDeviceStatus(const DeviceStatus &status)
{
trayPresenceAvailable = status.statusValid && status.plcConnected;
for (int index = 0; index < 6; ++index) {
trayPresent[index] = status.trayPresent[index];
}
updateTrayButtons();
}
void RackPage::loadTrays()
{
QString error;
@@ -148,15 +171,17 @@ void RackPage::updateTrayButtons()
for (int index = 0; index < rackTrayButtons.size(); ++index) {
SquareTrayButton *button = rackTrayButtons.at(index);
if (index >= trays.size()) {
button->setTrayInfo(0, QString(), 0, "无数据", false);
button->setTrayInfo(0, QString(), 0, "无数据", false, true);
button->setPlanned(false);
button->setChecked(false);
continue;
}
const Tray &tray = trays.at(index);
const bool sensorPresent = !trayPresenceAvailable || trayPresent[index];
button->setTrayInfo(tray.id, tray.code, tray.loadedCount,
tray.status, tray.present);
displayTrayStatus(tray.status), tray.present,
sensorPresent);
bool planned = false;
QString error;
const QList<TraySlot> traySlots =
+4
View File
@@ -11,6 +11,7 @@ class QLabel;
class QButtonGroup;
class QResizeEvent;
class SquareTrayButton;
struct DeviceStatus;
namespace Ui { class RackPage; }
@@ -24,6 +25,7 @@ public:
public slots:
void refresh();
void updateDeviceStatus(const DeviceStatus &status);
signals:
void logRequested(const QString &type, const QString &module, const QString &action,
@@ -48,6 +50,8 @@ private:
QList<Tray> trays;
int selectedTrayId;
int selectedTrayIndex;
bool trayPresenceAvailable = false;
bool trayPresent[6] = {};
};
#endif // RACKPAGE_H
+15 -10
View File
@@ -7,6 +7,7 @@ SquareTrayButton::SquareTrayButton(int trayIndex, int loadedCount, QWidget *pare
: QAbstractButton(parent)
, m_trayId(0)
, m_planned(false)
, m_sensorPresent(true)
{
setCheckable(true);
setCursor(Qt::PointingHandCursor);
@@ -14,16 +15,17 @@ SquareTrayButton::SquareTrayButton(int trayIndex, int loadedCount, QWidget *pare
}
void SquareTrayButton::setTrayInfo(int trayId, const QString &code, int loadedCount,
const QString &status, bool present)
const QString &status, bool databasePresent,
bool sensorPresent)
{
m_trayId = trayId;
m_sensorPresent = sensorPresent;
const QString displayCode = code.isEmpty() ? QString("托盘 %1").arg(trayId) : code;
const QString displayStatus = present ? status : "离位";
setText(QString("%1\n7 x 7\n%2 %3/49")
.arg(displayCode)
.arg(displayStatus)
.arg(loadedCount));
setEnabled(present);
setText(sensorPresent
? QString("%1\n7 x 7\n%2:%3/49")
.arg(displayCode).arg(status).arg(loadedCount)
: QString("%1\n7 x 7\n不在位:0/49").arg(displayCode));
setEnabled(databasePresent);
update();
}
@@ -51,11 +53,14 @@ void SquareTrayButton::paintEvent(QPaintEvent *event)
painter.setRenderHint(QPainter::Antialiasing, true);
const QRectF rect = QRectF(1, 1, width() - 2, height() - 2);
const QColor background = isChecked() ? QColor("#00897b")
const QColor background = !m_sensorPresent ? QColor("#90a4ae")
: isChecked() ? QColor("#00897b")
: m_planned ? QColor("#f9a825") : QColor("#eceff1");
const QColor border = isChecked() ? QColor("#004d40")
const QColor border = !m_sensorPresent ? QColor("#78909c")
: isChecked() ? QColor("#004d40")
: m_planned ? QColor("#ef6c00") : QColor("#b0bec5");
const QColor textColor = isChecked() ? QColor("#ffffff") : QColor("#263238");
const QColor textColor = !m_sensorPresent || isChecked()
? QColor("#ffffff") : QColor("#263238");
painter.setPen(QPen(border, 2));
painter.setBrush(background);
+3 -1
View File
@@ -9,7 +9,8 @@ public:
explicit SquareTrayButton(int trayIndex, int loadedCount, QWidget *parent = nullptr);
void setTrayInfo(int trayId, const QString &code, int loadedCount,
const QString &status, bool present);
const QString &status, bool databasePresent,
bool sensorPresent);
void setPlanned(bool planned);
QSize sizeHint() const override;
@@ -21,6 +22,7 @@ protected:
private:
int m_trayId;
bool m_planned;
bool m_sensorPresent;
};
#endif // SQUARETRAYBUTTON_H
+77 -34
View File
@@ -182,7 +182,7 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
{
const bool useErrorCode =
ConfigManager::instance().productionConfig().usePlcErrorCode;
if (index >= (useErrorCode ? 19 : 18)) {
if (index >= (useErrorCode ? 25 : 24)) {
finishStatusRequest(true, status, QString());
return;
}
@@ -205,23 +205,29 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
DeviceStatus nextStatus = status;
switch (index) {
case 1: nextStatus.plcRunning = value != 0; break;
case 2: nextStatus.safetyDoorClosed = value != 0; break;
case 3: nextStatus.safetyDoor1Closed = value != 0; break;
case 4: nextStatus.safetyDoor2Closed = value != 0; break;
case 5: nextStatus.safetyDoor3Closed = value != 0; break;
case 6: nextStatus.emergencyStop = value != 0; break;
case 7: nextStatus.robotIdle = value != 0; break;
case 8: nextStatus.robotRunning = value != 0; break;
case 9: nextStatus.robotAlarm = value != 0; break;
case 10: nextStatus.plcReady = value != 0; break;
case 11: nextStatus.inspectionMachineReady = value != 0; break;
case 12: nextStatus.visionReady = value != 0; break;
case 13: nextStatus.robotControlCabinetReady = value != 0; break;
case 14: nextStatus.mainControlCabinetReady = value != 0; break;
case 15: nextStatus.activeAlarm = value != 0; break;
case 16: nextStatus.currentStep = value; break;
case 17: nextStatus.checkResult = value; break;
case 18: nextStatus.errorCode = value; break;
case 2: nextStatus.trayPresent[0] = value != 0; break;
case 3: nextStatus.trayPresent[1] = value != 0; break;
case 4: nextStatus.trayPresent[2] = value != 0; break;
case 5: nextStatus.trayPresent[3] = value != 0; break;
case 6: nextStatus.trayPresent[4] = value != 0; break;
case 7: nextStatus.trayPresent[5] = value != 0; break;
case 8: nextStatus.safetyDoorClosed = value != 0; break;
case 9: nextStatus.safetyDoor1Closed = value != 0; break;
case 10: nextStatus.safetyDoor2Closed = value != 0; break;
case 11: nextStatus.safetyDoor3Closed = value != 0; break;
case 12: nextStatus.emergencyStop = value != 0; break;
case 13: nextStatus.robotIdle = value != 0; break;
case 14: nextStatus.robotRunning = value != 0; break;
case 15: nextStatus.robotAlarm = value != 0; break;
case 16: nextStatus.plcReady = value != 0; break;
case 17: nextStatus.inspectionMachineReady = value != 0; break;
case 18: nextStatus.visionReady = value != 0; break;
case 19: nextStatus.robotControlCabinetReady = value != 0; break;
case 20: nextStatus.mainControlCabinetReady = value != 0; break;
case 21: nextStatus.activeAlarm = value != 0; break;
case 22: nextStatus.currentStep = value; break;
case 23: nextStatus.checkResult = value; break;
case 24: nextStatus.errorCode = value; break;
default: break;
}
readStatusStep(index + 1, nextStatus);
@@ -236,96 +242,132 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
});
break;
case 2:
m_modbus->readCoil(addresses.safetyDoorClosed,
m_modbus->readCoil(addresses.trayPresent1,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 3:
m_modbus->readCoil(addresses.safetyDoor1Closed,
m_modbus->readCoil(addresses.trayPresent2,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 4:
m_modbus->readCoil(addresses.safetyDoor2Closed,
m_modbus->readCoil(addresses.trayPresent3,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 5:
m_modbus->readCoil(addresses.safetyDoor3Closed,
m_modbus->readCoil(addresses.trayPresent4,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 6:
m_modbus->readCoil(addresses.emergencyStop,
m_modbus->readCoil(addresses.trayPresent5,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 7:
m_modbus->readCoil(addresses.robotIdle,
m_modbus->readCoil(addresses.trayPresent6,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 8:
m_modbus->readCoil(addresses.robotRunning,
m_modbus->readCoil(addresses.safetyDoorClosed,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 9:
m_modbus->readCoil(addresses.robotAlarm,
m_modbus->readCoil(addresses.safetyDoor1Closed,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 10:
m_modbus->readCoil(addresses.plcReady,
m_modbus->readCoil(addresses.safetyDoor2Closed,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 11:
m_modbus->readCoil(addresses.inspectionMachineReady,
m_modbus->readCoil(addresses.safetyDoor3Closed,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 12:
m_modbus->readCoil(addresses.visionReady,
m_modbus->readCoil(addresses.emergencyStop,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 13:
m_modbus->readCoil(addresses.robotControlCabinetReady,
m_modbus->readCoil(addresses.robotIdle,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 14:
m_modbus->readCoil(addresses.mainControlCabinetReady,
m_modbus->readCoil(addresses.robotRunning,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 15:
m_modbus->readCoil(addresses.activeAlarm,
m_modbus->readCoil(addresses.robotAlarm,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 16:
m_modbus->readHoldingRegister(addresses.currentStep, next);
m_modbus->readCoil(addresses.plcReady,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 17:
m_modbus->readHoldingRegister(addresses.checkResult, next);
m_modbus->readCoil(addresses.inspectionMachineReady,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 18:
m_modbus->readCoil(addresses.visionReady,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 19:
m_modbus->readCoil(addresses.robotControlCabinetReady,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 20:
m_modbus->readCoil(addresses.mainControlCabinetReady,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 21:
m_modbus->readCoil(addresses.activeAlarm,
[next](bool ok, bool value, const QString &error) {
next(ok, value ? 1 : 0, error);
});
break;
case 22:
m_modbus->readHoldingRegister(addresses.currentStep, next);
break;
case 23:
m_modbus->readHoldingRegister(addresses.checkResult, next);
break;
case 24:
m_modbus->readHoldingRegister(addresses.errorCode, next);
break;
}
@@ -355,6 +397,7 @@ DeviceStatus DeviceService::simulatedStatus() const
status.robotIdle = true;
status.robotRunning = false;
status.robotAlarm = false;
for (int index = 0; index < 6; ++index) status.trayPresent[index] = true;
status.safetyDoorClosed = true;
status.emergencyStop = false;
status.inspectionMachineReady = true;
+1
View File
@@ -18,6 +18,7 @@ struct DeviceStatus
bool robotIdle = false;
bool robotRunning = false;
bool robotAlarm = false;
bool trayPresent[6] = {};
bool safetyDoorClosed = false;
bool emergencyStop = false;
bool inspectionMachineReady = false;
+2
View File
@@ -176,6 +176,8 @@ void Widget::setupMainArea(QVBoxLayout *rootLayout)
});
connect(dashboardPage, &DashboardPage::deviceStatusChanged,
devicePage, &DevicePage::updateStatus);
connect(dashboardPage, &DashboardPage::deviceStatusChanged,
rackPage, &RackPage::updateDeviceStatus);
connect(dashboardPage, &DashboardPage::deviceStatusChanged,
this, [this](const DeviceStatus &status) {
const bool offline = !status.statusValid || !status.plcConnected;