添加状态点位表
This commit is contained in:
+86
-10
@@ -138,19 +138,28 @@ void DeviceService::requestStatus(const StatusCallback &callback)
|
||||
}
|
||||
|
||||
void DeviceService::finishStatusRequest(bool success,
|
||||
const DeviceStatus &status,
|
||||
const QString &error)
|
||||
const DeviceStatus &status,
|
||||
const QString &error)
|
||||
{
|
||||
DeviceStatus finalStatus = status;
|
||||
finalStatus.statusValid = success;
|
||||
if (success) {
|
||||
finalStatus.safetyDoorClosed = finalStatus.safetyDoorClosed
|
||||
&& finalStatus.safetyDoor1Closed
|
||||
&& finalStatus.safetyDoor2Closed
|
||||
&& finalStatus.safetyDoor3Closed;
|
||||
}
|
||||
|
||||
m_statusRequestPending = false;
|
||||
const QList<StatusCallback> callbacks = m_statusCallbacks;
|
||||
m_statusCallbacks.clear();
|
||||
emit statusChanged(status);
|
||||
emit statusChanged(finalStatus);
|
||||
if (!success && !error.isEmpty()) {
|
||||
emit communicationError(error);
|
||||
}
|
||||
for (const StatusCallback &callback : callbacks) {
|
||||
if (callback) {
|
||||
callback(success, status, error);
|
||||
callback(success, finalStatus, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +168,7 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
|
||||
{
|
||||
const bool useErrorCode =
|
||||
ConfigManager::instance().productionConfig().usePlcErrorCode;
|
||||
if (index >= (useErrorCode ? 7 : 6)) {
|
||||
if (index >= (useErrorCode ? 15 : 14)) {
|
||||
finishStatusRequest(true, status, QString());
|
||||
return;
|
||||
}
|
||||
@@ -185,9 +194,17 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
|
||||
case 1: nextStatus.robotReady = value != 0; break;
|
||||
case 2: nextStatus.safetyDoorClosed = value != 0; break;
|
||||
case 3: nextStatus.emergencyStop = value != 0; break;
|
||||
case 4: nextStatus.currentStep = value; break;
|
||||
case 5: nextStatus.checkResult = value; break;
|
||||
case 6: nextStatus.errorCode = value; break;
|
||||
case 4: nextStatus.inspectionMachineReady = value != 0; break;
|
||||
case 5: nextStatus.visionReady = value != 0; break;
|
||||
case 6: nextStatus.robotControlCabinetReady = value != 0; break;
|
||||
case 7: nextStatus.mainControlCabinetReady = value != 0; break;
|
||||
case 8: nextStatus.safetyDoor1Closed = value != 0; break;
|
||||
case 9: nextStatus.safetyDoor2Closed = value != 0; break;
|
||||
case 10: nextStatus.safetyDoor3Closed = value != 0; break;
|
||||
case 11: nextStatus.activeAlarm = value != 0; break;
|
||||
case 12: nextStatus.currentStep = value; break;
|
||||
case 13: nextStatus.checkResult = value; break;
|
||||
case 14: nextStatus.errorCode = value; break;
|
||||
default: break;
|
||||
}
|
||||
readStatusStep(index + 1, nextStatus);
|
||||
@@ -220,14 +237,64 @@ void DeviceService::readStatusStep(int index, const DeviceStatus &status)
|
||||
});
|
||||
break;
|
||||
case 4:
|
||||
m_modbus->readHoldingRegister(addresses.currentStep, next);
|
||||
m_modbus->readCoil(addresses.inspectionMachineReady,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 5:
|
||||
m_modbus->readHoldingRegister(addresses.checkResult, next);
|
||||
m_modbus->readCoil(addresses.visionReady,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 6:
|
||||
m_modbus->readCoil(addresses.robotControlCabinetReady,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 7:
|
||||
m_modbus->readCoil(addresses.mainControlCabinetReady,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 8:
|
||||
m_modbus->readCoil(addresses.safetyDoor1Closed,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 9:
|
||||
m_modbus->readCoil(addresses.safetyDoor2Closed,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 10:
|
||||
m_modbus->readCoil(addresses.safetyDoor3Closed,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 11:
|
||||
m_modbus->readCoil(addresses.activeAlarm,
|
||||
[next](bool ok, bool value, const QString &error) {
|
||||
next(ok, value ? 1 : 0, error);
|
||||
});
|
||||
break;
|
||||
case 12:
|
||||
m_modbus->readHoldingRegister(addresses.currentStep, next);
|
||||
break;
|
||||
case 13:
|
||||
m_modbus->readHoldingRegister(addresses.checkResult, next);
|
||||
break;
|
||||
case 14:
|
||||
if (useErrorCode) {
|
||||
m_modbus->readHoldingRegister(addresses.errorCode, next);
|
||||
} else {
|
||||
finishStatusRequest(true, status, QString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -250,11 +317,20 @@ void DeviceService::pollStatus()
|
||||
DeviceStatus DeviceService::simulatedStatus() const
|
||||
{
|
||||
DeviceStatus status;
|
||||
status.statusValid = true;
|
||||
status.plcConnected = true;
|
||||
status.plcReady = true;
|
||||
status.robotReady = true;
|
||||
status.safetyDoorClosed = true;
|
||||
status.emergencyStop = false;
|
||||
status.inspectionMachineReady = true;
|
||||
status.visionReady = true;
|
||||
status.robotControlCabinetReady = true;
|
||||
status.mainControlCabinetReady = true;
|
||||
status.safetyDoor1Closed = true;
|
||||
status.safetyDoor2Closed = true;
|
||||
status.safetyDoor3Closed = true;
|
||||
status.activeAlarm = false;
|
||||
status.currentStep = 0;
|
||||
status.checkResult = 0;
|
||||
return status;
|
||||
|
||||
Reference in New Issue
Block a user