From 35309337aacac2eac7d7215e526bddcf7647b8cf Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 11 Mar 2026 11:02:24 +0100 Subject: 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 --- src/Xpl2Client.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Xpl2Client.h (limited to 'src/Xpl2Client.h') 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 +#include +#include + +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; +}; -- cgit v1.2.3