-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_port.h
63 lines (55 loc) · 1.52 KB
/
serial_port.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* qCommTest - Serial Communication Test Tool
* Version : 1.0
* Date : 20.11.2017
* Author : Eray Ozturk | github.com/diffstorm
*/
#ifndef SERIAL_PORT_H
#define SERIAL_PORT_H
#include <QDebug>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QByteArray>
#include <QTimer>
#include <QtCore>
class serial_port : public QObject
{
Q_OBJECT
public:
explicit serial_port(QObject *parent = nullptr);
~serial_port();
QList<QString> Scan();
void Configure(qint32 rate, QSerialPort::DataBits bits, QSerialPort::FlowControl flow, QSerialPort::Parity parity, QSerialPort::StopBits stopBits);
bool Open(QString);
bool isOpen();
bool Write(const QByteArray &);
QByteArray Read();
void Close();
qint64 getBaudTimeout(qint64);
qint64 getReceivedTime();
qint64 getSentTime();
signals:
void dataReceived();
void logMessage(const QString &);
public slots:
private slots:
void onBytesWritten(qint64);
void onReadyRead();
void onTimeoutTX();
void onTimeoutRX();
void onError(QSerialPort::SerialPortError);
private:
void Log(const QString &);
void setBaudTimeout(qint64, qint8);
void waitForBytesWritten();
QSerialPort *m_serialPort = nullptr;
QByteArray m_readData;
QByteArray m_writeData;
qint64 m_bytesWritten = 0;
QTimer m_timer_tx;
QTimer m_timer_rx;
qint64 m_dataReceivedAt;
qint64 m_dataSentAt;
qint64 m_baudtimeout;
};
#endif // SERIAL_PORT_H