-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathQAsyncSerial.h
executable file
·87 lines (70 loc) · 1.77 KB
/
QAsyncSerial.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Author: Terraneo Federico
* Distributed under the Boost Software License, Version 1.0.
*/
#ifndef QASYNCSERIAL_H
#define QASYNCSERIAL_H
#include <QObject>
#include <memory>
class QAsyncSerialImpl;
/**
* Asynchronous serial class that integrates well with Qt GUI applictions.
*/
class QAsyncSerial : public QObject
{
Q_OBJECT
public:
/**
* Default constructor
*/
QAsyncSerial();
/**
* Constructor. Opens a serial port
* \param devname port name, like "/dev/ttyUSB0" or "COM4"
* \param baudrate port baud rate, example 115200
* Format is 8N1, flow control is disabled.
*/
QAsyncSerial(QString devname, unsigned int baudrate);
/**
* Opens a serial port
* \param devname port name, like "/dev/ttyUSB0" or "COM4"
* \param baudrate port baud rate, example 115200
* Format is 8N1, flow control is disabled.
*/
void open(QString devname, unsigned int baudrate);
/**
* Closes a serial port.
*/
void close();
/**
* \return true if the port is open
*/
bool isOpen();
/**
* \return true if any error
*/
bool errorStatus();
/**
* Write a string to the serial port
*/
void write(QString data);
/**
* Destructor
*/
~QAsyncSerial();
signals:
/**
* Signal called when data is received from the serial port.
* This signal is line based, data is grouped by line and a signal
* is emitted for each line.
* \param data the line of text just received.
*/
void lineReceived(QString data);
private:
/**
* Called when data is received
*/
void readCallback(const char *data, size_t size);
std::shared_ptr<QAsyncSerialImpl> pimpl; ///< Pimpl idiom
};
#endif // QASYNCSERIAL_H