12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef SERIALTOOL_H
- #define SERIALTOOL_H
- #include <QObject>
- #include <QSerialPort>
- #include <QPushButton>
- #include <QLineEdit>
- #include <QTextEdit>
- #include <QByteArray>
- #include <QMutex>
- class SerialTool : public QObject
- {
- Q_OBJECT
- public:
- static SerialTool* getInstance(QObject *parent = nullptr, bool* success = nullptr);
- SerialTool(QObject *parent = nullptr);
- ~SerialTool();
- static SerialTool* instance;
- void setupSerialPort();
- void openSerialPort();
- void closeSerialPort();
- void readData();
- bool sendData(const QByteArray &data);
- void releaseInstance();
- bool isInUse = false;
- bool getIsInUse();
- signals:
- void openCloseButtonTextChanged(const QString& text);
- void openError();
- void dataReceived(const QByteArray& data);
- void serialPortOpened(); // 新增信号
- // 新增三个信号
- void disableButtonReceived();
- void buttonPressedReceived();
- void enableButtonReceived();
- public slots:
- void handleSendDataReques(const QByteArray &data);
- private:
- QByteArray buffer; // 确保这里声明了 buffer 变量
- QSerialPort serialPort;
- static QMutex globalMutex;
- };
- #endif // SERIALTOOL_H
|