Qt Serial Port: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Improve some docs about Abdroid support)
 
(63 intermediate revisions by 9 users not shown)
Line 1: Line 1:
'''English''' | [[QtSerialPort German|Deutsch]] | [[QtSerialPort Russian|Русский]] | [[QtSerialPort Polish|Polski]] | [[QtSerialPort Dutch|Nederlands]] | [[QtSerialPort Portuguese|Português]] | [[QtSerialPort Spanish|Español]] | [[QtSerialPort Ukrainian|Українською]] | [[QtSerialPort Persian|فارسی]] | [[QtSerialPort Arabic|عربي]] | [[QtSerialPort Korean|한국어]] | [[QtSerialPort Finnish|Suomi]] | [[Wiki-Home-Catalan|Català]] | [[Wiki-Home-Italian|Italiano]] | [[QtSerialPort Japanese|日本語]] | [[QtSerialPort French|Français]] | [[Wiki-Home-Hungarian|Magyar]] | [[QtSerialPort Kannada|ಕನ್ನಡ]] | [[QtSerialPort Hindi|हिन्दी]] | [[QtSerialPort Thai|ภาษาไทย]] | [[QtSerialPort SimplifiedChinese|简体中文]] | [[QtSerialPort Bulgarian|Български]]
{{LangSwitch}}
__TOC__


=QtSerialPort=
'''NOTE: As of Qt 5.1, Qt Serial Port is now officially part of Qt. You no longer need to build Qt Serial Port manually; simply install Qt 5.1 or later and go to section [[Qt Serial Port#Usage|Usage]]'''


'''''Note''': this page is work in progress, needs review.''
== Brief description ==


==News==
The [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] module is an add-on module for the Qt5 library, providing a single interface for both hardware and virtual serial ports.


Fill up
'''''Note:''' Also added support for Qt4.''
 
Serial interfaces, due to their simplicity and reliability, are still popular in some industries like the development of embedded systems, robotics, etc.
 
