Source

Target

Commits (5)
Showing with 33 additions and 38 deletions
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = cenumerator
greaterThan(QT_MAJOR_VERSION, 4) {
!isEmpty(QT.widgets.name):SUBDIRS += enumerator terminal blockingmaster blockingslave
} else {
SUBDIRS += enumerator terminal blockingmaster blockingslave master slave
}
SUBDIRS += serialport
......@@ -43,17 +43,17 @@
and performed when the control returns to Qt's event loop. QSerialPort emits
a signal when the operation is finished. For example, QSerialPort::write()
returns immediately. When the data is sent to the serial port, QSerialPort
emits \l{QSerialPort::bytesWritten()}{bytesWritten()}.
emits \l{QIODevice::bytesWritten()}{bytesWritten()}.
\li \e{The synchronous (blocking) approach.} In non-GUI and multithreaded
applications, the \c waitFor...() functions can be called (i.e.
QSerialPort::waitReadyRead()) to suspend the calling thread until the
QSerialPort::waitForReadyRead()) to suspend the calling thread until the
operation has completed.
\endlist
In this example, the synchronous approach is demonstrated. The
\l{examples/terminal}{Simple Terminal} example illustrates the
\l{terminal}{Terminal} example illustrates the
asynchronous approach.
The purpose of this example is to demonstrate a pattern that you can use
......@@ -65,7 +65,7 @@
necessarily add unmanagable complexity to your application.
This application is a Master, that demonstrate the work paired with Slave
application \l{examples/blockingslave}{Blocking Slave Example}.
application \l{blockingslave}{Blocking Slave Example}.
The Master application is initiate the transfer request via serial port to
the Slave application and wait for a response from it.
......@@ -102,7 +102,7 @@
serial port name, timeout and request data from the member data, and then
releasing the lock again. The case that we are protecting ourselves against
is that \c transaction() could be called at the same time as we are fetching
this data. QString is \l reentrant but \e not \l{thread-safe}, and we must
this data. QString is reentrant but not thread-safe, and we must
also avoid the unlikely risk of reading the serial port name from one request,
and timeout or request data of another. And as you might have guessed,
MasterThread can only handle one request at a time.
......@@ -158,5 +158,5 @@
\snippet blockingmaster/masterthread.cpp 13
\sa {Simple Terminal Example}, {Blocking Slave Example}
\sa {Terminal Example}, {Blocking Slave Example}
*/
......@@ -43,17 +43,17 @@
and performed when the control returns to Qt's event loop. QSerialPort emits
a signal when the operation is finished. For example, QSerialPort::write()
returns immediately. When the data is sent to the serial port, QSerialPort
emits \l{QSerialPort::bytesWritten()}{bytesWritten()}.
emits \l{QIODevice::bytesWritten()}{bytesWritten()}.
\li \e{The synchronous (blocking) approach.} In non-GUI and multithreaded
applications, the \c waitFor...() functions can be called (i.e.
QSerialPort::waitReadyRead()) to suspend the calling thread until the
QSerialPort::waitForReadyRead()) to suspend the calling thread until the
operation has completed.
\endlist
In this example, the synchronous approach is demonstrated. The
\l{examples/slave}{Slave Example} example illustrates the
\l{terminal}{Terminal} example illustrates the
asynchronous approach.
The purpose of this example is to demonstrate a pattern that you can use
......@@ -65,7 +65,7 @@
necessarily add unmanagable complexity to your application.
This application is a Slave, that demonstrate the work paired with Master
application \l{examples/blockingmaster}{Blocking Master Example}.
application \l{Blocking Master Example}.
The Slave application is receives the request via serial port from
the Master application and send a response to it.
......@@ -105,7 +105,7 @@
serial port name, timeout and response data from the member data, and then
releasing the lock again. The case that we are protecting ourselves against
is that \c startSlave() could be called at the same time as we are fetching
this data. QString is \l reentrant but \e not \l{thread-safe}, and we must
this data. QString is reentrant but not thread-safe, and we must
also avoid the unlikely risk of reading the serial port name from one startup,
call and timeout or response data of another. And as you might have guessed,
SlaveThread can only handle one startup at a time.
......@@ -161,5 +161,5 @@
\snippet blockingslave/slavethread.cpp 13
\sa {Simple Terminal Example}, {Blocking Master Example}
\sa {Terminal Example}, {Blocking Master Example}
*/
......@@ -48,39 +48,39 @@
and performed when the control returns to Qt's event loop. QSerialPort emits
a signal when the operation is finished. For example, QSerialPort::write()
returns immediately. When the data is sent to the serial port, QSerialPort
emits \l{QSerialPort::bytesWritten()}{bytesWritten()}.
emits \l{QIODevice::bytesWritten()}{bytesWritten()}.
\li \e{The synchronous (blocking) approach.} In non-GUI and multithreaded
applications, the \c waitFor...() functions can be called (i.e.
QSerialPort::waitReadyRead()) to suspend the calling thread until the
QSerialPort::waitForReadyRead()) to suspend the calling thread until the
operation has completed.
\endlist
In this example, the asynchronous approach is demonstrated. The
\l{examples/blockingterminal}{Blocking Simple Terminal} example
illustrates the synchronous approach.
\l{blockingslave}{Blocking Slave} example illustrates the synchronous
approach.
Our example contains some GUI widgets:
\list
\li \l{examples/terminal/mainwindow.cpp}{MainWindow} - is the main application
\li \l{terminal/mainwindow.cpp}{MainWindow} - is the main application
window that contains all the working logic for the serial port programming,
including configuration, I/O processing and so forth, while inheriting the
QMainWindow.
\li \l{examples/terminal/console.cpp}{Console} - is the central widget of the
\li \l{terminal/console.cpp}{Console} - is the central widget of the
main window, displaying the transmitted or received data. The widget is
derived from the QPlainTextEdit class.
\li \l{examples/terminal/settingsdialog.cpp}{SettingsDialog} - is a dialog
for configuring the serial port, as well as for displaying the available
serial ports and information about them.
\li \l{terminal/settingsdialog.cpp}{SettingsDialog} - is a dialog for
configuring the serial port, as well as for displaying the available serial
ports and information about them.
\endlist
The serial port is instantiated in the \l{examples/terminal/mainwindow.cpp}{MainWindow}
The serial port is instantiated in the \l{terminal/mainwindow.cpp}{MainWindow}
constructor. The main widget is passed as the parent, so the object deletion
happens automatically according to the the parent and child mechanism in Qt:
......@@ -89,8 +89,8 @@
\snippet terminal/mainwindow.cpp 1
The only QSerialPort signal invoked in this example is
QSerialPort::readyRead(), which shows that new data has been received and
hence available:
\l{QIODevice::readyRead()}{readyRead()}, which shows that new data has been
received and hence available:
\dots
\snippet terminal/mainwindow.cpp 2
......@@ -101,13 +101,13 @@
\snippet terminal/mainwindow.cpp 4
In this slot, the settings are read from \l{examples/terminal/settingsdialog.cpp}
In this slot, the settings are read from \l{terminal/settingsdialog.cpp}
{SettingsDialog} and an attempt is made to open and initialize the serial
port accordingly. If successful, the status bar displays a message that the
opening was successful with the given configuration; otherwise, a messagebox
is displayed with the appropriate error code and message. If the serial port
settings have never been called
\l{examples/terminal/settingsdialog.cpp}{SettingsDialog}, then the terminal
\l{terminal/settingsdialog.cpp}{SettingsDialog}, then the terminal
attempts to open the port with the default settings: 9600 8N1.
Clicking on the \b{Disconnect} button invokes the \c closeSerialPort()
......@@ -122,7 +122,7 @@
\snippet terminal/mainwindow.cpp 6
This slot sends the characters typed in the given
\l{examples/terminal/console.cpp}{Console} widget to the serial port.
\l{terminal/console.cpp}{Console} widget to the serial port.
When the serial port receives new data, the signal
\l{QTcpSocket::readyRead()}{readyRead()} is emitted, and that signal is
......@@ -131,16 +131,16 @@
\snippet terminal/mainwindow.cpp 7
This slot reads the data from the serial port and displays that in the
\l{examples/terminal/console.cpp}{Console} widget.
\l{terminal/console.cpp}{Console} widget.
Clicking on the \b{Configure} button invokes the \c show() slot which
belongs to the \l{examples/terminal/settingsdialog.cpp}{SettingsDialog}
belongs to the \l{terminal/settingsdialog.cpp}{SettingsDialog}
widget.
This method displays the \l{examples/terminal/settingsdialog.cpp}{SettingsDialog}
This method displays the \l{terminal/settingsdialog.cpp}{SettingsDialog}
in which the user can choose the desired serial port, see the information
about the selected port, and set the desired parameters of the given serial
port.
\sa {Blocking Simple Terminal Example}
\sa {Blocking Slave Example}
*/