3
3
4
4
#include < QCoreApplication>
5
5
#include < QtSerialPort/QSerialPort>
6
+ #include < QtSerialPort/QSerialPortInfo>
6
7
7
8
8
9
int main (int argc, char *argv[])
9
10
{
10
11
QCoreApplication coreApplication (argc, argv);
11
12
12
- QSerialPort serial;
13
+ std::cout << " * Number of serial ports available: " << QSerialPortInfo::availablePorts ().count () << std::endl;
14
+
13
15
QString port (" COM6" );
16
+ std::cout << " * Trying to find " << port.toStdString () << " ..." << std::endl;
17
+
18
+
19
+ for (int i = 0 ; i < QSerialPortInfo::availablePorts ().count (); i++)
20
+ {
21
+ QSerialPortInfo serial_info = QSerialPortInfo::availablePorts ()[i];
22
+ if (port == serial_info.portName ())
23
+ {
24
+ std::cout << " * OK, found it: " << serial_info.portName ().toStdString () << std::endl;
25
+ std::cout << " * Location: " << serial_info.systemLocation ().toStdString () << std::endl;
26
+ std::cout << " * Description: " << serial_info.description ().toStdString () << std::endl;
27
+ std::cout << " * Manufacturer: " << serial_info.manufacturer ().toStdString () << std::endl;
28
+ std::cout << " * Vendor Identifier: " << (serial_info.hasVendorIdentifier () ?
29
+ QString::number (serial_info.vendorIdentifier ()).toStdString () :
30
+ " " ) << std::endl;
31
+ std::cout << " * Product Identifier: " << (serial_info.hasProductIdentifier () ?
32
+ QString::number (serial_info.productIdentifier ()).toStdString () :
33
+ " " ) << std::endl;
34
+ std::cout << " * Busy: " << (serial_info.isBusy () ? " Yes" : " No" ) << std::endl;
35
+ }
36
+ }
37
+
38
+ QSerialPort serial;
14
39
serial.setPortName (port);
15
40
serial.setBaudRate (QSerialPort::Baud9600);
16
41
serial.setDataBits (QSerialPort::Data8);
@@ -26,6 +51,7 @@ int main(int argc, char *argv[])
26
51
}
27
52
28
53
SerialPortReader reader (&serial);
54
+ std::cout << " * Output:" << std::endl;
29
55
30
56
return coreApplication.exec ();
31
57
}
0 commit comments