Qt Serial Port: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
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|Български]]
'''English'''<br />| [[:QtSerialPort_German|Deutsch]]<br />| [[:QtSerialPort_Russian|Русский]]<br />| [[:QtSerialPort_Polish|Polski]]<br />| [[:QtSerialPort_Dutch|Nederlands]]<br />| [[:QtSerialPort_Portuguese|Português]]<br />| [[:QtSerialPort_Spanish|Español]]<br />| [[:QtSerialPort_Ukrainian|Українською]]<br />| [[:QtSerialPort_Persian|فارسی]]<br />| [[:QtSerialPort_Arabic|عربي]]<br />| [[:QtSerialPort_Korean|한국어]]<br />| [[:QtSerialPort_Finnish|Suomi]]<br />| [[:Wiki Home Catalan|Català]]<br />| [[:Wiki Home Italian|Italiano]]<br />| [[:QtSerialPort_Japanese|日本語]]<br />| [[:QtSerialPort_French|Français]]<br />| [[:Wiki Home Hungarian|Magyar]]<br />| [[:QtSerialPort_Kannada|ಕನ್ನಡ]]<br />| [[:QtSerialPort_Hindi|हिन्दी]]<br />| [[:QtSerialPort_Thai|ภาษาไทย]]<br />| [[:QtSerialPort_SimplifiedChinese|简体中文]]<br />| [[:QtSerialPort_Bulgarian|Български]]


=QtSerialPort=
[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]
 
= QtSerialPort =


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


==News==
== News ==


Fill up
Fill up


02/26/2013 The project moved from the playground to the trunk of Qt5!
02/26/2013 - The project moved from the playground to the trunk of Qt5!


==Brief description==
== 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.
The '''QtSerialPort''' module is an add-on module for the Qt5 library, providing a single interface for both hardware and virtual serial ports.
Line 21: Line 23:
Using the '''QtSerialPort''' module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.
Using the '''QtSerialPort''' module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.


==History==
== History ==


