QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
qserialport.h
Go to the documentation of this file.
1// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
2// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#pragma once
6
7#include <QtCore/qiodevice.h>
8
9#include "qserialportglobal.h"
10
12
13class QSerialPortInfo;
15
16class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice
17{
18 Q_OBJECT
19 Q_DECLARE_PRIVATE(QSerialPort)
20
21 Q_PROPERTY(qint32 baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
22 Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged BINDABLE bindableDataBits)
23 Q_PROPERTY(Parity parity READ parity WRITE setParity NOTIFY parityChanged BINDABLE bindableParity)
24 Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged BINDABLE bindableStopBits)
25 Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl NOTIFY flowControlChanged BINDABLE
26 bindableFlowControl)
27 Q_PROPERTY(
28 bool dataTerminalReady READ isDataTerminalReady WRITE setDataTerminalReady NOTIFY dataTerminalReadyChanged)
29 Q_PROPERTY(bool requestToSend READ isRequestToSend WRITE setRequestToSend NOTIFY requestToSendChanged)
30 Q_PROPERTY(SerialPortError error READ error RESET clearError NOTIFY errorOccurred BINDABLE bindableError)
31 Q_PROPERTY(bool breakEnabled READ isBreakEnabled WRITE setBreakEnabled NOTIFY breakEnabledChanged BINDABLE
32 bindableIsBreakEnabled)
33
34 typedef int Handle;
35
36public:
38 {
39 Input = 1,
40 Output = 2,
41 AllDirections = Input | Output
42 };
43 Q_FLAG(Direction)
44 Q_DECLARE_FLAGS(Directions, Direction)
45
47 {
48 Baud1200 = 1200,
49 Baud2400 = 2400,
50 Baud4800 = 4800,
51 Baud9600 = 9600,
52 Baud19200 = 19200,
53 Baud38400 = 38400,
54 Baud57600 = 57600,
55 Baud115200 = 115200
56 };
57 Q_ENUM(BaudRate)
58
60 {
61 Data5 = 5,
62 Data6 = 6,
63 Data7 = 7,
64 Data8 = 8
65 };
66 Q_ENUM(DataBits)
67
68 enum Parity
69 {
70 NoParity = 0,
71 EvenParity = 2,
72 OddParity = 3,
73 SpaceParity = 4,
74 MarkParity = 5
75 };
76 Q_ENUM(Parity)
77
79 {
80 OneStop = 1,
81 OneAndHalfStop = 3,
82 TwoStop = 2
83 };
84 Q_ENUM(StopBits)
85
87 {
90 SoftwareControl
91 };
92 Q_ENUM(FlowControl)
93
95 {
96 NoSignal = 0x00,
97 DataTerminalReadySignal = 0x04,
98 DataCarrierDetectSignal = 0x08,
99 DataSetReadySignal = 0x10,
100 RingIndicatorSignal = 0x20,
101 RequestToSendSignal = 0x40,
102 ClearToSendSignal = 0x80,
103 SecondaryTransmittedDataSignal = 0x100,
104 SecondaryReceivedDataSignal = 0x200
105 };
106 Q_FLAG(PinoutSignal)
107 Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)
108
123 Q_ENUM(SerialPortError)
124
125 explicit QSerialPort(QObject* parent = nullptr);
126 explicit QSerialPort(const QString& name, QObject* parent = nullptr);
127 explicit QSerialPort(const QSerialPortInfo& info, QObject* parent = nullptr);
128 virtual ~QSerialPort();
129
130 void setPortName(const QString& name);
131 QString portName() const;
132
133 void setPort(const QSerialPortInfo& info);
134
135 bool open(OpenMode mode) override;
136 void close() override;
137
138 bool setBaudRate(qint32 baudRate, Directions directions = AllDirections);
139 qint32 baudRate(Directions directions = AllDirections) const;
140
141 bool setDataBits(DataBits dataBits);
142 DataBits dataBits() const;
143 QBindable<DataBits> bindableDataBits();
144
145 bool setParity(Parity parity);
146 Parity parity() const;
147 QBindable<Parity> bindableParity();
148
149 bool setStopBits(StopBits stopBits);
150 StopBits stopBits() const;
151 QBindable<StopBits> bindableStopBits();
152
153 bool setFlowControl(FlowControl flowControl);
154 FlowControl flowControl() const;
155 QBindable<FlowControl> bindableFlowControl();
156
157 bool setDataTerminalReady(bool set);
158 bool isDataTerminalReady();
159
160 bool setRequestToSend(bool set);
161 bool isRequestToSend();
162
163 PinoutSignals pinoutSignals();
164
165 bool flush();
166 bool clear(Directions directions = AllDirections);
167
168 SerialPortError error() const;
169 void clearError();
170 QBindable<SerialPortError> bindableError() const;
171
172 qint64 readBufferSize() const;
173 void setReadBufferSize(qint64 size);
174
175 bool isSequential() const override;
176
177 qint64 bytesAvailable() const override;
178 qint64 bytesToWrite() const override;
179 bool canReadLine() const override;
180
181 bool waitForReadyRead(int msecs = 30000) override;
182 bool waitForBytesWritten(int msecs = 30000) override;
183
184 bool setBreakEnabled(bool set = true);
185 bool isBreakEnabled() const;
186 QBindable<bool> bindableIsBreakEnabled();
187
188 Handle handle() const;
189
190Q_SIGNALS:
191 void baudRateChanged(qint32 baudRate, QSerialPort::Directions directions);
197 void requestToSendChanged(bool set);
199 void breakEnabledChanged(bool set);
200
201protected:
202 qint64 readData(char* data, qint64 maxSize) override;
203 qint64 readLineData(char* data, qint64 maxSize) override;
204 qint64 writeData(const char* data, qint64 maxSize) override;
205
206private:
207 Q_DISABLE_COPY(QSerialPort)
208};
209
210Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::Directions)
211Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::PinoutSignals)
212
213QT_END_NAMESPACE
Error error
Provides information about existing serial ports.
Provides functions to access serial ports.
Definition qserialport.h:17
void requestToSendChanged(bool set)
This signal is emitted after the state (high or low) of the line signal RTS has been changed.
void dataTerminalReadyChanged(bool set)
This signal is emitted after the state (high or low) of the line signal DTR has been changed.
void baudRateChanged(qint32 baudRate, QSerialPort::Directions directions)
This signal is emitted after the baud rate has been changed.
void parityChanged(QSerialPort::Parity parity)
This signal is emitted after the parity checking mode has been changed.
void errorOccurred(QSerialPort::SerialPortError error)
DataBits
This enum describes the number of data bits used.
Definition qserialport.h:60
void breakEnabledChanged(bool set)
void stopBitsChanged(QSerialPort::StopBits stopBits)
This signal is emitted after the number of stop bits in a frame has been changed.
void dataBitsChanged(QSerialPort::DataBits dataBits)
This signal is emitted after the data bits in a frame has been changed.
Parity
This enum describes the parity scheme used.
Definition qserialport.h:69
SerialPortError
This enum describes the errors that may be contained by the QSerialPort::error property.
@ UnsupportedOperationError
PinoutSignal
This enum describes the possible RS-232 pinout signals.
Definition qserialport.h:95
void flowControlChanged(QSerialPort::FlowControl flowControl)
This signal is emitted after the flow control mode has been changed.
Direction
This enum describes the possible directions of the data transmission.
Definition qserialport.h:38
BaudRate
This enum describes the baud rate which the communication device operates with.
Definition qserialport.h:47
StopBits
This enum describes the number of stop bits used.
Definition qserialport.h:79
FlowControl
This enum describes the flow control used.
Definition qserialport.h:87
QT_BEGIN_NAMESPACE
#define Q_SERIALPORT_EXPORT