#ifndef DEVICESERVICE_H #define DEVICESERVICE_H #include #include #include struct DeviceStatus { bool plcConnected = false; bool plcReady = false; bool robotReady = false; bool safetyDoorClosed = false; bool emergencyStop = false; quint16 currentStep = 0; quint16 checkResult = 0; quint16 errorCode = 0; }; Q_DECLARE_METATYPE(DeviceStatus) class QTimer; class DeviceService : public QObject { Q_OBJECT public: static DeviceService &instance(); 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); 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); QTimer *m_pollTimer; }; #endif // DEVICESERVICE_H