#ifndef SERIALTOOL_H
#define SERIALTOOL_H


#include <QObject>
#include <QSerialPort>
#include <QPushButton>
#include <QLineEdit>
#include <QTextEdit>
#include <QByteArray>
class SerialTool : public QObject
{
    Q_OBJECT
public:
    static SerialTool* getInstance(QObject *parent = nullptr);
    SerialTool(QObject *parent = nullptr);
    ~SerialTool();
    static SerialTool* instance;
    void openSerialPort();
    void closeSerialPort();
    void readData();

    bool sendData(const QByteArray &data);
signals:
    void openCloseButtonTextChanged(const QString& text);
    void openError();
    void dataReceived(const QByteArray& data);
    void serialPortOpened(); // 新增信号

public slots:
    void handleSendDataReques(const QByteArray &data);
private:
    void setupSerialPort();
    QByteArray buffer; // 确保这里声明了 buffer 变量
    QSerialPort serialPort;
};

#endif // SERIALTOOL_H
