btnserialtool.h 780 B

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