'''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/
'''QtSerialPort''' originated from the third-party library &quot;QSerialDevice&amp;quot;:http://gitorious.org/qserialdevice/qserialdevice/trees/2.0 (branch 2.0), which was recently moved to a repository on https://codereview.qt.io/


This was done to allow more open development, and to gather and coordinate a community that is interested in developing this module.
This was done to allow more open development, and to gather and coordinate a community that is interested in developing this module.


==Functionality==
== Functionality ==


Currently, the module <span class="caps">API</span> contains two classes: '''QSerialPort''' and '''QSerialPortInfo'''.
Currently, the module API contains two classes: '''QSerialPort''' and '''QSerialPortInfo'''.


===QSerialPort===
=== QSerialPort ===


'''QSerialPort''' is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.
'''QSerialPort''' is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.
Line 37: Line 39:
Supports the following operating systems:
Supports the following operating systems:


<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.
{background:#009900}. |''. Operating system |''. Support state |''. Note<br />|<br />|Windows NT/2K/XP/Vista/7<br />|YES<br />|Full support<br />|<br />|Windows CE<br />|YES<br />|Tested only on 5 and 6 platforms in the emulator<br />|<br />|Gnu/Linux<br />|YES<br />|Full support<br />|<br />|MacOSX<br />|YES<br />|Full support<br />|<br />|Others Unix<br />|YES<br />|All POSIX-compatible<br />|<br />|Symbian<ref>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.
</ref><br />|YES<br />|Partially, tested only in the emulator<br />|


===QSerialPortInfo===


'''QSerialPortInfo''' is a helper class. It provides information on the available serial ports on the system.
<br />h3. QSerialPortInfo
<br />'''QSerialPortInfo''' is a helper class. It provides information on the available serial ports on the system.
<br />Supports the following operating systems:
<br />{background:#009900}. |''. Operating system |''. Support state |''. Note<br />|<br />|Windows NT/2K/XP/Vista/7<br />|YES<br />|Full support (using SetupAPI)<br />|<br />|Windows CE<br />|YES<br />|Tested only on 5 and 6 platforms in the emulator<br />|<br />|Gnu/Linux<br />|YES<br />|Full support (using libudev or simple search in /dev)<br />|<br />|MacOSX<br />|YES<br />|Full support<br />|<br />|Others Unix<br />|YES<br />|All POSIX-compatible (only simple search in /dev)<br />|<br />|Symbian<ref>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.
</ref><br />|YES<br />|Partially, tested only in the emulator<br />|


Supports the following operating systems:
== View the source code ==


<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.
Recently launched a public mirror of the repository project at &quot;Gitorious&amp;quot;:http://qt.gitorious.org/qt/qtserialport


==View the source code==
Now everyone can freely and quickly view the latest changes through a WEB browser.


Recently launched a public mirror of the repository project at [http://qt.gitorious.org/qt/qtserialport Gitorious] ''[qt.gitorious.org]''
== Getting the source code ==


Now everyone can freely and quickly view the latest changes through a <span class="caps">WEB</span> browser.
=== For end-users ===


==Getting the source code==
To get the current snapshot of the source code as an archive click on &quot;this&amp;quot;:http://qt.gitorious.org/qt/qtserialport/archive-tarball/stable link.


===For end-users===
Those who want to use Git can run the following command:


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>git clone git://gitorious.org/qt/qtserialport.git<code>
 
Those who want to use Git can run the following command:


===For developers===
=== For developers ===


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]'').
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 &quot;Setting up Gerrit&amp;quot;:http://wiki.qt.io/Setting_up_Gerrit).


You can then check out the repository using git, like this:
You can then check out the repository using git, like this:


…with your Gerrit user ID in place of &lt;username&gt;.
</code>git clone ssh://&amp;lt;username&amp;gt;</code>codereview.qt.io:29418/qt/qtserialport.git</code>


==Building and Installing==
…with your Gerrit user ID in place of &lt;username&amp;gt;.


===Build and install from command line===
== Building and Installing ==


Before building you need to:
=== Build and install from command line ===


* ensure that the environment variables are set correctly:
Before building you need to:<br />* install Perl<ref>Perl is required only in the case of Qt5, see &quot;here&amp;quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.
** correctly specified the path to the installed Qt4/Qt5
</ref><br />* ensure that the environment variables are set correctly:<br />'''''' correctly specified the path to the installed Qt4/Qt5<br />'''''' correctly specified the path to use the compiler<br />'''''' correctly specified the path to Perl<ref>Perl is required only in the case of Qt5, see &quot;here&amp;quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.
** correctly specified the path to use the compiler
</ref><br />* create a build directory that is in the same level as the directory with the source code<br /><code><br />/<br />|- /serialport-src<br />|- /serialport-build<br /></code>
* 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.
The following are the recommended steps for building the '''QtSerialPort''' library on Qt4/Qt5 from the command line.


'''''Note:''' on *nix systems super user privileges might be required:''<br />
<code><br />cd serialport-build<br />qmake ../serialport-src/qtserialport.pro<br />make [or 'nmake' for MSVC compiler, or 'mingw32-make' for MinGW compiler]<br />make install [or 'nmake install' for MSVC compiler, or 'mingw32-make install' for MinGW compiler]<br /></code>


===Build and install from the QtCreator===
'''''Note:''' on '''nix systems super user privileges might be required:_<br /><code><br />sudo make install<br /></code>
<br />h3. Build and install from the QtCreator
<br />Using QtCreator is the simplest and fastest way to manually install the library.
<br />Before building you need to:
<br />''' install Perl<ref>Perl is required only in the case of Qt5, see &quot;here&amp;quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.
</ref> and check that the path to Perl was correctly specified in a global env<br />* check that the desired toolchains (kits) of QtCreator have been correctly configured
<br />Recommended steps to build the '''QtSerialPort''' library for Qt4/Qt5 from QtCreator:
<br />* download and unpack the QtSerialPort sources<br />* run QtCreator and open the &quot;qtserialport.pro&amp;quot; project file<br />* get to &quot;Projects-&gt;(Your Kit)<s>&gt;Build</s>&gt;Build Steps&amp;quot;<br />* add a new make &quot;Build Step&amp;quot; and write to the &quot;Make arguments&amp;quot; the '''install''' target<br />* from the menus, select &quot;Rebuild Project qtserialport&amp;quot;
<br />As a result, the QtSerialPort library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).
<br />'''''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 &quot;make install&amp;quot; target_


Using QtCreator is the simplest and fastest way to manually install the library.
== Usage ==


Before building you need to:
To use the library, add serialport to the ''*.pro'' file of your project:


* check that the desired toolchains (kits) of QtCreator have been correctly configured
=== Qt4 ===


Recommended steps to build the '''QtSerialPort''' library for Qt4/Qt5 from QtCreator:
<code><br />CONFIG ''= serialport<br /></code>
<br />h3. Qt5
<br /><code><br />QT''= serialport<br /></code>


