#ifndef SERIALUI_H
#define SERIALUI_H

#include <QObject>
#include <QMutex>
#include "serialport.h"

class SerialUi : public QObject
{
    Q_OBJECT
    //Q_PROPERTY(QString portStatus  NOTIFY portStatusChange)
public:
    explicit SerialUi(QObject *parent = nullptr);
     bool serialConnect(QString port,QString baudrate,QString databits,QString parity,QString stopbits);
     void serialWrite(QByteArray sendData);
     void onlyWrite(QByteArray sendData);
     void closeConnect();
     QByteArray  serialWriteReponse(QByteArray sendData);


public slots:
    void receivePortStatus(bool status);
    void receiveData(QByteArray data);
    void receiveCrcError();
    void receiveTimeout();


signals:
    void spy();
    void receiveRawDataChange(QList<int> data);
    void portStatusChange(bool status);
    void receiveDataChange(QString data);
    void sendConnect(QString port,QString baudrate,QString databits,QString parity,QString stopbits);
    void sendWrite(QByteArray sendData);
    void sendOnlyWrite(QByteArray sendData);
    void sendClose();
    void sendInit();
    void timeout();
    void checkError();



private:
    SerialPort *mSerialPort;
    QMutex mutex;
};

#endif // SERIALUI_H
