76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#ifndef DEVICESERVICE_H
|
|
#define DEVICESERVICE_H
|
|
|
|
#include <QString>
|
|
#include <QtGlobal>
|
|
#include <QObject>
|
|
|
|
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:
|
|
enum ProductionAction
|
|
{
|
|
RackPick,
|
|
FrontLoad,
|
|
Inspect,
|
|
FrontUnload,
|
|
Flip,
|
|
BackLoad,
|
|
BackUnload,
|
|
RackPlace
|
|
};
|
|
|
|
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);
|
|
bool setInspectionMode(const QString &mode, QString *error = nullptr);
|
|
bool executeProductionAction(ProductionAction action, int trayNo,
|
|
int slotNo, 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
|