proto-debuger/protoDebuger/serialcontroller.h

55 lines
1.3 KiB
C++

#ifndef SERIALCONTROLLER_H
#define SERIALCONTROLLER_H
#include <QObject>
#include <QList>
#include "qserialproto.h"
#include <vector>
#include <QDebug>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#define OK 0
#define NULLPOINTER -1
/*
* 数据传输方式
data -> controler -> proto -> listener
*/
using namespace std;
class SerialController : public QObject
{
Q_OBJECT
public slots:
void ReadyRead();
void AboutClose();
public:
typedef enum {
ERROR_OPEN = -1,
ERROR_SEND = -2,
}SerialError;
explicit SerialController(QObject *parent = nullptr);
int OpenSerial(QString port,QString baudRate, QString dataBits, QString stopBits, QString flow);
int CloseSerial();
QList<QSerialPortInfo> GetPorts();
int SetProto(QSerialProto *);
int SendData(uint8_t *,uint8_t len);
void GetSetting(QString baudRate, QString dataBits, QString stopBits, QString flow);
signals:
private:
QList<QSerialPortInfo> mPorts;
bool mConnected;
QSerialPort *mCurrentPort;
QSerialProto *mProto;
QString mPortName;
uint32_t mBaudrate;
QSerialPort::DataBits mDataBits;
QSerialPort::Parity mParity;
QSerialPort::StopBits mStopBits;
QSerialPort::FlowControl mFlow;
};
#endif // SERIALCONTROLLER_H