-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialworker.h
53 lines (39 loc) · 963 Bytes
/
serialworker.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
#ifndef SERIALWORKER_H
#define SERIALWORKER_H
#include <QObject>
#include <QDebug>
#include <QByteArray>
#include <QTimer>
#include <QThread>
#include <QDateTime>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QTextStream>
#include <QCoreApplication>
#include <QFile>
#include <QStringList>
#define PACKET_BEGIN 0xf0
#define PACKET_END 0xf7
QT_USE_NAMESPACE
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
class SerialWorker : public QObject
{
Q_OBJECT
public:
SerialWorker(QObject *parent = 0);
QByteArray read();
void write(QByteArray writeData);
private slots:
void handleError(QSerialPort::SerialPortError error);
void handleReadTimeout();
void handleReadyRead();
Q_SIGNALS:
void dataReceived(QByteArray data);
private:
QSerialPort *m_serialPort;
QByteArray m_readData;
QTimer m_timerRead;
QTextStream m_standardOutput;
};
#endif // SERIALWORKER_H