![Qt Serial Port Communication Example Qt Serial Port Communication Example](http://processors.wiki.ti.com/images/d/da/Sitara_Linux_QT_options_add_device.png)
Serial to QML Communication In order for your microcontroller to communicate with the QML Viewer (a tool for loading QML documents that makes it easy to quickly develop and debug QML applications) messages being sent need to be translated.
Introduction QtSerialPort is a Qt module that provides support for serial ports such as those that follow the RS-232 standard. Serial port modules for Qt have existed for some time, going back at least as far as QExtSerialPort under Qt version 2, but none of them were officially part of Qt. QtSerialPort originated from the third-party library QSerialDevice and was subsequently made part of the Qt project.
It officially becomes part of Qt with the 5.1.0 release. QtSerialPort supports Qt versions 4 and 5.
With versions of Qt prior to 5.1.0 you can get the source code separately from. The module supports most 32 and 64-bit versions of Microsoft Windows, Linux, Mac OS X, and POSIX-compatible systems such as UNIXes. There is partial support for Windows CE and Symbian but these aren't likely to be actively supported in future since Qt 5 does not support them. Using It The module provides two main classes: QSerialPort and QSerialPortInfo.
To use the module with Qt 5 add this line to your qmake project file. QT + = serialport You can then include the header files.
There is quite good documentation for the classes. You can view it from Qt Assistant or on-line (once Qt 5.1.0 is released). APIs The QSerialPortInfo class provides information about a serial port on the system.
You can create a QSerialPortInfo object by specifying a device name or an existing QSerialPort object. You can also get a list of QSerialPort objects for all serial ports by calling the static method availablePorts(). Once you have a QSerialPortInfo object you can call various methods to get information such as the port's name, location, description, and manufacturer. QSerialPort is the class used for communication. It inherits from QIODevice, the base class of all I/O devices in Qt, including files, buffers, and TCP and UDP sockets. This allows you to leverage your knowledge of input/output in Qt and use it with any class that operates on a QIODevice, like the XML classes.
The QSerialPort class was modelled on the functionality and behavior of the QAbstractSocket class, so if you have used network sockets with Qt it should be familiar to you. The API documentation describes the class in detail. You can use the serial port in blocking or non-blocking modes. Note that the serial port is always opened for exclusive access so no other process or thread can access the opened serial port. To maintain portability across platforms more advanced features such as setting timeouts and delays are not provided.
The module comes with example applications that illustrate blocking and non-blocking I/O and how to get and display the serial port information. Here is a code example that displays information about each port found. It uses both the QSerialPortInfo and QSerialPort classes. It is similar to the 'cenumerator' example that comes with the source distribution. Number of serial ports: 1 Port: 'ttyUSB0' Location: '/dev/ttyUSB0' Description: 'USB-Serial Controller' Manufacturer: 'Prolific Technology Inc.'