blob: 33a8a2652516a8a726f6de803fa2a0acab75d469 (
plain)
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
|
#pragma once
#include <QSerialPort>
#include <QString>
#include <vector>
using std::string;
using std::vector;
/** @brief manage asynchronous serial connection */
class CDSerialConnector {
public:
CDSerialConnector();
virtual ~CDSerialConnector();
/** @brief get list of available serial ports */
static vector<string> get_ports();
/** @brief open serial port */
virtual void connect(string port);
/** @brief close serial port */
virtual void disconnect();
/** @brief write to serial port */
virtual void write(QByteArray msg);
/** @brief get last message */
virtual QByteArray get_data();
/** @brief get current port name */
virtual string get_port();
private:
/** @brief executed when new data is received */
virtual void action();
QSerialPort *_serial = nullptr;
QByteArray _msg;
};
/** @brief global pointer to serial connector, initialized in CDMainWindow */
extern CDSerialConnector *g_cd_serial;
|