* download and unpack the QtSerialPort sources
Include the header files of QtSerialPort where appropriate:<br /><code><br />…<br />#include &lt;QtSerialPort/QSerialPort&amp;gt;<br />#include &lt;QtSerialPort/QSerialPortInfo&amp;gt;<br />…<br /></code>
* run QtCreator and open the “qtserialport.pro” project file
* get to “Projects-&gt;(Your Kit)-&gt;Build-&gt;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).
=== Simple example ===


'''''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''
Below is a simple example of ''main.cpp'':<br /><code><br />#include &lt;QtCore/QCoreApplication&amp;gt;<br />#include &lt;QtCore/QDebug&amp;gt;


<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 &lt;QtSerialPort/QSerialPort&amp;gt;<br />#include &lt;QtSerialPort/QSerialPortInfo&amp;gt;


==Usage==
QT_USE_NAMESPACE


To use the library, add serialport to the ''*.pro'' file of your project:
int main(int argc, char *argv[])<br />{<br /> QCoreApplication a(argc, argv);


===Qt4===
// Example use QSerialPortInfo<br /> foreach (const QSerialPortInfo &amp;info, QSerialPortInfo::availablePorts()) {<br /> qDebug() &lt;&lt; &quot;Name : &quot; &lt;&lt; info.portName();<br /> qDebug() &lt;&lt; &quot;Description : &quot; &lt;&lt; info.description();<br /> qDebug() &lt;&lt; &quot;Manufacturer: &quot; &lt;&lt; info.manufacturer();


===Qt5===
// Example use QSerialPort<br /> QSerialPort serial;<br /> serial.setPort(info);<br /> if (serial.open(QIODevice::ReadWrite))<br /> serial.close();<br /> }


Include the header files of QtSerialPort where appropriate:<br />
return a.exec&amp;amp;#40;&amp;#41;;<br />}<br /></code>


===Simple example===
'''''Note:''' CONFIG ''= serial port / QT''= serialport must be the first or second line in your .pro file.''


Below is a simple example of ''main.cpp'':<br />
== Documentation generation ==


'''''Note:''' <span class="caps">CONFIG</span> += serial port / QT += serialport must be the first or second line in your .pro file.''
There is no need to build the documentation, because the documentation is available &quot;here&amp;quot;:http://doc-snapshot.qt.io/qt5-stable/qtserialport-index.html.


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


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]''.
All development is done through &quot;Gerrit&amp;quot;:http://wiki.qt.io/Setting_up_Gerrit. Therefore, those wishing to be involved in the development process must have a Qt developer account.


==For those wishing to contribute to the development==
More information about the registration process and development can be found &quot;here&amp;quot;:http://wiki.qt.io/Code_Reviews


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.
== Possible problems ==
 
More information about the registration process and development can be found [[Code Reviews|here]] ''[wiki.qt.io]''
 
==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 &quot;bugreports.qt.io&amp;quot;:https://bugreports.qt.io, Project &quot;Qt&amp;quot;, Component &quot;Serial Port&amp;quot;.


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

Revision as of 14:07, 23 February 2015

English
| Deutsch
| Русский
| Polski
| Nederlands
| Português
| Español
| Українською
| فارسی
| عربي
| 한국어
| Suomi
| Català
| Italiano
| 日本語
| Français
| Magyar
| ಕನ್ನಡ
| हिन्दी
| ภาษาไทย
| 简体中文
| Български

[toc align_right="yes&quot; depth="3&quot;]

QtSerialPort

Note: this page is work in progress, needs review.

News

Fill up

02/26/2013 - The project moved from the playground to the trunk of Qt5!

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.

History

QtSerialPort originated from the third-party library "QSerialDevice&quot;:http://gitorious.org/qserialdevice/qserialdevice/trees/2.0 (branch 2.0), which was recently moved to a repository on https://codereview.qt.io/

This was done to allow more open development, and to gather and coordinate a community that is interested in developing this module.

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:

{background:#009900}. |. Operating system |. Support state |. Note
|
|Windows NT/2K/XP/Vista/7
|YES
|Full support
|
|Windows CE
|YES
|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
|
|Symbian[1]
|YES
|Partially, tested only in the emulator
|



h3. QSerialPortInfo
QSerialPortInfo is a helper class. It provides information on the available serial ports on the system.
Supports the following operating systems:
{background:#009900}. |. Operating system |. Support state |. Note
|
|Windows NT/2K/XP/Vista/7
|YES
|Full support (using SetupAPI)
|
|Windows CE
|YES
|Tested only on 5 and 6 platforms in the emulator
|
|Gnu/Linux
|YES
|Full support (using libudev or simple search in /dev)
|
|MacOSX
|YES
|Full support
|
|Others Unix
|YES
|All POSIX-compatible (only simple search in /dev)
|
|Symbian[2]
|YES
|Partially, tested only in the emulator
|

View the source code

Recently launched a public mirror of the repository project at "Gitorious&quot;:http://qt.gitorious.org/qt/qtserialport

Now everyone can freely and quickly view the latest changes through a WEB browser.

Getting the source code

For end-users

To get the current snapshot of the source code as an archive click on "this&quot;:http://qt.gitorious.org/qt/qtserialport/archive-tarball/stable link.

Those who want to use Git can run the following command:

git clone git://gitorious.org/qt/qtserialport.git<code>

=== For developers ===

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 &quot;Setting up Gerrit&amp;quot;:http://wiki.qt.io/Setting_up_Gerrit).

You can then check out the repository using git, like this:

git clone ssh://&lt;username&gt;codereview.qt.io:29418/qt/qtserialport.git

…with your Gerrit user ID in place of <username&gt;.

Building and Installing

Build and install from command line

Before building you need to:
* install Perl[3]
* 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[4]
* create a build directory that is in the same level as the directory with the source code

<br />/<br />|- /serialport-src<br />|- /serialport-build<br />

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

<br />cd serialport-build<br />qmake ../serialport-src/qtserialport.pro<br />make [or 'nmake' for MSVC compiler, or 'mingw32-make' for MinGW compiler]<br />make install [or 'nmake install' for MSVC compiler, or 'mingw32-make install' for MinGW compiler]<br />

Note:' on nix systems super user privileges might be required:_

<br />sudo make install<br />


h3. Build and install from the QtCreator
Using QtCreator is the simplest and fastest way to manually install the library.
Before building you need to:
install Perl[5] and check that the path to Perl was correctly specified in a global env
* 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 "qtserialport.pro&quot; project file
* get to "Projects->(Your Kit)>Build>Build Steps&quot;
* add a new make "Build Step&quot; and write to the "Make arguments&quot; the install target
* from the menus, select "Rebuild Project qtserialport&quot;
As a result, the QtSerialPort library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).
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&quot; target_

Usage

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

Qt4

<br />CONFIG ''= serialport<br />


h3. Qt5


<br />QT''= serialport<br />

Include the header files of QtSerialPort where appropriate:

<br /><br />#include &lt;QtSerialPort/QSerialPort&amp;gt;<br />#include &lt;QtSerialPort/QSerialPortInfo&amp;gt;<br /><br />

Simple example

Below is a simple example of main.cpp:

<br />#include &lt;QtCore/QCoreApplication&amp;gt;<br />#include &lt;QtCore/QDebug&amp;gt;

#include &lt;QtSerialPort/QSerialPort&amp;gt;<br />#include &lt;QtSerialPort/QSerialPortInfo&amp;gt;

QT_USE_NAMESPACE

int main(int argc, char *argv[])<br />{<br /> QCoreApplication a(argc, argv);

// Example use QSerialPortInfo<br /> foreach (const QSerialPortInfo &amp;info, QSerialPortInfo::availablePorts()) {<br /> qDebug() &lt;&lt; &quot;Name : &quot; &lt;&lt; info.portName();<br /> qDebug() &lt;&lt; &quot;Description : &quot; &lt;&lt; info.description();<br /> qDebug() &lt;&lt; &quot;Manufacturer: &quot; &lt;&lt; info.manufacturer();

// Example use QSerialPort<br /> QSerialPort serial;<br /> serial.setPort(info);<br /> if (serial.open(QIODevice::ReadWrite))<br /> serial.close();<br /> }

return a.exec&amp;amp;#40;&amp;#41;;<br />}<br />

Note: CONFIG = serial port / QT= serialport must be the first or second line in your .pro file.

Documentation generation

There is no need to build the documentation, because the documentation is available "here&quot;:http://doc-snapshot.qt.io/qt5-stable/qtserialport-index.html.

For those wishing to contribute to the development

All development is done through "Gerrit&quot;:http://wiki.qt.io/Setting_up_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&quot;:http://wiki.qt.io/Code_Reviews

Possible problems

Fill up

Bug Tracking

Use "bugreports.qt.io&quot;:https://bugreports.qt.io, Project "Qt&quot;, Component "Serial Port&quot;.

  1. 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.
  2. 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.
  3. Perl is required only in the case of Qt5, see "here&quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.
  4. Perl is required only in the case of Qt5, see "here&quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.
  5. Perl is required only in the case of Qt5, see "here&quot;:http://wiki.qt.io/Building_Qt_5_from_Git. When using Qt4 just skip this point.