btnserialtool.h 764 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef BTNSERIALTOOL_H
  2. #define BTNSERIALTOOL_H
  3. #include <QObject>
  4. #include <QSerialPort>
  5. #include <QPushButton>
  6. #include <QLineEdit>
  7. #include <QTextEdit>
  8. #include <QByteArray>
  9. class BtnSerialTool: public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. BtnSerialTool(QObject *parent = nullptr);
  14. void openSerialPort();
  15. void closeSerialPort();
  16. void readData();
  17. bool sendData(const QByteArray &data);
  18. signals:
  19. void openCloseButtonTextChanged(const QString& text);
  20. void openError();
  21. void dataReceived(const QByteArray& data);
  22. public slots:
  23. void handleSendDataReques(const QByteArray &data);
  24. private:
  25. void setupSerialPort();
  26. QByteArray buffer; // 确保这里声明了 buffer 变量
  27. QSerialPort serialPort;
  28. };
  29. #endif // BTNSERIALTOOL_H