diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-03-11 11:02:24 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-03-11 11:09:40 +0100 |
| commit | 35309337aacac2eac7d7215e526bddcf7647b8cf (patch) | |
| tree | 3626e5e5e17e23122deab1bf3ade0502872873f3 /src/Xpl2Client.h | |
| download | QtXpl2-35309337aacac2eac7d7215e526bddcf7647b8cf.tar.gz QtXpl2-35309337aacac2eac7d7215e526bddcf7647b8cf.zip | |
Initial project setup: Qt 6.10.2 TCP client library for Alchemie XPL2 protocol
- Static library (src/) with QML singleton Xpl2Client for TCP communication
- Qt Quick demo app (demo/) with connection UI, command input, and response log
Diffstat (limited to 'src/Xpl2Client.h')
| -rw-r--r-- | src/Xpl2Client.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Xpl2Client.h b/src/Xpl2Client.h new file mode 100644 index 0000000..f052962 --- /dev/null +++ b/src/Xpl2Client.h @@ -0,0 +1,53 @@ +/** + * @file Xpl2Client.h + * @brief TCP client for the Alchemie XPL2 printhead protocol. + */ +#pragma once + +#include <QObject> +#include <QQmlEngine> +#include <QTcpSocket> + +class Xpl2Client : public QObject { + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + + Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged) + Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged) + Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) + +public: + explicit Xpl2Client(QObject *parent = nullptr); + + QString host() const; + void setHost(const QString &host); + + quint16 port() const; + void setPort(quint16 port); + + bool isConnected() const; + + Q_INVOKABLE void connectToServer(); + Q_INVOKABLE void disconnectFromServer(); + Q_INVOKABLE void sendCommand(const QString &command); + +signals: + void hostChanged(); + void portChanged(); + void connectedChanged(); + void responseReceived(const QString &response); + void errorOccurred(const QString &error); + void statusMessage(const QString &message); + +private slots: + void onConnected(); + void onDisconnected(); + void onReadyRead(); + void onErrorOccurred(QAbstractSocket::SocketError error); + +private: + QTcpSocket m_socket; + QString m_host = QStringLiteral("127.0.0.1"); + quint16 m_port = 5000; +}; |
