1/****************************************************************************
2**
3** Copyright (C) 2011-2012 Denis Shienkov <denis.shienkov@gmail.com>
4** Copyright (C) 2011 Sergey Belyashov <Sergey.Belyashov@gmail.com>
5** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
6** Contact: https://www.qt.io/licensing/
7**
8** This file is part of the QtSerialPort module of the Qt Toolkit.
9**
10** $QT_BEGIN_LICENSE:LGPL$
11** Commercial License Usage
12** Licensees holding valid commercial Qt licenses may use this file in
13** accordance with the commercial license agreement provided with the
14** Software or, alternatively, in accordance with the terms contained in
15** a written agreement between you and The Qt Company. For licensing terms
16** and conditions see https://www.qt.io/terms-conditions. For further
17** information use the contact form at https://www.qt.io/contact-us.
18**
19** GNU Lesser General Public License Usage
20** Alternatively, this file may be used under the terms of the GNU Lesser
21** General Public License version 3 as published by the Free Software
22** Foundation and appearing in the file LICENSE.LGPL3 included in the
23** packaging of this file. Please review the following information to
24** ensure the GNU Lesser General Public License version 3 requirements
25** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** GNU General Public License Usage
28** Alternatively, this file may be used under the terms of the GNU
29** General Public License version 2.0 or (at your option) the GNU General
30** Public license version 3 or any later version approved by the KDE Free
31** Qt Foundation. The licenses are as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
33** included in the packaging of this file. Please review the following
34** information to ensure the GNU General Public License requirements will
35** be met: https://www.gnu.org/licenses/gpl-2.0.html and
36** https://www.gnu.org/licenses/gpl-3.0.html.
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qserialportinfo.h"
43#include "qserialportinfo_p.h"
44#include "qserialport.h"
45#include "qserialport_p.h"
46
47QT_BEGIN_NAMESPACE
48
49
50/*!
51 \class QSerialPortInfo
52
53 \brief Provides information about existing serial ports.
54
55 \ingroup serialport-main
56 \inmodule QtSerialPort
57 \since 5.1
58
59 Use the static functions to generate a list of QSerialPortInfo
60 objects. Each QSerialPortInfo object in the list represents a single
61 serial port and can be queried for the port name, system location,
62 description, and manufacturer. The QSerialPortInfo class can also be
63 used as an input parameter for the setPort() method of the QSerialPort
64 class.
65
66 \sa QSerialPort
67*/
68
69/*!
70 Constructs an empty QSerialPortInfo object.
71
72 \sa isNull()
73*/
74QSerialPortInfo::QSerialPortInfo()
75{
76}
77
78/*!
79 Constructs a copy of \a other.
80*/
81QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)
82 : d_ptr(other.d_ptr ? new QSerialPortInfoPrivate(*other.d_ptr) : nullptr)
83{
84}
85
86/*!
87 Constructs a QSerialPortInfo object from serial \a port.
88*/
89QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
90 : QSerialPortInfo(port.portName())
91{
92}
93
94/*!
95 Constructs a QSerialPortInfo object from serial port \a name.
96
97 This constructor finds the relevant serial port among the available ones
98 according to the port name \a name, and constructs the serial port info
99 instance for that port.
100*/
101QSerialPortInfo::QSerialPortInfo(const QString &name)
102{
103 const auto infos = QSerialPortInfo::availablePorts();
104 for (const QSerialPortInfo &info : infos) {
105 if (name == info.portName()) {
106 *this = info;
107 break;
108 }
109 }
110}
111
112QSerialPortInfo::QSerialPortInfo(const QSerialPortInfoPrivate &dd)
113 : d_ptr(new QSerialPortInfoPrivate(dd))
114{
115}
116
117/*!
118 Destroys the QSerialPortInfo object. References to the values in the
119 object become invalid.
120*/
121QSerialPortInfo::~QSerialPortInfo()
122{
123}
124
125/*!
126 Swaps QSerialPortInfo \a other with this QSerialPortInfo. This operation is
127 very fast and never fails.
128*/
129void QSerialPortInfo::swap(QSerialPortInfo &other)
130{
131 d_ptr.swap(other&: other.d_ptr);
132}
133
134/*!
135 Sets the QSerialPortInfo object to be equal to \a other.
136*/
137QSerialPortInfo& QSerialPortInfo::operator=(const QSerialPortInfo &other)
138{
139 QSerialPortInfo(other).swap(other&: *this);
140 return *this;
141}
142
143/*!
144 Returns the name of the serial port.
145
146 \sa systemLocation()
147*/
148QString QSerialPortInfo::portName() const
149{
150 Q_D(const QSerialPortInfo);
151 return !d ? QString() : d->portName;
152}
153
154/*!
155 Returns the system location of the serial port.
156
157 \sa portName()
158*/
159QString QSerialPortInfo::systemLocation() const
160{
161 Q_D(const QSerialPortInfo);
162 return !d ? QString() : d->device;
163}
164
165/*!
166 Returns the description string of the serial port,
167 if available; otherwise returns an empty string.
168
169 \sa manufacturer(), serialNumber()
170*/
171QString QSerialPortInfo::description() const
172{
173 Q_D(const QSerialPortInfo);
174 return !d ? QString() : d->description;
175}
176
177/*!
178 Returns the manufacturer string of the serial port,
179 if available; otherwise returns an empty string.
180
181 \sa description(), serialNumber()
182*/
183QString QSerialPortInfo::manufacturer() const
184{
185 Q_D(const QSerialPortInfo);
186 return !d ? QString() : d->manufacturer;
187}
188
189/*!
190 \since 5.3
191
192 Returns the serial number string of the serial port,
193 if available; otherwise returns an empty string.
194
195 \note The serial number may include letters.
196
197 \sa description(), manufacturer()
198*/
199QString QSerialPortInfo::serialNumber() const
200{
201 Q_D(const QSerialPortInfo);
202 return !d ? QString() : d->serialNumber;
203}
204
205/*!
206 Returns the 16-bit vendor number for the serial port, if available;
207 otherwise returns zero.
208
209 \sa hasVendorIdentifier(), productIdentifier(), hasProductIdentifier()
210*/
211quint16 QSerialPortInfo::vendorIdentifier() const
212{
213 Q_D(const QSerialPortInfo);
214 return !d ? 0 : d->vendorIdentifier;
215}
216
217/*!
218 Returns the 16-bit product number for the serial port, if available;
219 otherwise returns zero.
220
221 \sa hasProductIdentifier(), vendorIdentifier(), hasVendorIdentifier()
222*/
223quint16 QSerialPortInfo::productIdentifier() const
224{
225 Q_D(const QSerialPortInfo);
226 return !d ? 0 : d->productIdentifier;
227}
228
229/*!
230 Returns \c true if there is a valid \c 16-bit vendor number present; otherwise
231 returns \c false.
232
233 \sa vendorIdentifier(), productIdentifier(), hasProductIdentifier()
234*/
235bool QSerialPortInfo::hasVendorIdentifier() const
236{
237 Q_D(const QSerialPortInfo);
238 return !d ? false : d->hasVendorIdentifier;
239}
240
241/*!
242 Returns \c true if there is a valid \c 16-bit product number present; otherwise
243 returns \c false.
244
245 \sa productIdentifier(), vendorIdentifier(), hasVendorIdentifier()
246*/
247bool QSerialPortInfo::hasProductIdentifier() const
248{
249 Q_D(const QSerialPortInfo);
250 return !d ? false : d->hasProductIdentifier;
251}
252
253/*!
254 \fn bool QSerialPortInfo::isNull() const
255
256 Returns whether this QSerialPortInfo object holds a
257 serial port definition.
258
259 \sa isBusy()
260*/
261
262#if QT_DEPRECATED_SINCE(5, 6)
263/*!
264 \fn bool QSerialPortInfo::isBusy() const
265 \obsolete
266
267 Returns \c true if serial port is busy;
268 otherwise returns \c false.
269
270 \sa isNull()
271*/
272#endif // QT_DEPRECATED_SINCE(5, 6)
273
274#if QT_DEPRECATED_SINCE(5, 2)
275/*!
276 \fn bool QSerialPortInfo::isValid() const
277 \obsolete
278
279 Returns \c true if serial port is present on system;
280 otherwise returns \c false.
281
282 \sa isNull(), isBusy()
283*/
284#endif // QT_DEPRECATED_SINCE(5, 2)
285
286/*!
287 \fn QList<qint32> QSerialPortInfo::standardBaudRates()
288
289 Returns a list of available standard baud rates supported
290 by the target platform.
291*/
292QList<qint32> QSerialPortInfo::standardBaudRates()
293{
294 return QSerialPortPrivate::standardBaudRates();
295}
296
297/*!
298 \fn QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
299
300 Returns a list of available serial ports on the system.
301*/
302
303QT_END_NAMESPACE
304

source code of qtserialport/src/serialport/qserialportinfo.cpp