36 lines
693 B
C
36 lines
693 B
C
|
#ifndef SERIALPORT_H
|
|||
|
#define SERIALPORT_H
|
|||
|
|
|||
|
#include <QObject>
|
|||
|
#include <QThread>
|
|||
|
#include <QtSerialPort/QSerialPort>
|
|||
|
|
|||
|
class SerialPort : public QObject
|
|||
|
{
|
|||
|
Q_OBJECT
|
|||
|
public:
|
|||
|
explicit SerialPort(QObject *parent = nullptr);
|
|||
|
~SerialPort();
|
|||
|
|
|||
|
signals:
|
|||
|
void recvSerialDataSignal(const QByteArray &buf);
|
|||
|
|
|||
|
public slots:
|
|||
|
void writeData(const QString &cmd);
|
|||
|
void writeData(const QByteArray &buf);
|
|||
|
void readData();
|
|||
|
bool open();
|
|||
|
void close();
|
|||
|
void setSerialconfig(QString comName,int baud);
|
|||
|
void setSerialconfig(int baud);
|
|||
|
bool isOpen();
|
|||
|
int getBaud();
|
|||
|
|
|||
|
private:
|
|||
|
QSerialPort *serial;
|
|||
|
QThread *thread;
|
|||
|
int curBaud;
|
|||
|
};
|
|||
|
|
|||
|
#endif // SERIALPORT_H
|