Using the [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.
 
== Functionality ==
 
Currently, the module API contains two classes: [http://doc.qt.io/qt-5/qserialport.html QSerialPort] and [http://doc.qt.io/qt-5/qserialportinfo.html QSerialPortInfo].
 
=== QSerialPort ===
 
[http://doc.qt.io/qt-5/qserialport.html QSerialPort] is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.


02/26/2013 – The project moved from the playground to the trunk of Qt5!
Supports the following operating systems:


==Brief description==
{| class="wikitable"
!Operating system
!Support state
!Note
|-
|Windows XP/Vista/7/8/10
|YES
|Full support
|-
|Windows CE
|NO (since 5.7)
|Tested only on 5 and 6 platforms in the emulator
|-
|Gnu/Linux
|YES
|Full support
|-
|MacOSX
|YES
|Full support
|-
|Others Unix
|YES
|All POSIX-compatible
|}


The '''QtSerialPort''' module is an add-on module for the Qt5 library, providing a single interface for both hardware and virtual serial ports.
Non-official partial Android Support (on own risk, only for rooted devices, in which is it possible to get/set a permissions to the /dev/ttyXYZ nodes) [http://www.qtcentre.org/threads/57928-Serial-Port-in-Android 1] [https://forum.qt.io/topic/34000/does-qt-support-serialport-in-android-system/19 2].


'''''Note:''' Also added support for Qt4.''
=== QSerialPortInfo ===


Serial interfaces, due to their simplicity and reliability, are still popular in some industries like the development of embedded systems, robotics, etc.
[http://doc.qt.io/qt-5/qserialportinfo.html QSerialPortInfo] is a helper class. It provides information on the available serial ports on the system.


Using the '''QtSerialPort''' module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.
Supports the following operating systems:


==History==
{| class="wikitable"
!Operating system
!Support state
!|Note
|-
|Windows XP/Vista/7/8/10
|YES
|Full support (using SetupAPI)
|-
|Windows CE
|NO (since 5.7)
|Tested only on 5 and 6 platforms in the emulator
|-
|Gnu/Linux
|YES
|Full support (using libudev, sysfs or simple search in /dev)
|-
|MacOSX
|YES
|Full support
|-
|Others Unix
|YES
|All POSIX-compatible (only simple search in /dev)
|}


'''QtSerialPort''' originated from the third-party library [http://gitorious.org/qserialdevice/qserialdevice/trees/2.0 QSerialDevice] ''[gitorious.org]'' (branch 2.0), which was recently moved to a repository on https://codereview.qt.io/
== Getting the source code ==


This was done to allow more open development, and to gather and coordinate a community that is interested in developing this module.
You should clone from the [http://code.qt.io/ official mirror] and track changes from there in order to keep the load on Gerrit down.


==Functionality==
<code lang="bash">
$ git clone git://code.qt.io/qt/qtserialport.git
$ cd qtserialport
</code>


Currently, the module <span class="caps">API</span> contains two classes: '''QSerialPort''' and '''QSerialPortInfo'''.
This repository contains both versions for Qt4 and Qt5.  


===QSerialPort===
To take the version for Qt4 it is necessary to do<ref>Now QtSerialPort has a separate branch for Qt4 (similar to Qt4 itself), which will be only in one instance.</ref>:


'''QSerialPort''' is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.
<code lang="bash">
$ git checkout qt4-dev
</code>


Supports the following operating systems:
To take the version for Qt5 it is necessary to do:


<sup>1</sup> For OS Symbian development of the module is suspended due to lack of developers, as well as the fact that Nokia has abandoned the platform and will not include support for it in Qt5.
<code lang="bash">
$ git checkout qt5.x.y
</code>


===QSerialPortInfo===
where x and y is a versions of available branches, which can be displayed after:


'''QSerialPortInfo''' is a helper class. It provides information on the available serial ports on the system.
<code lang="bash">
$ git branch -a
</code>


Supports the following operating systems:
== Building and Installing ==


<sup>2</sup> Symbian development of the module is suspended due to lack of developers, as well as the fact that Nokia has abandoned the platform and will not include support for it in Qt5.
There are two simple methods to compile and install library using the command line or the [http://doc.qt.io/qtcreator/ QtCreator].


==View the source code==
Before building you need to install Perl.


Recently launched a public mirror of the repository project at [http://qt.gitorious.org/qt/qtserialport Gitorious] ''[qt.gitorious.org]''
'''''Note:''' Perl is required only in the case of Qt5, see [http://wiki.qt.io/Building_Qt_5_from_Git here]. When using Qt4 just skip this point.''


Now everyone can freely and quickly view the latest changes through a <span class="caps">WEB</span> browser.
=== Build and install from command line ===


==Getting the source code==
'''''Note:''' ensure that the environment variables are set correctly:''
* ''correctly specified the path to the installed Qt4/Qt5''
* ''correctly specified the path to use the compiler''
* ''correctly specified the path to Perl''


===For end-users===
The following are the recommended steps for building the [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] library for Qt4/Qt5 from the command line.


To get the current snapshot of the source code as an archive click on [http://qt.gitorious.org/qt/qtserialport/archive-tarball/stable this] ''[qt.gitorious.org]'' link.
<code lang="bash">
$ git clone git://code.qt.io/qt/qtserialport.git
$ mkdir qtserialport-build
$ cd qtserialport-build
$ qmake ../qtserialport/qtserialport.pro
</code>


Those who want to use Git can run the following command:
and next if you use GCC compiler then to do:


===For developers===
<code lang="bash">
$ make
$ make install
</code>


To get the source code and contribute to the development you need to register a Qt developer account and set it up for use with Gerrit and Git (see [[Setting up Gerrit]] ''[wiki.qt.io]'').
'''''Note:''' on unix-like systems super user privileges might be required:''
<code lang="bash">
$ sudo make install
</code>


You can then check out the repository using git, like this:
if you use MinGW compiler then to do:


…with your Gerrit user ID in place of &lt;username&gt;.
<code lang="bash">
$ mingw32-make
$ mingw32-make install
</code>


==Building and Installing==
if you use MSVC compiler then to do:


===Build and install from command line===
<code lang="bash">
$ nmake
$ nmake install
</code>


Before building you need to:
=== Build and install from QtCreator ===


* ensure that the environment variables are set correctly:
Using [http://doc.qt.io/qtcreator/ QtCreator] is the simplest and fastest way to manually install the library. Before building you need to check that the desired toolchains (kits) of [http://doc.qt.io/qtcreator/ QtCreator] have been correctly configured.
** correctly specified the path to the installed Qt4/Qt5
** correctly specified the path to use the compiler
* create a build directory that is in the same level as the directory with the source code<br />


The following are the recommended steps for building the '''QtSerialPort''' library on Qt4/Qt5 from the command line.
Recommended steps to build the [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] library for Qt4/Qt5 from [http://doc.qt.io/qtcreator/ QtCreator]:


'''''Note:''' on *nix systems super user privileges might be required:''<br />
* download and unpack the [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] sources
* run [http://doc.qt.io/qtcreator/ QtCreator] and open the root "qtserialport/qtserialport.pro" project file
* get to "Projects->(Your Kit)->Build->Build Steps"
* add a new make "Build Step" and write to the "Make arguments" the '''install''' target
* from the menus, select "Rebuild Project qtserialport"


===Build and install from the QtCreator===
As a result, the [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).


Using QtCreator is the simplest and fastest way to manually install the library.
'''''Note:''' on unix-like systems this method can be failed if Qt was installed into system directories. Super user privileges may be required for "install" target, so need to do:''
<code lang="bash">
sudo make install
</code>
''from the shadow directory.''


Before building you need to:
== Usage ==


* check that the desired toolchains (kits) of QtCreator have been correctly configured
To use the library, add serialport to the ''*.pro'' file of your project:


Recommended steps to build the '''QtSerialPort''' library for Qt4/Qt5 from QtCreator:
=== Qt4 ===


* download and unpack the QtSerialPort sources
<code>
* run QtCreator and open the “qtserialport.pro” project file
CONFIG += serialport
* get to “Projects-&gt;(Your Kit)-&gt;Build-&gt;Build Steps”
</code>
* add a new make “Build Step” and write to the “Make arguments” the '''install''' target
* from the menus, select “Rebuild Project qtserialport”


As a result, the QtSerialPort library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).
=== Qt5 ===


'''''Note:''' on *nix systems this method can be failed if Qt was installed from the repositories into system directories. Super user privileges may be required for “make install” target''
<code>
QT += serialport
</code>


<sup>3</sup> Perl is required only in the case of Qt5, see [[Building Qt 5 from Git|here]] ''[qt.io]''. When using Qt4 just skip this point.
Include the header files of [http://doc.qt.io/qt-5/qtserialport-index.html QtSerialPort] where appropriate:
<code>
#include <QSerialPort>
#include <QSerialPortInfo>
</code>


==Usage==
=== Simple example ===


To use the library, add serialport to the ''*.pro'' file of your project:
Below is a simple example of ''main.cpp'':
<code>
#include <QCoreApplication>
#include <QDebug>


===Qt4===
#include <QSerialPort>
#include <QSerialPortInfo>


===Qt5===
QT_USE_NAMESPACE


Include the header files of QtSerialPort where appropriate:<br />
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);


===Simple example===
    // Example use QSerialPortInfo
    foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
        qDebug() << "Name : " << info.portName();
        qDebug() << "Description : " << info.description();
        qDebug() << "Manufacturer: " << info.manufacturer();


Below is a simple example of ''main.cpp'':<br />
        // Example use QSerialPort
        QSerialPort serial;
        serial.setPort(info);
        if (serial.open(QIODevice::ReadWrite))
            serial.close();
    }


'''''Note:''' <span class="caps">CONFIG</span> += serial port / QT += serialport must be the first or second line in your .pro file.''
    return a.exec();
}
</code>


==Documentation generation==
== Documentation generation ==


There is no need to build the documentation, because the documentation is available [http://doc-snapshot.qt.io/qt5-stable/qtserialport-index.html here] ''[doc-snapshot.qt.io]''.
There is no need to build the documentation, because the documentation is available [http://doc-snapshot.qt.io/qt5-stable/qtserialport-index.html here].


==For those wishing to contribute to the development==
== For those wishing to contribute to the development ==


All development is done through [[Setting up Gerrit|Gerrit]] ''[wiki.qt.io]''. Therefore, those wishing to be involved in the development process must have a Qt developer account.
All development is done through [http://wiki.qt.io/Setting_up_Gerrit Gerrit]. Therefore, those wishing to be involved in the development process must have a Qt developer account.


More information about the registration process and development can be found [[Code Reviews|here]] ''[wiki.qt.io]''
More information about the registration process and development can be found [http://wiki.qt.io/Code_Reviews here]


==Possible problems==
== Possible problems ==


Fill up
Fill up


==Bug Tracking==
== Bug Tracking ==
 
Use [https://bugreports.qt.io bugreports.qt.io] ''[bugreports.qt.io]'', Project “Qt”, Component “Serial Port”.


===Categories:===
Use [https://bugreports.qt.io bugreports.qt.io], Project "Qt", Component "Serial Port".


* [[:Category:Playground|Playground]]
<references />

Latest revision as of 11:32, 29 May 2018

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

NOTE: As of Qt 5.1, Qt Serial Port is now officially part of Qt. You no longer need to build Qt Serial Port manually; simply install Qt 5.1 or later and go to section Usage

Brief description

The QtSerialPort module is an add-on module for the Qt5 library, providing a single interface for both hardware and virtual serial ports.

Note: Also added support for Qt4.

Serial interfaces, due to their simplicity and reliability, are still popular in some industries like the development of embedded systems, robotics, etc.

Using the QtSerialPort module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.

Functionality

Currently, the module API contains two classes: QSerialPort and QSerialPortInfo.

QSerialPort

QSerialPort is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.

Supports the following operating systems:

Operating system Support state Note
Windows XP/Vista/7/8/10 YES Full support
Windows CE NO (since 5.7) Tested only on 5 and 6 platforms in the emulator
Gnu/Linux YES Full support
MacOSX YES Full support
Others Unix YES All POSIX-compatible

Non-official partial Android Support (on own risk, only for rooted devices, in which is it possible to get/set a permissions to the /dev/ttyXYZ nodes) 1 2.

QSerialPortInfo

QSerialPortInfo is a helper class. It provides information on the available serial ports on the system.

Supports the following operating systems:

Operating system Support state Note
Windows XP/Vista/7/8/10 YES Full support (using SetupAPI)
Windows CE NO (since 5.7) Tested only on 5 and 6 platforms in the emulator
Gnu/Linux YES Full support (using libudev, sysfs or simple search in /dev)
MacOSX YES Full support
Others Unix YES All POSIX-compatible (only simple search in /dev)

Getting the source code

You should clone from the official mirror and track changes from there in order to keep the load on Gerrit down.

$ git clone git://code.qt.io/qt/qtserialport.git
$ cd qtserialport

This repository contains both versions for Qt4 and Qt5.

To take the version for Qt4 it is necessary to do[1]:

$ git checkout qt4-dev

To take the version for Qt5 it is necessary to do:

$ git checkout qt5.x.y

where x and y is a versions of available branches, which can be displayed after:

$ git branch -a

Building and Installing

There are two simple methods to compile and install library using the command line or the QtCreator.

Before building you need to install Perl.

Note: Perl is required only in the case of Qt5, see here. When using Qt4 just skip this point.

Build and install from command line

Note: ensure that the environment variables are set correctly:

  • correctly specified the path to the installed Qt4/Qt5
  • correctly specified the path to use the compiler
  • correctly specified the path to Perl

The following are the recommended steps for building the QtSerialPort library for Qt4/Qt5 from the command line.

$ git clone git://code.qt.io/qt/qtserialport.git
$ mkdir qtserialport-build
$ cd qtserialport-build
$ qmake ../qtserialport/qtserialport.pro

and next if you use GCC compiler then to do:

$ make
$ make install

Note: on unix-like systems super user privileges might be required:

$ sudo make install

if you use MinGW compiler then to do:

$ mingw32-make
$ mingw32-make install

if you use MSVC compiler then to do:

$ nmake
$ nmake install

Build and install from QtCreator

Using QtCreator is the simplest and fastest way to manually install the library. Before building you need to check that the desired toolchains (kits) of QtCreator have been correctly configured.

Recommended steps to build the QtSerialPort library for Qt4/Qt5 from QtCreator:

  • download and unpack the QtSerialPort sources
  • run QtCreator and open the root "qtserialport/qtserialport.pro" project file
  • get to "Projects->(Your Kit)->Build->Build Steps"
  • add a new make "Build Step" and write to the "Make arguments" the install target
  • from the menus, select "Rebuild Project qtserialport"

As a result, the QtSerialPort library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).

Note: on unix-like systems this method can be failed if Qt was installed into system directories. Super user privileges may be required for "install" target, so need to do:

sudo make install

from the shadow directory.

Usage

To use the library, add serialport to the *.pro file of your project:

Qt4

CONFIG += serialport

Qt5

QT += serialport

Include the header files of QtSerialPort where appropriate:


#include <QSerialPort>
#include <QSerialPortInfo>

Simple example

Below is a simple example of main.cpp:

#include <QCoreApplication>
#include <QDebug>

#include <QSerialPort>
#include <QSerialPortInfo>

QT_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, 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);
        if (serial.open(QIODevice::ReadWrite))
            serial.close();
    }

    return a.exec();
}

Documentation generation

There is no need to build the documentation, because the documentation is available here.

For those wishing to contribute to the development

All development is done through Gerrit. Therefore, those wishing to be involved in the development process must have a Qt developer account.

More information about the registration process and development can be found here

Possible problems

Fill up

Bug Tracking

Use bugreports.qt.io, Project "Qt", Component "Serial Port".

  1. Now QtSerialPort has a separate branch for Qt4 (similar to Qt4 itself), which will be only in one instance.