QtSerialPort
https://qt-project.org/wiki/QtSerialPort
http://qt-project.org/doc/qt-5/qserialport.html
Currently, the module API contains two classes: QSerialPort and QSerialPortInfo
QSerialPort is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.
QSerialPortInfo is a helper class. It provides information on the available serial ports on the system.
Below is a simple example of main.cpp :
-
#include <QtCore/QCoreApplication>
-
#include <QtCore/QDebug>
-
-
#include <QtSerialPort/QSerialPort>
-
#include <QtSerialPort/QSerialPortInfo>
-
QT_USE_NAMESPACE
-
int main(int argc, char *argv[])
-
{
-
// Example use QSerialPortInfo
-
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
-
qDebug() << “Name : “ << info.portName();
-
qDebug() << “Description : “ << info.description();
-
qDebug() << “Manufacturer: “ << info.manufacturer();
-
// Example use QSerialPort
-
QSerialPort serial;
-
serial.setPort(info);
-
serial.close();
-
}
-
return a.exec();
-
}
Note:
CONFIG += serial port
QT += serialport
must be the first or second line in your .pro file.
.
QextSerialPort *port = new QextSerialPort(<portname>, <Querymode>);
to add the setting like databit, stopbit, etc syntax is as follows:
port->setBaudRate(BAUD_9600);
port->setStopBit();
port->setDataBit(); etc..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.