Ajout de plein d'affaires.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
syntax: glob
|
||||
*.pro.user*
|
||||
*.app
|
||||
*.moc
|
||||
*.prl
|
||||
Makefile*
|
||||
doc/html/
|
||||
*.framework/
|
||||
*.xcodeproj/
|
||||
debug/
|
||||
release/
|
||||
qtc-gdbmacros/
|
||||
*.rej
|
||||
*.orig
|
||||
*.obj
|
||||
*.swp
|
||||
*.dll
|
||||
*.exp
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.lib
|
||||
Thumbs.db
|
||||
moc_*.cpp
|
||||
qrc_*.cpp
|
||||
*.o
|
||||
*.so.*
|
||||
*.so
|
||||
*.pdb
|
||||
ui_*.h
|
||||
*~
|
||||
.qmake.cache
|
||||
extserialport.prf
|
||||
lib/*
|
||||
*.orig
|
||||
*.exe
|
||||
*.vcproj
|
||||
*.vcproj.*.user
|
||||
*_resource.rc
|
||||
*.sln
|
||||
*.idb
|
||||
*.ncb
|
||||
*.suo
|
||||
examples/enumerator/enumerator
|
||||
examples/event/event
|
||||
examples/qespta/qespta
|
||||
examples/uartassistant/uartassistant
|
||||
object_script.*
|
||||
@@ -0,0 +1,267 @@
|
||||
Change history for QextSerialPort (formerly QwSerialPort):
|
||||
(Lines beginning with + represent new functionality, * represent changed or
|
||||
fixed functionality, - represent removed or deprecated functionality)
|
||||
|
||||
Version 1.2 rc (2012 Debao Zhang)
|
||||
* Build-system refactor
|
||||
* Issue 145 : Custom baud support for MacOS
|
||||
* Issue 36 : Fix Devices Notification for Vista
|
||||
* Issue 54 and Issue 108 : Try detect more ports for windows
|
||||
* Issue 139 : Adjust the name of generated library
|
||||
- QextWinEventNotifier has been removed
|
||||
|
||||
Version 1.2 beta2 (2012 Debao Zhang)
|
||||
* Issue 124 : implement canReadLine
|
||||
* Issue 122 : make Dtr default to TRUE under Windows.
|
||||
* Issue 127 : fix QObject::MoveToThread brokes SerialPort on Windows
|
||||
* Issue 129 : Add custom baud support for Windows.
|
||||
* Issue 131 : Make sure portName returned by QextSerialEnumerator can be used by QextSerialPort
|
||||
* Issue 134 : Make "make install" really works
|
||||
* Issue 2: device discovery / removal notification on linux (read config_example.pri to figure out how to enable it.)
|
||||
|
||||
Version 1.2 beta1 (2012 Debao Zhang)
|
||||
* D-pointer and Q_PRIVATE_SLOT are used to moving private members from QextSerialPort to QextSerialPortPrivate
|
||||
* qdoc3 instead of doxygen is used for generating documents
|
||||
* MIT license header add to all sources files
|
||||
+ add a helper class QextWinEventNotifier for windows user, when user's SDK doesnot contain Qt's private files, this class will be auto selected.
|
||||
|
||||
Version 1.2win-alpha (2007 Michal Policht)
|
||||
+ Added QextSerialEnumerator pre-alpha. Works under W2k and later versions of Windows.
|
||||
+ Event driven mechanism (alternative to polling) is now available on Windows.
|
||||
- Removed default (=0) parameter from open() functions.
|
||||
* Fixed bug #1714917 in Win_QextSerialPort::close() method (by Kurt).
|
||||
* Fixed problem with lack of proper blocking in readData() on win32 (by Brandon Fosdick).
|
||||
* Removed QT_THREAD_SUPPORT option. Now QextSerialPort must be always compiled with threads support.
|
||||
* Mutexes are not static.
|
||||
* setTimeout() now accepts only one parameter.
|
||||
* bytesAvailable() on POSIX now shows 0 bytes instead of -1 when no bytes are available.
|
||||
* bytesAvailable() is const.
|
||||
* native POSIX file descriptors instead of QFile->handle() calls
|
||||
+ POSIX: Save and restore original termios when opening and closing the device
|
||||
* POSIX: Only disable special characters on systems that support it
|
||||
* POSIX: Use cfmakeraw(3) to get a non-canonical termios
|
||||
+ POSIX: Call close(2) in close() to actually close the device
|
||||
|
||||
Version 1.1 (official release)
|
||||
|
||||
Version 1.0.1
|
||||
* Minor changes (mostly in test application)
|
||||
|
||||
Version 1.0.0e (by Micha? Policht)
|
||||
* Fixed bytesAvailable(). Includes buffered bytes to the result.
|
||||
+ Added isSequential() method.
|
||||
+ Provided test application
|
||||
|
||||
Version 1.0.0d ( changes by Micha? Policht )
|
||||
- Removed isOpen() overriden declaration/implementation from qextserialport's classes. isOpen() relies on QIODevice now.
|
||||
- Removed bool portOpen variable. Replaced by internal QIODevice.openMode.
|
||||
- Removed getChar(), putChar() overriden declaration/implementation. QIODevice can handle this.
|
||||
* Calling open() with specified OpenMode invokes QIODevice::open() which result in proper openMode setting.
|
||||
* readData(), writeData() are protected as in QIODevice declaration.
|
||||
* QIODevice:: read() and write() function are working now (use them instead of readData() writeData()).
|
||||
* readData(), writeData() don't check if port is open any more (read() and write() assures that). The same behaviour can be found in QFile for example.
|
||||
* Fixed readLine().
|
||||
|
||||
* Fixed randomly crash on deletion bug on Windows ( by Stuart Nixon )
|
||||
http://lists.trolltech.com/qt-interest/2007-02/thread00340-0.html#msg00351
|
||||
|
||||
Version 0.9 (March 3, 2005) Stefan Sander <stefan-sander@users.sf.net>:
|
||||
+ Added a new precompiler constant, _TTY_FREEBSD_
|
||||
to support FreeBSD port names.
|
||||
+ Added _TTY_WIN_ constant in qextserialport.pro win32:DEFINES
|
||||
to have Windows port names as default when compiling on it.
|
||||
- Removed construct() call from QextSerialBase constructors,
|
||||
it is called indirectly through Win_QextSerialPort::construct()
|
||||
and Posix_QextSerialPort::construct().
|
||||
+ Added construct() call to Win_QextSerialPort constructors.
|
||||
+ Added setTimeout(0, 500) call to Win_QextSerialPort::construct().
|
||||
- Removed setTimeout(0, 500) call from Win_QextSerialPort(const char* name).
|
||||
* Fixed Posix_QextSerialPort::open(int) control flow, now the port settings
|
||||
are only applied if the associated file could be opened.
|
||||
* Fixed masking CR to NL, in Posix_CommConfig.c_iflag
|
||||
|
||||
Version 0.8 (, 2003) (Alpha release):
|
||||
* Added code to set the port timeouts in Win_QextSerialPort's default
|
||||
constructor.
|
||||
* Fixed Posix_QextSerialPort::construct() to set up the port correctly.
|
||||
* Fixed syntax errors in 2 ioctl() calls in posix_QextSerialPort.
|
||||
* lastError is now initialized to E_NO_ERROR in the QextSerialBase
|
||||
constructor.
|
||||
* The select() call in posix_QextSerialPort::bytesWaiting() is now
|
||||
properly coded. Previously it would always time out.
|
||||
* Fixed runtime errors in the ioctl() calls for
|
||||
Posix_QextSerialPort::setDtr() and Posix_QextSerialPort::setRts().
|
||||
Thanks to Marc Pignat.
|
||||
|
||||
Version 0.7 (June 15, 2002) <Bugfix release>:
|
||||
(0.61 - unofficial release)
|
||||
* Fixed a small bug in the initializations of the static members when
|
||||
QT_THREAD_SUPPORT was defined.
|
||||
* Fixed a bug that caused Borland's compiler to choke on Windows platforms
|
||||
(which perversely actually stemmed from a shortcoming of Visual C++ that
|
||||
Borland doesn't have).
|
||||
|
||||
(0.62 - unofficial release)
|
||||
* Fixed a bug that gave Q_LONG the wrong typedef for QT versions prior to
|
||||
3.0.
|
||||
|
||||
(0.63 - unofficial release)
|
||||
* Fixed 2 incorrect references to Posix_Comm_Config.
|
||||
* Fixed scoping of Posix_QextSerialPort::operator=().
|
||||
* Posix_QextSerialPort::construct should now be coded correctly.
|
||||
* Fixed return type for Posix_QextSerialPort::size().
|
||||
|
||||
(0.64 - unofficial release)
|
||||
* Fixed all the port settings functions to work properly when opening the
|
||||
port for the first time - previously none of the settings were being
|
||||
applied when the port was opened.
|
||||
* Fixed an oversight in Win_QextSerialPort::open() that caused the setting
|
||||
of port parameters to fail on NT and 2000 systems.
|
||||
|
||||
(0.7 - official release)
|
||||
* Fixed some calls to QextSerialBase constructors that no longer exist on
|
||||
the POSIX side.
|
||||
* Fixed the bad memcpy()'s in the POSIX copy constructor.
|
||||
* Fixed the Offset scoping problem under gcc 2.95.
|
||||
* The CBAUD flag has been deprecated on some POSIX systems. Fixed
|
||||
Posix_QextSerialPort::setBaudRate() to reflect this.
|
||||
* Added construct() calls to all of the Posix_QextSerialPort constructors.
|
||||
* Fixed double (and conflicting) typedefs of Offset when using QT versions
|
||||
prior to 3.0
|
||||
* Changed the call to CreateFile() to CreateFileA() in
|
||||
Win_QextSerialPort.cpp. This should get rid of problems for those using
|
||||
Unicode or other multibyte character sets for their string literals.
|
||||
* A few tweaks to the documentation.
|
||||
|
||||
- Removed the protected Posix_Handle variable from Posix_QextSerialPort.
|
||||
|
||||
Version 0.6 (March 11, 2002) <Bugfix release>:
|
||||
+ Added a new precompiler constant, QTVER_PRE_30. QT3 changed the return
|
||||
types of some QIODevice functions. Therefore, if compiling on versions
|
||||
of QT prior to 3.0, you should always define QTVER_PRE_30 in your project.
|
||||
Also had to add some preprocessor blocks to support both 3.0 and earlier
|
||||
versions of QT.
|
||||
+ Added implementations of 2 of the new constructors added in 0.5 to both
|
||||
Win_QextSerialPort and Posix_QextSerialPort.
|
||||
|
||||
* The scoping of the enums used in the PortSettings struct has been fixed.
|
||||
* QObject inheritance has been removed. This should not affect the
|
||||
functionality of the classes.
|
||||
* Replaced a few stray references to mutex->unlock() with UNLOCK_MUTEX() in
|
||||
the Windows code.
|
||||
* Fixed several runtime errors caused by calling nonexistent members of
|
||||
QextSerialBase.
|
||||
* Fixed a whole bunch of little things that were causing MSVC to choke when
|
||||
compiling for Windows.
|
||||
|
||||
Version 0.5 (February 15, 2002):
|
||||
+ There are 4 new macros (LOCK_MUTEX, UNLOCK_MUTEX, TTY_WARNING, and
|
||||
TTY_PORTABILITY_WARNING) that replace most of those ugly #ifdef blocks in
|
||||
the code.
|
||||
+ In place of the old namingConvention stuff, there is a new function,
|
||||
setName(). It is used to set the name of the device to be associated with
|
||||
the object. The new name() function can be used to retrieve the device
|
||||
name, which is stored in the new member variable portName.
|
||||
+ There is a new version of open() that takes a const char* as a parameter.
|
||||
It can be used to specify the name of the device when it is opened rather
|
||||
than at construction time.
|
||||
|
||||
* 3 constructors have been removed and 3 more added. There is now a copy
|
||||
constructor (and operator=()) as well as a constructor that takes a
|
||||
PortSettings structure as a parameter, and another that takes both a
|
||||
device name and a PortSettings structure. As a result of these changes
|
||||
the PortSettings structure declaration is no longer local to the
|
||||
QextSerialBase class. All of the removed constructors had to do with
|
||||
the setNamingConvention() system.
|
||||
* The static mutex member should now be reference-counted and only deleted
|
||||
when it is no longer referenced.
|
||||
* Most of the object construction duties have been pushed back into
|
||||
QextSerialBase
|
||||
* Fixed a couple resource leaks, mostly to do with unlocking the mutex
|
||||
properly
|
||||
|
||||
- Removed the setNamingConvention() nonsense.
|
||||
- Removed all QStrings and calls to sprintf() for thread compatibility.
|
||||
- Removed setNumber() functions as well as the portNumber member variable,
|
||||
as they were only necessary under the setNamingConvention() system.
|
||||
|
||||
I am grateful to Jorg Preiss (Preisz? Sorry, American keyboards don't have
|
||||
an ess-tset character ;)) for his invaluable input on most of the changes
|
||||
that went into this version.
|
||||
|
||||
Version 0.4 (March 20, 2001):
|
||||
+ All of the classes now derive from QObject as well as QIODevice. This
|
||||
is pretty much useless at the moment - signals and slots may be used
|
||||
to implement asynchronous communications in a future version
|
||||
+ Added configurable timeouts via the setTimeout() function. The default
|
||||
timeout for read and write operations is now 500 milliseconds
|
||||
+ There is now a functional .pro file for the library (thanks to
|
||||
Gunnstein Lye)
|
||||
+ The prefixes for all of the classes have changed from Qw to Qext, in
|
||||
compliance with the qt-addons project standard
|
||||
|
||||
* Fixed a bug that caused port settings to be restored incorrectly when
|
||||
switching ports with setNumber()
|
||||
* Minor changes to QextSerialBase::setNumber(). Functionality should now
|
||||
reflect the documentation, which has also been updated to reflect the
|
||||
changes that went in on version 0.3.
|
||||
* Some fixes to the documentation. The Posix_QextSerialPort and
|
||||
Win_QextSerialPort classes should no longer have any unnecessary
|
||||
references to inapplicable platforms, and the documentation for open() has
|
||||
been updated.
|
||||
* Should now compile without QT_THREAD_SUPPORT defined (ie, in single-
|
||||
threaded environments), although it will require slight changes to the
|
||||
makefile (tmake "CONFIG-=thread" should work)
|
||||
* Fixed a few compilation issues, especially on the POSIX side (should
|
||||
compile under Linux now :))
|
||||
* POSIX code is a little cleaner and more efficient
|
||||
* Various small fixes to the documentation
|
||||
* Constants now follow a consistent naming convention, with underscores at
|
||||
the beginning and end of each. For example TTY_POSIX has become
|
||||
_TTY_POSIX_
|
||||
|
||||
Version 0.3 (Feb. 14, 2001):
|
||||
+ Added a warning that appears when QwSerialPort is compiled on a POSIX
|
||||
platform that does not implement 76800 baud operation. In this situation
|
||||
QwSerialPort will also switch to 57600 baud.
|
||||
+ Major code reorganization - there are now 4 classes instead of 1. This
|
||||
should remove a lot of the #ifdef...#else...#endif constructs and
|
||||
hopefully make the code easier to read. Including the class in your
|
||||
project is still done by including QwSerialPort.h and instantiating a
|
||||
QwSerialPort object.
|
||||
|
||||
* The serial port associated with a QwSerialPort object is no longer
|
||||
opened on construction, or upon calling the setNumber() function. You
|
||||
must now explicitly call open() to open the port.
|
||||
|
||||
Version 0.2 (Jan. 3, 2001):
|
||||
+ Added lastError() function with rudimentary error codes
|
||||
+ Better documentation
|
||||
+ Added ability to examine the empty/not empty state of a port's input
|
||||
buffer with atEnd()
|
||||
+ Added ability to retrieve the number of bytes in a port's input buffer
|
||||
with size() (thanks to Olivier Tubach)
|
||||
+ Added ability to turn off portability warnings by defining
|
||||
TTY_NOWARN_PORT in your project
|
||||
+ Added ability to turn off all warning messages by defining TTY_NOWARN
|
||||
in your project
|
||||
+ Added ability to select POSIX serial functions in Windows NT/2000 by
|
||||
defining TTY_POSIX in your project (untested)
|
||||
+ Added control over RTS and DTR lines with setRts() and setDtr()
|
||||
respectively
|
||||
+ Added ability to query line status using lineStatus().
|
||||
+ Added readLine() functionality (thanks to Olivier Tubach)
|
||||
+ Added bytesWaiting(), a non-const/thread-safe version of size()
|
||||
+ The class should now be thread-safe through the use of a recursive
|
||||
QMutex (untested)
|
||||
|
||||
* Fixed a bug that could cause hardware flow control not to work on some
|
||||
POSIX systems
|
||||
* Put in a few missing fileno() calls in the POSIX code
|
||||
* Fixed a few syntax errors that caused compilation to fail on POSIX systems
|
||||
|
||||
- BAUD0 is no longer a valid baud rate setting - to drop the DTR line,
|
||||
call setDtr(FALSE)
|
||||
|
||||
Version 0.1 (Dec. 11, 2000):
|
||||
Initial public release.
|
||||
@@ -0,0 +1,94 @@
|
||||
From QextSerialPort 1.2-beta on, we use MIT license for QextSerialPort project.
|
||||
|
||||
== License ==
|
||||
|
||||
Copyright (c) 2000-2003 Wayne Roth
|
||||
Copyright (c) 2004-2007 Stefan Sander
|
||||
Copyright (c) 2007 Michal Policht
|
||||
Copyright (c) 2008 Brandon Fosdick
|
||||
Copyright (c) 2009-2010 Liam Staskawicz
|
||||
Copyright (c) 2011 Debao Zhang
|
||||
|
||||
Web: http://code.google.com/p/qextserialport/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
== Why license needed? ==
|
||||
|
||||
Many users complains that, without a proper licence they can not use this library.
|
||||
|
||||
* http://groups.google.com/group/qextserialport/browse_thread/thread/0e8756920b01da82
|
||||
|
||||
Hi,
|
||||
we are considering using a modified version of QExtSerialPort in one of our
|
||||
projects (Qt Creator, http://qt.gitorious.org/qt-creator).
|
||||
Would it be possible to add license header information or a license file to the
|
||||
QExtSerialPort code base? - This would make re-use of the code base easier.
|
||||
If that is not possible, could we redistribute the source code with BSD-
|
||||
license headers manually added?
|
||||
|
||||
And
|
||||
|
||||
I am also considering packaging the software for Debian, but I
|
||||
couldn't do it yet just because of the license.
|
||||
|
||||
* http://code.google.com/p/qextserialport/issues/detail?id=8
|
||||
|
||||
Questions:
|
||||
Can I use qextserialport in a commercial product?
|
||||
If yes, how?
|
||||
Compile it in? I guess no.
|
||||
If I can use it as a library, how should the README be formulated?
|
||||
Is the "MIT license" from 2008 appropriate?
|
||||
|
||||
== Why can we use MIT? ==
|
||||
|
||||
Form the history of [http://lists.trolltech.com/qt-interest/2004-12/msg01022.html qt-interest mail list]
|
||||
|
||||
* Wayne Roth, the original author of the project, had said that:
|
||||
|
||||
the code is in the public domain. Do whatever you like with it. Right
|
||||
now I have too many other things to do to put any serious time into
|
||||
fixing it. Trolltech should be aware of this already; they asked
|
||||
about a license when they offered to host the tarball.
|
||||
|
||||
* Stefan Sander, the maintainer of qextserialport on sourceforge, said that
|
||||
|
||||
Hello,
|
||||
My project registration at !SourceForge have been approved.
|
||||
http://www.sf.net/projects/qextserialport
|
||||
I thought an initial licence of Public Domain would be best solution.
|
||||
Someone wrote: - Because its public domain, some could fork it under different licenses -
|
||||
|
||||
And from [http://groups.google.com/group/qextserialport/browse_thread/thread/fbcddbfb4a0b5a51?pli=1 this thread] on qesp mail list, we can see that, current maintainers and users agree with a MIT licence.
|
||||
|
||||
* Brandon Fosdick,
|
||||
|
||||
I would vote for BSD or MIT :)
|
||||
|
||||
* Liam Staskawicz,
|
||||
|
||||
That works for me - let's call it MIT and go for it :)
|
||||
|
||||
And from [[https://groups.google.com/forum/?fromgroups#!topic/qextserialport/P_5TrNHBICE this other thread]] on the same mailing list:
|
||||
|
||||
* Michal Policht,
|
||||
|
||||
I agree to license.
|
||||
@@ -0,0 +1,64 @@
|
||||
= About QextSerialPort =
|
||||
|
||||
QextSerialPort provides an interface to old fashioned serial ports for Qt-based applications. It currently supports Mac OS X, Windows, Linux, FreeBSD.
|
||||
|
||||
http://code.google.com/p/qextserialport/
|
||||
|
||||
== How to use (1) ==
|
||||
|
||||
* Download the source code.
|
||||
|
||||
* Put the source code in any directory you like. For example, 3rdparty:
|
||||
|
||||
|-- project.pro
|
||||
|-- ....
|
||||
|-- 3rdparty\
|
||||
| |-- qextserialport\
|
||||
| |
|
||||
|
||||
* Add following line to your qmake project file:
|
||||
|
||||
include(3rdparty/qextserialport/src/qextserialport.pri)
|
||||
|
||||
* Using QextSerialPort in your code. Enjoy it!
|
||||
|
||||
#include "qextserialport.h"
|
||||
....
|
||||
QextSerialPort * port = new QextSerialPort();
|
||||
....
|
||||
|
||||
== How to use (2) ==
|
||||
It's very easy to compile QextSerialPort directly into your application
|
||||
(see above section), however, we would prefer to use it as a shared library.
|
||||
|
||||
* Download the source code, and put it in any location you like.
|
||||
|
||||
* Run following command to generate library.
|
||||
|
||||
qmake
|
||||
make (or nmake)
|
||||
sudo make install (or nmake install)
|
||||
|
||||
* Add following line to your project's file
|
||||
|
||||
CONFIG += extserialport
|
||||
|
||||
* Using QextSerialPort in your code. Enjoy it!
|
||||
|
||||
#include "qextserialport.h"
|
||||
....
|
||||
QextSerialPort * port = new QextSerialPort();
|
||||
....
|
||||
|
||||
== Build Documents ==
|
||||
* Run
|
||||
qmake
|
||||
make docs
|
||||
|
||||
* Note: More information can be found in doc/readme.txt
|
||||
|
||||
== Build examples ==
|
||||
* Goto examples directory, then run
|
||||
qmake (or qmake -r)
|
||||
make (or nmake)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
OTHER_FILES += $$PWD/qextserialport.qdocconf
|
||||
|
||||
#name of qdoc3 has been changed to qdoc under Qt5
|
||||
QESP_QDOC = qdoc
|
||||
lessThan(QT_MAJOR_VERSION, 5):QESP_QDOC = qdoc3
|
||||
|
||||
docs_target.target = docs
|
||||
docs_target.commands = $$QESP_QDOC $$PWD/qextserialport.qdocconf
|
||||
|
||||
QMAKE_EXTRA_TARGETS = docs_target
|
||||
QMAKE_CLEAN += "-r $$PWD/html"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*!
|
||||
\example examples/enumerator
|
||||
\title enumerator Demo
|
||||
|
||||
The example demonstrates how to use QextSerialEnumerator.
|
||||
|
||||
Include the proper header file
|
||||
\snippet examples/enumerator/main.cpp 0
|
||||
|
||||
Get available ports in the system.
|
||||
\snippet examples/enumerator/main.cpp 1
|
||||
|
||||
Output
|
||||
\snippet examples/enumerator/main.cpp 2
|
||||
*/
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
\example examples/qespta
|
||||
\title qespta Demo
|
||||
|
||||
The example demonstrates how to use QextSerialPort.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*!
|
||||
\example examples/uartassistant
|
||||
\title UartAssistant Demo
|
||||
|
||||
The example demonstrates how to use QextSerialPort.
|
||||
|
||||
Initialze UI element.
|
||||
\snippet examples/uartassistant/dialog.cpp 0
|
||||
|
||||
Initialize serial port
|
||||
\snippet examples/uartassistant/dialog.cpp 1
|
||||
|
||||
port Settings
|
||||
\snippet examples/uartassistant/dialog.cpp 2
|
||||
|
||||
Open or Close the port.
|
||||
\snippet examples/uartassistant/dialog.cpp 3
|
||||
|
||||
Read from or Write to the port
|
||||
\snippet examples/uartassistant/dialog.cpp 4
|
||||
|
||||
\image uartassistant.png
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/*!
|
||||
\page index.html
|
||||
\title QextSerialPort Manual
|
||||
|
||||
\section1 Overview
|
||||
QextSerialPort provides an interface to old fashioned serial ports for
|
||||
Qt-based applications. It currently supports Mac OS X, Windows, Linux, FreeBSD.
|
||||
|
||||
From QextSerialPort 1.2-beta on, license of the project has been changed to MIT.
|
||||
|
||||
\list
|
||||
\o Revision 0.9.x is Qt 2 & 3 compatible.
|
||||
\o Revision 1.x.x is Qt 4 compatible.
|
||||
\o From revision 1.2beta1 on, Qt 5 support is added.
|
||||
\endlist
|
||||
|
||||
|
||||
\section1 Classes
|
||||
\list
|
||||
\o \l QextSerialPort encapsulates a serial port on both POSIX and Windows systems.
|
||||
\o \l QextSerialEnumerator enumerates ports currently available in the system.
|
||||
\endlist
|
||||
|
||||
\section1 Getting Started
|
||||
|
||||
|
||||
\section2 Usage(1): Source Code Only
|
||||
|
||||
The package contains a qextserialport.pri file that allows you to integrate the component into programs that use qmake for the build step.
|
||||
|
||||
Download the source code.
|
||||
Put the source code in any directory you like. For example, 3rdparty:
|
||||
|
||||
\code
|
||||
|-- project.pro
|
||||
|-- ....
|
||||
|-- 3rdparty\
|
||||
| |-- qextserialport\
|
||||
| |
|
||||
\endcode
|
||||
|
||||
Add following line to your qmake project file:
|
||||
\code
|
||||
include(pathToPri/qextserialport.pri)
|
||||
\endcode
|
||||
|
||||
Then, using QextSerialPort in your code
|
||||
\code
|
||||
#include "qextserialport.h"
|
||||
...
|
||||
MyClass::MyClass()
|
||||
{
|
||||
port = new QextSerialPort("COM1");
|
||||
connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
|
||||
port->open();
|
||||
}
|
||||
|
||||
void MyClass::onDataAvailable()
|
||||
{
|
||||
QByteArray data = port->readAll();
|
||||
processNewData(usbdata);
|
||||
}
|
||||
\endcode
|
||||
|
||||
\section2 Usage(2): shared library
|
||||
Although QextSerialPort can be directly compiled into your application, You may prefer
|
||||
to use QextSerailPort as an library, which is very easy too.
|
||||
|
||||
1. Download the source code, and put it in any location you like.
|
||||
|
||||
2. Goto the top level directory ,run following command to generate library.
|
||||
|
||||
\code
|
||||
qmake
|
||||
sudo make install (or nmake install)
|
||||
\endcode
|
||||
|
||||
3. Add following line to your project's file
|
||||
|
||||
\code
|
||||
CONFIG += extserialport
|
||||
\endcode
|
||||
|
||||
4. Using QextSerialPort in your code. Enjoy it!
|
||||
|
||||
\code
|
||||
#include "qextserialport.h"
|
||||
....
|
||||
QextSerialPort * port = new QextSerialPort();
|
||||
....
|
||||
\endcode
|
||||
|
||||
\section2 Usage(3): Static library
|
||||
|
||||
Someone prefer to use QextSerailPort as static library.
|
||||
|
||||
Open the project file: qextserialport.pro, add uncomment follow line
|
||||
|
||||
\code
|
||||
# CONFIG += qesp_static
|
||||
\endcode
|
||||
|
||||
Then follow the same steps as shared library
|
||||
|
||||
\code
|
||||
qmake
|
||||
sudo make install
|
||||
\endcode
|
||||
|
||||
The static library, the header files, and the feature file will be installed to your system.
|
||||
|
||||
Add following line to your qmake's project file:
|
||||
|
||||
\code
|
||||
CONFIG += extserialport
|
||||
\endcode
|
||||
|
||||
\section1 Platform Special
|
||||
|
||||
\section2 For MacX: Build as framework
|
||||
|
||||
Open the project file: *qextserialport.pro*, and uncomment follow line
|
||||
|
||||
\code
|
||||
# CONFIG += qesp_mac_framework
|
||||
\endcode
|
||||
|
||||
Then follow the same steps as shared library, Goto the top level directory , and run
|
||||
|
||||
\code
|
||||
qmake
|
||||
sudo make install
|
||||
\endcode
|
||||
|
||||
The framework which includes libraries and the header files, and the feature file will be installed to your system.
|
||||
|
||||
Add following line to your qmake's project file:
|
||||
|
||||
\code
|
||||
CONFIG += extserialport
|
||||
\endcode
|
||||
|
||||
\section2 For Linux: Enable udev
|
||||
|
||||
Open the project file: *qextserialport.pro*, uncomment follow line
|
||||
|
||||
\code
|
||||
#linux*:CONFIG += qesp_linux_udev
|
||||
\endcode
|
||||
|
||||
Note, If you are using the usage(1), Add following line before include the qextserialport.pri file.
|
||||
\code
|
||||
CONFIG += qesp_linux_udev
|
||||
\endcode
|
||||
|
||||
|
||||
\section2 Build documents
|
||||
\code
|
||||
make docs
|
||||
\endcode
|
||||
|
||||
\section1 Examples
|
||||
\list
|
||||
\o \l examples/enumerator
|
||||
\o \l examples/qespta
|
||||
\o \l examples/uartassistant
|
||||
\endlist
|
||||
|
||||
\section1 Resources
|
||||
\section2 Nokia(Trolltech)
|
||||
\list
|
||||
\o \l {http://doc.trolltech.com/qq/qq12-iodevice.html} {Writing a Custom I/O Device}
|
||||
\o \l {http://doc.trolltech.com/3.3/qiodevice.html} {Qt 3.3: QIODevice Class Reference}
|
||||
\o \l {http://doc.trolltech.com/4.7/qiodevice.html} {Qt 4.7: QIODevice Class Reference}
|
||||
\endlist
|
||||
\section2 MSDN
|
||||
\list
|
||||
\o \l {http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_resources.asp} {Communications Resources}
|
||||
\o \l {http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/about_communications_resources.asp} {About Communications Resources}
|
||||
\o \l {http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/using_communications_resources.asp}{Using Communications Resources}
|
||||
\o \l {http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_functions.asp} {Communications Functions}
|
||||
\o \l {http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_structures.asp} {Communications Structures}
|
||||
\endlist
|
||||
\section2 TLDP
|
||||
\list
|
||||
\o \l {http://www.tldp.org/HOWTO/Serial-HOWTO.html}{Serial HOWTO}
|
||||
\o \l {http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/}{Serial Programming HOWTO}
|
||||
\endlist
|
||||
\section2 Other
|
||||
\list
|
||||
\o \l {http://www.easysw.com/~mike/serial/serial.html} {Serial Programming Guide for POSIX Operating Systems}
|
||||
\endlist
|
||||
|
||||
*/
|
||||
|
||||
/*!
|
||||
\page classes.html
|
||||
\generatelist annotatedclasses
|
||||
*/
|
||||
@@ -0,0 +1,53 @@
|
||||
# Run qdoc3 from the directory that contains this file.
|
||||
project = qesp
|
||||
description = QextSerialPort Reference Documentation
|
||||
url = http://code.google.com/p/qextserialport
|
||||
|
||||
outputencoding = UTF-8
|
||||
language = Cpp
|
||||
|
||||
#Paths are relative to the location of this file
|
||||
headerdirs = . ../src
|
||||
sourcedirs = . ../src
|
||||
exampledirs = ../examples ..
|
||||
imagedirs = ./examples/images images
|
||||
|
||||
Cpp.ignoretokens = QEXTSERIALPORT_EXPORT
|
||||
|
||||
indexes = $QTDIR/doc/html/qt.index
|
||||
|
||||
qhp.projects = qesp
|
||||
qhp.qesp.file = qesp.qhp
|
||||
qhp.qesp.namespace = com.google.code.qextserialport.120
|
||||
qhp.qesp.virtualFolder = qdoc
|
||||
qhp.qesp.indexTitle = QextSerialPort Reference Documentation
|
||||
qhp.qesp.indexRoot =
|
||||
qhp.qesp.extraFiles = style/style.css
|
||||
|
||||
|
||||
#------------------------------------------------------------------
|
||||
outputdir = html
|
||||
outputformats = HTML
|
||||
|
||||
headers.fileextensions = "*.h"
|
||||
sources.fileextensions = "*.cpp *.qdoc"
|
||||
|
||||
HTML.templatedir = .
|
||||
HTML.stylesheets = style/style.css
|
||||
|
||||
HTML.headerstyles = " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\" />\n"
|
||||
HTML.endheader = "</head>\n"
|
||||
|
||||
HTML.postheader = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n" \
|
||||
"<tr>\n" \
|
||||
"<td class=\"postheader\" valign=\"center\">" \
|
||||
"<a href=\"index.html\">Home</a> ·" \
|
||||
" <a href=\"classes.html\">All Classes</a> ·" \
|
||||
"</td></tr></table>"
|
||||
|
||||
HTML.footer = "<p /><address><hr /><div align=\"center\">\n" \
|
||||
"<table width=\"100%\" cellspacing=\"0\" border=\"0\"><tr class=\"address\">\n" \
|
||||
"<td width=\"40%\" align=\"left\">Copyright © 2000-2012</td>\n" \
|
||||
"<td width=\"20%\" align=\"center\"><a href=\"http://code.google.com/p/qextserialport\">QextSerialPort Project</a></td>\n" \
|
||||
"<td width=\"40%\" align=\"right\"><div align=\"right\">QextSerialPort Manual</div></td>\n" \
|
||||
"</tr></table></div></address>"
|
||||
@@ -0,0 +1,35 @@
|
||||
Note:
|
||||
|
||||
If you are using qextserialport-XXX.tar.gz, the qesp.qch and
|
||||
html files have been provided.
|
||||
|
||||
Open the file "html/index.html" using your web browser.
|
||||
Or integrated the "html/qesp.qch" into your QtCreator.
|
||||
|
||||
|
||||
== How to generate help files? ==
|
||||
|
||||
Simply run following commands at toplevel directory.
|
||||
qmake
|
||||
make docs
|
||||
|
||||
Or run the following command at this directory
|
||||
qdoc3 qextserialport.qdocconf
|
||||
|
||||
Then a folder called "html" will be generated.
|
||||
Open the file "html/index.html" using your web browser.
|
||||
|
||||
== How to integrated into Qt Creator or Qt Assistant? ==
|
||||
|
||||
Once the html files are generated. run following commands
|
||||
cd doc/html
|
||||
qhelpgenerator qesp.qhp
|
||||
|
||||
A file called "qesp.qch" will be generated.
|
||||
|
||||
For Qt Assistant:
|
||||
Edit ==> Preferences ==> Documentations ==> Add...
|
||||
|
||||
For Qt Creator
|
||||
Tools ==> Options ==> Help ==> Documentations ==> Add...
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
a:link, a:visited {
|
||||
color: #00732F;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
body {
|
||||
font: normal 400 14px/1.2 Arial;
|
||||
margin-top: 85px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font: 500 20px/1.2 Arial;
|
||||
}
|
||||
|
||||
h3.fn, span.fn {
|
||||
-moz-border-radius: 7px 7px 7px 7px;
|
||||
-webkit-border-radius: 7px 7px 7px 7px;
|
||||
border-radius: 7px 7px 7px 7px;
|
||||
background-color: #F6F6F6;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: #E6E6E6;
|
||||
word-spacing: 3px;
|
||||
padding: 3px 5px;
|
||||
}
|
||||
|
||||
table, pre {
|
||||
-moz-border-radius: 7px 7px 7px 7px;
|
||||
-webkit-border-radius: 7px 7px 7px 7px;
|
||||
border-radius: 7px 7px 7px 7px;
|
||||
background-color: #F6F6F6;
|
||||
border: 1px solid #E6E6E6;
|
||||
border-collapse: separate;
|
||||
font-size: 12px;
|
||||
line-height: 1.2;
|
||||
margin-bottom: 25px;
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
table td {
|
||||
padding: 3px 15px 3px 20px;
|
||||
}
|
||||
|
||||
table tr.even {
|
||||
background-color: white;
|
||||
color: #66666E;
|
||||
}
|
||||
|
||||
table tr.odd {
|
||||
background-color: #F6F6F6;
|
||||
color: #66666E;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 10px;
|
||||
padding-left: 12px;
|
||||
}
|
||||
|
||||
.cpp {
|
||||
display: block;
|
||||
margin: 10;
|
||||
overflow: hidden;
|
||||
overflow-x: hidden;
|
||||
overflow-y: hidden;
|
||||
padding: 20px 0 20px 0;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.memItemLeft {
|
||||
padding-right: 3px;
|
||||
}
|
||||
|
||||
.memItemRight {
|
||||
padding: 3px 15px 3px 0;
|
||||
}
|
||||
|
||||
.qml {
|
||||
display: block;
|
||||
margin: 10;
|
||||
overflow: hidden;
|
||||
overflow-x: hidden;
|
||||
overflow-y: hidden;
|
||||
padding: 20px 0 20px 0;
|
||||
}
|
||||
|
||||
.qmldefault {
|
||||
padding-left: 5px;
|
||||
float: right;
|
||||
color: red;
|
||||
}
|
||||
|
||||
.qmlreadonly {
|
||||
padding-left: 5px;
|
||||
float: right;
|
||||
color: #254117;
|
||||
}
|
||||
|
||||
.rightAlign {
|
||||
padding: 3px 5px 3px 10px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.title {
|
||||
background-color: white;
|
||||
color: #44A51C;
|
||||
font-family: Verdana;
|
||||
font-size: 35px;
|
||||
font-weight: normal;
|
||||
left: 0;
|
||||
padding-bottom: 5px;
|
||||
padding-left: 16px;
|
||||
padding-top: 20px;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.toc {
|
||||
float: right;
|
||||
-moz-border-radius: 7px 7px 7px 7px;
|
||||
-webkit-border-radius: 7px 7px 7px 7px;
|
||||
border-radius: 7px 7px 7px 7px;
|
||||
background-color: #F6F6F6;
|
||||
border: 1px solid #DDD;
|
||||
margin: 0 20px 10px 10px;
|
||||
padding: 20px 15px 20px 20px;
|
||||
height: auto;
|
||||
width: 200px;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
CONFIG += console
|
||||
include(../../src/qextserialport.pri)
|
||||
SOURCES += main.cpp
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
//! [0]
|
||||
#include "qextserialenumerator.h"
|
||||
//! [0]
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QDebug>
|
||||
int main()
|
||||
{
|
||||
//! [1]
|
||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||
//! [1]
|
||||
qDebug() << "List of ports:";
|
||||
//! [2]
|
||||
foreach (QextPortInfo info, ports) {
|
||||
qDebug() << "port name:" << info.portName;
|
||||
qDebug() << "friendly name:" << info.friendName;
|
||||
qDebug() << "physical name:" << info.physName;
|
||||
qDebug() << "enumerator name:" << info.enumName;
|
||||
qDebug() << "vendor ID:" << info.vendorID;
|
||||
qDebug() << "product ID:" << info.productID;
|
||||
|
||||
qDebug() << "===================================";
|
||||
}
|
||||
//! [2]
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "PortListener.h"
|
||||
#include <QtDebug>
|
||||
|
||||
PortListener::PortListener(const QString &portName)
|
||||
{
|
||||
qDebug() << "hi there";
|
||||
this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
|
||||
port->setBaudRate(BAUD38400);
|
||||
port->setFlowControl(FLOW_OFF);
|
||||
port->setParity(PAR_NONE);
|
||||
port->setDataBits(DATA_8);
|
||||
port->setStopBits(STOP_1);
|
||||
|
||||
if (port->open(QIODevice::ReadWrite) == true) {
|
||||
connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||
connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
|
||||
if (!(port->lineStatus() & LS_DSR))
|
||||
qDebug() << "warning: device is not turned on";
|
||||
qDebug() << "listening for data on" << port->portName();
|
||||
}
|
||||
else {
|
||||
qDebug() << "device failed to open:" << port->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
void PortListener::onReadyRead()
|
||||
{
|
||||
QByteArray bytes;
|
||||
int a = port->bytesAvailable();
|
||||
bytes.resize(a);
|
||||
port->read(bytes.data(), bytes.size());
|
||||
qDebug() << "bytes read:" << bytes.size();
|
||||
qDebug() << "bytes:" << bytes;
|
||||
}
|
||||
|
||||
void PortListener::onDsrChanged(bool status)
|
||||
{
|
||||
if (status)
|
||||
qDebug() << "device was turned on";
|
||||
else
|
||||
qDebug() << "device was turned off";
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#ifndef PORTLISTENER_H_
|
||||
#define PORTLISTENER_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "qextserialport.h"
|
||||
|
||||
class PortListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PortListener(const QString &portName);
|
||||
|
||||
private:
|
||||
QextSerialPort *port;
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onDsrChanged(bool status);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /*PORTLISTENER_H_*/
|
||||
@@ -0,0 +1,7 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
CONFIG += console
|
||||
include(../../src/qextserialport.pri)
|
||||
|
||||
SOURCES += main.cpp PortListener.cpp
|
||||
HEADERS += PortListener.h
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Michal Policht
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include "PortListener.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QString portName = QLatin1String("/dev/ttyS0"); // update this to use your port of choice
|
||||
PortListener listener(portName); // signals get hooked up internally
|
||||
|
||||
// start the event loop and wait for signals
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS = qespta enumerator \
|
||||
uartassistant
|
||||
win32:SUBDIRS += event
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file MainWindow.cpp
|
||||
* @brief MainWindow Implementation.
|
||||
* @see MainWindow.h
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QMenuBar>
|
||||
#include "MainWindow.h"
|
||||
#include "MessageWindow.h"
|
||||
#include "QespTest.h"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
//central widget
|
||||
QespTest *qespTest = new QespTest();
|
||||
setCentralWidget(qespTest);
|
||||
//bottom dock widget
|
||||
MessageWindow *msgWindow = new MessageWindow();
|
||||
addDockWidget(Qt::BottomDockWidgetArea, msgWindow);
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
|
||||
setWindowTitle(tr("QextSerialPort Test Application"));
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About "),
|
||||
tr("<B>""</B><BR>"
|
||||
"author: Michal Policht<br>"
|
||||
"<a href='mailto:xpolik@users.sourceforge.net'>xpolik@users.sourceforge.net</a>"));
|
||||
}
|
||||
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
//File actions
|
||||
exitAct = new QAction(tr("E&xit"), this);
|
||||
exitAct->setShortcut(tr("CTRL+D"));
|
||||
exitAct->setStatusTip(tr("Exit the application"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
//Help actions
|
||||
aboutAct = new QAction(tr("&About"), this);
|
||||
aboutAct->setShortcut(tr("CTRL+A"));
|
||||
aboutAct->setStatusTip(tr("About application"));
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu->addAction(exitAct);
|
||||
|
||||
helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu->addAction(aboutAct);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file MainWindow.h
|
||||
* @brief Application's Main Window.
|
||||
* @see MainWindow
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#ifndef MAINWINDOW_H_
|
||||
#define MAINWINDOW_H_
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QMenu;
|
||||
class QAction;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QMenu *fileMenu;
|
||||
QAction *exitAct;
|
||||
QMenu *helpMenu;
|
||||
QAction *aboutAct;
|
||||
|
||||
private:
|
||||
void createMenus();
|
||||
void createActions();
|
||||
|
||||
private slots:
|
||||
void about();
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
};
|
||||
|
||||
#endif /*MAINWINDOW_H_*/
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file MessageWindow.cpp
|
||||
* @brief MessageWindow Implementation.
|
||||
* @see MessageWindow.h
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "MessageWindow.h"
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QMutexLocker>
|
||||
|
||||
const char *MessageWindow::WINDOW_TITLE = "Message Window";
|
||||
MessageWindow *MessageWindow::MsgHandler = NULL;
|
||||
|
||||
MessageWindow::MessageWindow(QWidget *parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags),
|
||||
msgTextEdit(this)
|
||||
{
|
||||
setWindowTitle(tr(WINDOW_TITLE));
|
||||
msgTextEdit.setReadOnly(true);
|
||||
setWidget(&msgTextEdit);
|
||||
|
||||
MessageWindow::MsgHandler = this;
|
||||
}
|
||||
|
||||
//static
|
||||
QString MessageWindow::QtMsgToQString(QtMsgType type, const char *msg)
|
||||
{
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
return QLatin1String("Debug: ")+QLatin1String(msg);
|
||||
case QtWarningMsg:
|
||||
return QLatin1String("Warning: ")+QLatin1String(msg);
|
||||
case QtCriticalMsg:
|
||||
return QLatin1String("Critical: ")+QLatin1String(msg);
|
||||
case QtFatalMsg:
|
||||
return QLatin1String("Fatal: ")+QLatin1String(msg);
|
||||
default:
|
||||
return QLatin1String("Unrecognized message type: ")+QLatin1String(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//static
|
||||
void MessageWindow::AppendMsgWrapper(QtMsgType type, const char *msg)
|
||||
{
|
||||
static QMutex mutex;
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
if (MessageWindow::MsgHandler != NULL)
|
||||
return MessageWindow::MsgHandler->postMsgEvent(type, msg);
|
||||
else
|
||||
fprintf(stderr, "%s", MessageWindow::QtMsgToQString(type, msg).toLatin1().data());
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
void MessageWindow::AppendMsgWrapper(QtMsgType type, const QMessageLogContext & /*context*/, const QString &msg)
|
||||
{
|
||||
AppendMsgWrapper(type, msg.toLatin1().data());
|
||||
}
|
||||
#endif
|
||||
|
||||
void MessageWindow::customEvent(QEvent *event)
|
||||
{
|
||||
if (static_cast<MessageWindow::EventType>(event->type()) == MessageWindow::MessageEventType)
|
||||
msgTextEdit.append(dynamic_cast<MessageEvent *>(event)->msg);
|
||||
}
|
||||
|
||||
void MessageWindow::postMsgEvent(QtMsgType type, const char *msg)
|
||||
{
|
||||
QString qmsg = MessageWindow::QtMsgToQString(type, msg);
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
qmsg.prepend(QLatin1String("<FONT color=\"#FF0000\">"));
|
||||
qmsg.append(QLatin1String("</FONT>"));
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
if (QMessageBox::critical(this, QLatin1String("Critical Error"), qmsg,
|
||||
QMessageBox::Ignore,
|
||||
QMessageBox::Abort,
|
||||
QMessageBox::NoButton) == QMessageBox::Abort)
|
||||
abort(); // core dump
|
||||
qmsg.prepend(QLatin1String("<B><FONT color=\"#FF0000\">"));
|
||||
qmsg.append(QLatin1String("</FONT></B>"));
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
QMessageBox::critical(this, QLatin1String("Fatal Error"), qmsg, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
|
||||
abort(); // deliberately core dump
|
||||
}
|
||||
//it's impossible to change GUI directly from thread other than the main thread
|
||||
//so post message encapsulated by MessageEvent to the main thread's event queue
|
||||
QCoreApplication::postEvent(this, new MessageEvent(qmsg));
|
||||
}
|
||||
|
||||
MessageEvent::MessageEvent(QString &msg):
|
||||
QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEventType))
|
||||
{
|
||||
this->msg = msg;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file MessageWindow.h
|
||||
* @brief Message Window.
|
||||
* @see MessageWindow
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#ifndef MESSAGEWINDOW_H_
|
||||
#define MESSAGEWINDOW_H_
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QEvent>
|
||||
|
||||
/**
|
||||
* Message Window. Handling errors and other messages.
|
||||
*/
|
||||
class MessageWindow: public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QTextEdit msgTextEdit; ///< Main widget.
|
||||
static MessageWindow *MsgHandler; ///< Set in constructor.
|
||||
static const char *WINDOW_TITLE; ///< Window title.
|
||||
|
||||
private:
|
||||
static QString QtMsgToQString(QtMsgType type, const char *msg);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Handle custom events. MessageWindow hadles custom events listed in
|
||||
* EventType enum.
|
||||
*/
|
||||
virtual void customEvent(QEvent* event);
|
||||
|
||||
public:
|
||||
enum EventType {MessageEventType = QEvent::User}; ///< Custom event types.
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* @param parent parent widget.
|
||||
* @param flags widget flags.
|
||||
*/
|
||||
MessageWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
|
||||
/**
|
||||
* Append message wrapper. Since ISO forbids casting member functions
|
||||
* to C functions, wrapper is needed to use this class as QtMsgHandler.
|
||||
* This method is thread-safe but not reentrant.
|
||||
* @param type message type.
|
||||
* @param msg message string.
|
||||
*/
|
||||
static void AppendMsgWrapper(QtMsgType type, const char *msg);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
static void AppendMsgWrapper(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
#endif
|
||||
/**
|
||||
* Post message event to the main event loop. This function encapsulates
|
||||
* message into MessageEvent object and passes it to the main event loop.
|
||||
* @param type message type.
|
||||
* @param msg message string.
|
||||
*/
|
||||
void postMsgEvent(QtMsgType type, const char *msg);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Message Event. Custom event used by @ref MessageWindow to provide multi-threaded
|
||||
* access. Encapsulates message inside @a msg variable.
|
||||
*/
|
||||
class MessageEvent: public QEvent
|
||||
{
|
||||
public:
|
||||
QString msg; ///< Message string.
|
||||
|
||||
/**
|
||||
* Contructor.
|
||||
* @param msg message to post.
|
||||
*/
|
||||
MessageEvent(QString &msg);
|
||||
};
|
||||
|
||||
#endif /*MESSAGEWINDOW_H_*/
|
||||
@@ -0,0 +1,128 @@
|
||||
/* QespTest.cpp
|
||||
**************************************/
|
||||
#include "QespTest.h"
|
||||
#include "qextserialport.h"
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
|
||||
|
||||
QespTest::QespTest(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
||||
{
|
||||
//modify the port settings on your own
|
||||
#ifdef Q_OS_UNIX
|
||||
port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
|
||||
#else
|
||||
port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
|
||||
#endif /*Q_OS_UNIX*/
|
||||
port->setBaudRate(BAUD19200);
|
||||
port->setFlowControl(FLOW_OFF);
|
||||
port->setParity(PAR_NONE);
|
||||
port->setDataBits(DATA_8);
|
||||
port->setStopBits(STOP_2);
|
||||
//set timeouts to 500 ms
|
||||
port->setTimeout(500);
|
||||
|
||||
message = new QLineEdit(this);
|
||||
|
||||
// transmit receive
|
||||
QPushButton *transmitButton = new QPushButton(tr("Transmit"));
|
||||
connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
|
||||
QPushButton *receiveButton = new QPushButton(tr("Receive"));
|
||||
connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
|
||||
QHBoxLayout *trLayout = new QHBoxLayout;
|
||||
trLayout->addWidget(transmitButton);
|
||||
trLayout->addWidget(receiveButton);
|
||||
|
||||
//CR LF
|
||||
QPushButton *CRButton = new QPushButton(tr("CR"));
|
||||
connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
|
||||
QPushButton *LFButton = new QPushButton(tr("LF"));
|
||||
connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
|
||||
QHBoxLayout *crlfLayout = new QHBoxLayout;
|
||||
crlfLayout->addWidget(CRButton);
|
||||
crlfLayout->addWidget(LFButton);
|
||||
|
||||
//open close
|
||||
QPushButton *openButton = new QPushButton(tr("Open"));
|
||||
connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
|
||||
QPushButton *closeButton = new QPushButton(tr("Close"));
|
||||
connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
|
||||
QHBoxLayout *ocLayout = new QHBoxLayout;
|
||||
ocLayout->addWidget(openButton);
|
||||
ocLayout->addWidget(closeButton);
|
||||
|
||||
received_msg = new QTextEdit();
|
||||
|
||||
QVBoxLayout *myVBox = new QVBoxLayout;
|
||||
myVBox->addWidget(message);
|
||||
myVBox->addLayout(crlfLayout);
|
||||
myVBox->addLayout(trLayout);
|
||||
myVBox->addLayout(ocLayout);
|
||||
myVBox->addWidget(received_msg);
|
||||
setLayout(myVBox);
|
||||
|
||||
qDebug("isOpen : %d", port->isOpen());
|
||||
}
|
||||
|
||||
QespTest::~QespTest()
|
||||
{
|
||||
delete port;
|
||||
port = NULL;
|
||||
}
|
||||
|
||||
void QespTest::transmitMsg()
|
||||
{
|
||||
int i = port->write(message->text().toLatin1());
|
||||
qDebug("trasmitted : %d", i);
|
||||
}
|
||||
|
||||
void QespTest::receiveMsg()
|
||||
{
|
||||
char buff[1024];
|
||||
int numBytes;
|
||||
|
||||
numBytes = port->bytesAvailable();
|
||||
if(numBytes > 1024)
|
||||
numBytes = 1024;
|
||||
|
||||
int i = port->read(buff, numBytes);
|
||||
if (i != -1)
|
||||
buff[i] = '\0';
|
||||
else
|
||||
buff[0] = '\0';
|
||||
QString msg = QLatin1String(buff);
|
||||
|
||||
received_msg->append(msg);
|
||||
received_msg->ensureCursorVisible();
|
||||
qDebug("bytes available: %d", numBytes);
|
||||
qDebug("received: %d", i);
|
||||
}
|
||||
|
||||
|
||||
void QespTest::appendCR()
|
||||
{
|
||||
message->insert(QLatin1String("\x0D"));
|
||||
}
|
||||
|
||||
void QespTest::appendLF()
|
||||
{
|
||||
message->insert(QLatin1String("\x0A"));
|
||||
}
|
||||
|
||||
void QespTest::closePort()
|
||||
{
|
||||
port->close();
|
||||
qDebug("is open: %d", port->isOpen());
|
||||
}
|
||||
|
||||
void QespTest::openPort()
|
||||
{
|
||||
port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
|
||||
qDebug("is open: %d", port->isOpen());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* qesptest.h
|
||||
**************************************/
|
||||
#ifndef _QESPTEST_H_
|
||||
#define _QESPTEST_H_
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
class QextSerialPort;
|
||||
class QSpinBox;
|
||||
|
||||
class QespTest : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QespTest(QWidget *parent=0);
|
||||
|
||||
virtual ~QespTest();
|
||||
|
||||
private:
|
||||
QLineEdit *message;
|
||||
QSpinBox *delaySpinBox;
|
||||
QTextEdit *received_msg;
|
||||
QextSerialPort *port;
|
||||
|
||||
private slots:
|
||||
void transmitMsg();
|
||||
void receiveMsg();
|
||||
void appendCR();
|
||||
void appendLF();
|
||||
void closePort();
|
||||
void openPort();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,4 @@
|
||||
This is simple application using QextSerialPort library.
|
||||
|
||||
Port settings are in QespTest constructor (QespTest.cpp)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Micha? Policht
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include "MainWindow.h"
|
||||
#include "MessageWindow.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
//! [0]
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
//redirect debug messages to the MessageWindow dialog
|
||||
qInstallMsgHandler(MessageWindow::AppendMsgWrapper);
|
||||
#else
|
||||
qInstallMessageHandler(MessageWindow::AppendMsgWrapper);
|
||||
#endif
|
||||
//! [0]
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
QT += core gui
|
||||
contains(QT_VERSION, ^5\\..*\\..*): QT += widgets
|
||||
HEADERS += MainWindow.h \
|
||||
MessageWindow.h \
|
||||
QespTest.h
|
||||
|
||||
SOURCES += main.cpp \
|
||||
MainWindow.cpp \
|
||||
MessageWindow.cpp \
|
||||
QespTest.cpp
|
||||
|
||||
include(../../src/qextserialport.pri)
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "qextserialport.h"
|
||||
#include "qextserialenumerator.h"
|
||||
#include "dialog.h"
|
||||
#include "ui_dialog.h"
|
||||
#include <QtCore>
|
||||
|
||||
Dialog::Dialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Dialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//! [0]
|
||||
foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
|
||||
ui->portBox->addItem(info.portName);
|
||||
//make sure user can input their own port name!
|
||||
ui->portBox->setEditable(true);
|
||||
|
||||
ui->baudRateBox->addItem("1200", BAUD1200);
|
||||
ui->baudRateBox->addItem("2400", BAUD2400);
|
||||
ui->baudRateBox->addItem("4800", BAUD4800);
|
||||
ui->baudRateBox->addItem("9600", BAUD9600);
|
||||
ui->baudRateBox->addItem("19200", BAUD19200);
|
||||
ui->baudRateBox->setCurrentIndex(3);
|
||||
|
||||
ui->parityBox->addItem("NONE", PAR_NONE);
|
||||
ui->parityBox->addItem("ODD", PAR_ODD);
|
||||
ui->parityBox->addItem("EVEN", PAR_EVEN);
|
||||
|
||||
ui->dataBitsBox->addItem("5", DATA_5);
|
||||
ui->dataBitsBox->addItem("6", DATA_6);
|
||||
ui->dataBitsBox->addItem("7", DATA_7);
|
||||
ui->dataBitsBox->addItem("8", DATA_8);
|
||||
ui->dataBitsBox->setCurrentIndex(3);
|
||||
|
||||
ui->stopBitsBox->addItem("1", STOP_1);
|
||||
ui->stopBitsBox->addItem("2", STOP_2);
|
||||
|
||||
ui->queryModeBox->addItem("Polling", QextSerialPort::Polling);
|
||||
ui->queryModeBox->addItem("EventDriven", QextSerialPort::EventDriven);
|
||||
//! [0]
|
||||
|
||||
ui->led->turnOff();
|
||||
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(40);
|
||||
//! [1]
|
||||
PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
|
||||
port = new QextSerialPort(ui->portBox->currentText(), settings, QextSerialPort::Polling);
|
||||
//! [1]
|
||||
|
||||
enumerator = new QextSerialEnumerator(this);
|
||||
enumerator->setUpNotifications();
|
||||
|
||||
connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), SLOT(onBaudRateChanged(int)));
|
||||
connect(ui->parityBox, SIGNAL(currentIndexChanged(int)), SLOT(onParityChanged(int)));
|
||||
connect(ui->dataBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onDataBitsChanged(int)));
|
||||
connect(ui->stopBitsBox, SIGNAL(currentIndexChanged(int)), SLOT(onStopBitsChanged(int)));
|
||||
connect(ui->queryModeBox, SIGNAL(currentIndexChanged(int)), SLOT(onQueryModeChanged(int)));
|
||||
connect(ui->timeoutBox, SIGNAL(valueChanged(int)), SLOT(onTimeoutChanged(int)));
|
||||
connect(ui->portBox, SIGNAL(editTextChanged(QString)), SLOT(onPortNameChanged(QString)));
|
||||
connect(ui->openCloseButton, SIGNAL(clicked()), SLOT(onOpenCloseButtonClicked()));
|
||||
connect(ui->sendButton, SIGNAL(clicked()), SLOT(onSendButtonClicked()));
|
||||
connect(timer, SIGNAL(timeout()), SLOT(onReadyRead()));
|
||||
connect(port, SIGNAL(readyRead()), SLOT(onReadyRead()));
|
||||
|
||||
connect(enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
|
||||
connect(enumerator, SIGNAL(deviceRemoved(QextPortInfo)), SLOT(onPortAddedOrRemoved()));
|
||||
|
||||
setWindowTitle(tr("QextSerialPort Demo"));
|
||||
}
|
||||
|
||||
Dialog::~Dialog()
|
||||
{
|
||||
delete ui;
|
||||
delete port;
|
||||
}
|
||||
|
||||
void Dialog::changeEvent(QEvent *e)
|
||||
{
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::onPortNameChanged(const QString & /*name*/)
|
||||
{
|
||||
if (port->isOpen()) {
|
||||
port->close();
|
||||
ui->led->turnOff();
|
||||
}
|
||||
}
|
||||
//! [2]
|
||||
void Dialog::onBaudRateChanged(int idx)
|
||||
{
|
||||
port->setBaudRate((BaudRateType)ui->baudRateBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onParityChanged(int idx)
|
||||
{
|
||||
port->setParity((ParityType)ui->parityBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onDataBitsChanged(int idx)
|
||||
{
|
||||
port->setDataBits((DataBitsType)ui->dataBitsBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onStopBitsChanged(int idx)
|
||||
{
|
||||
port->setStopBits((StopBitsType)ui->stopBitsBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onQueryModeChanged(int idx)
|
||||
{
|
||||
port->setQueryMode((QextSerialPort::QueryMode)ui->queryModeBox->itemData(idx).toInt());
|
||||
}
|
||||
|
||||
void Dialog::onTimeoutChanged(int val)
|
||||
{
|
||||
port->setTimeout(val);
|
||||
}
|
||||
//! [2]
|
||||
//! [3]
|
||||
void Dialog::onOpenCloseButtonClicked()
|
||||
{
|
||||
if (!port->isOpen()) {
|
||||
port->setPortName(ui->portBox->currentText());
|
||||
port->open(QIODevice::ReadWrite);
|
||||
}
|
||||
else {
|
||||
port->close();
|
||||
}
|
||||
|
||||
//If using polling mode, we need a QTimer
|
||||
if (port->isOpen() && port->queryMode() == QextSerialPort::Polling)
|
||||
timer->start();
|
||||
else
|
||||
timer->stop();
|
||||
|
||||
//update led's status
|
||||
ui->led->turnOn(port->isOpen());
|
||||
}
|
||||
//! [3]
|
||||
//! [4]
|
||||
void Dialog::onSendButtonClicked()
|
||||
{
|
||||
if (port->isOpen() && !ui->sendEdit->toPlainText().isEmpty())
|
||||
port->write(ui->sendEdit->toPlainText().toLatin1());
|
||||
}
|
||||
|
||||
void Dialog::onReadyRead()
|
||||
{
|
||||
if (port->bytesAvailable()) {
|
||||
ui->recvEdit->moveCursor(QTextCursor::End);
|
||||
ui->recvEdit->insertPlainText(QString::fromLatin1(port->readAll()));
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::onPortAddedOrRemoved()
|
||||
{
|
||||
QString current = ui->portBox->currentText();
|
||||
|
||||
ui->portBox->blockSignals(true);
|
||||
ui->portBox->clear();
|
||||
foreach (QextPortInfo info, QextSerialEnumerator::getPorts())
|
||||
ui->portBox->addItem(info.portName);
|
||||
|
||||
ui->portBox->setCurrentIndex(ui->portBox->findText(current));
|
||||
|
||||
ui->portBox->blockSignals(false);
|
||||
}
|
||||
|
||||
//! [4]
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef DIALOG_H
|
||||
#define DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class Dialog;
|
||||
}
|
||||
class QTimer;
|
||||
class QextSerialPort;
|
||||
class QextSerialEnumerator;
|
||||
|
||||
class Dialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Dialog(QWidget *parent = 0);
|
||||
~Dialog();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPortNameChanged(const QString &name);
|
||||
void onBaudRateChanged(int idx);
|
||||
void onParityChanged(int idx);
|
||||
void onDataBitsChanged(int idx);
|
||||
void onStopBitsChanged(int idx);
|
||||
void onQueryModeChanged(int idx);
|
||||
void onTimeoutChanged(int val);
|
||||
void onOpenCloseButtonClicked();
|
||||
void onSendButtonClicked();
|
||||
void onReadyRead();
|
||||
|
||||
void onPortAddedOrRemoved();
|
||||
|
||||
private:
|
||||
Ui::Dialog *ui;
|
||||
QTimer *timer;
|
||||
QextSerialPort *port;
|
||||
QextSerialEnumerator *enumerator;
|
||||
};
|
||||
|
||||
#endif // DIALOG_H
|
||||
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>604</width>
|
||||
<height>485</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="3,1">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="recvEdit">
|
||||
<property name="maximumBlockCount">
|
||||
<number>800</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="sendEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="portBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>BaudRate:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="baudRateBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>DataBits:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="dataBitsBox"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Parity:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="parityBox"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>StopBits:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="stopBitsBox"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>QueryMode:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="queryModeBox"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Timeout:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QSpinBox" name="timeoutBox">
|
||||
<property name="suffix">
|
||||
<string> ms</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="HLed" name="led" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>25</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openCloseButton">
|
||||
<property name="text">
|
||||
<string>Open/Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="sendButton">
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>HLed</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>hled.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,133 @@
|
||||
#include <QtGui>
|
||||
#include "hled.h"
|
||||
|
||||
struct HLed::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: darkerFactor(300), color(Qt::green), isOn(true)
|
||||
{ }
|
||||
|
||||
int darkerFactor;
|
||||
QColor color;
|
||||
bool isOn;
|
||||
};
|
||||
|
||||
HLed::HLed(QWidget *parent)
|
||||
:QWidget(parent), m_d(new Private)
|
||||
{
|
||||
}
|
||||
|
||||
HLed::~HLed()
|
||||
{
|
||||
delete m_d;
|
||||
}
|
||||
|
||||
QColor HLed::color() const
|
||||
{
|
||||
return m_d->color;
|
||||
}
|
||||
|
||||
void HLed::setColor(const QColor &color)
|
||||
{
|
||||
if (m_d->color == color)
|
||||
return;
|
||||
update();
|
||||
}
|
||||
|
||||
QSize HLed::sizeHint() const
|
||||
{
|
||||
return QSize(20, 20);
|
||||
}
|
||||
|
||||
QSize HLed::minimumSizeHint() const
|
||||
{
|
||||
return QSize(16, 16);
|
||||
}
|
||||
|
||||
void HLed::toggle()
|
||||
{
|
||||
m_d->isOn = !m_d->isOn;
|
||||
update();
|
||||
}
|
||||
|
||||
void HLed::turnOn(bool on)
|
||||
{
|
||||
m_d->isOn = on;
|
||||
update();
|
||||
}
|
||||
|
||||
void HLed::turnOff(bool off)
|
||||
{
|
||||
turnOn(!off);
|
||||
}
|
||||
|
||||
void HLed::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
int width = ledWidth();
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QColor color = m_d->isOn ? m_d->color
|
||||
: m_d->color.darker(m_d->darkerFactor);
|
||||
|
||||
QBrush brush;
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
brush.setColor(color);
|
||||
painter.setBrush(brush);
|
||||
// draw plain
|
||||
painter.drawEllipse(1, 1, width-1, width-1);
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
|
||||
int pos = width / 5 + 1;
|
||||
int lightWidth = width * 2 / 3;
|
||||
int lightQuote = 130 * 2 / (lightWidth ? lightWidth : 1) + 100;
|
||||
|
||||
// draw bright spot
|
||||
while (lightWidth) {
|
||||
color = color.lighter(lightQuote);
|
||||
pen.setColor(color);
|
||||
painter.setPen(pen);
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
lightWidth--;
|
||||
|
||||
if (!lightWidth)
|
||||
break;
|
||||
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
lightWidth--;
|
||||
|
||||
if (!lightWidth)
|
||||
break;
|
||||
|
||||
painter.drawEllipse(pos, pos, lightWidth, lightWidth);
|
||||
pos++;
|
||||
lightWidth--;
|
||||
}
|
||||
|
||||
//draw border
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
|
||||
int angle = -720;
|
||||
color = palette().color(QPalette::Light);
|
||||
|
||||
for (int arc=120; arc<2880; arc+=240) {
|
||||
pen.setColor(color);
|
||||
painter.setPen(pen);
|
||||
int w = width - pen.width()/2;
|
||||
painter.drawArc(pen.width()/2, pen.width()/2, w, w, angle+arc, 240);
|
||||
painter.drawArc(pen.width()/2, pen.width()/2, w, w, angle-arc, 240);
|
||||
color = color.darker(110);
|
||||
}
|
||||
}
|
||||
|
||||
int HLed::ledWidth() const
|
||||
{
|
||||
int width = qMin(this->width(), this->height());
|
||||
width -= 2;
|
||||
return width > 0 ? width : 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef HLED_H
|
||||
#define HLED_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QColor;
|
||||
|
||||
class HLed : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HLed(QWidget *parent = 0);
|
||||
~HLed();
|
||||
|
||||
QColor color() const;
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
public slots:
|
||||
void setColor(const QColor &color);
|
||||
void toggle();
|
||||
void turnOn(bool on=true);
|
||||
void turnOff(bool off=true);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
int ledWidth() const;
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private * const m_d;
|
||||
};
|
||||
|
||||
#endif // HLED_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <QApplication>
|
||||
#include "dialog.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Dialog w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2011-11-06T21:37:41
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
contains(QT_VERSION, ^5\\..*\\..*): QT += widgets
|
||||
|
||||
TARGET = uartassistant
|
||||
TEMPLATE = app
|
||||
|
||||
include(../../src/qextserialport.pri)
|
||||
|
||||
SOURCES += main.cpp\
|
||||
dialog.cpp\
|
||||
hled.cpp
|
||||
|
||||
HEADERS += dialog.h \
|
||||
hled.h
|
||||
|
||||
FORMS += dialog.ui
|
||||
@@ -0,0 +1,24 @@
|
||||
defineReplace(qextLibraryName) {
|
||||
unset(LIBRARY_NAME)
|
||||
LIBRARY_NAME = \$\$1
|
||||
greaterThan(QT_MAJOR_VERSION, 4):LIBRARY_NAME ~= s,^Qt,Qt\$\$QT_MAJOR_VERSION,
|
||||
CONFIG(debug, debug|release) {
|
||||
!debug_and_release|build_pass {
|
||||
mac:LIBRARY_NAME = \$\${LIBRARY_NAME}_debug
|
||||
else:win32:LIBRARY_NAME = \$\${LIBRARY_NAME}d
|
||||
}
|
||||
}
|
||||
return(\$\$LIBRARY_NAME)
|
||||
}
|
||||
|
||||
!!IF qesp_mac_framework
|
||||
LIBS += -framework $$QESP_LIB_BASENAME
|
||||
INCLUDEPATH += $$[QT_INSTALL_LIBS]/$${QESP_LIB_BASENAME}.framework/Headers
|
||||
!!ELSE
|
||||
LIBS += -l\$\$qextLibraryName($$QESP_LIB_BASENAME)
|
||||
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtExtSerialPort
|
||||
!!ENDIF
|
||||
|
||||
!!IF !qesp_static
|
||||
DEFINES += QEXTSERIALPORT_USING_SHARED
|
||||
!!ENDIF
|
||||
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
############################### *User Config* ###############################
|
||||
|
||||
# Uncomment following line if you want to build a static library
|
||||
#CONFIG += qesp_static
|
||||
|
||||
# Uncomment following line if you want to build framework for mac
|
||||
# macx:CONFIG += qesp_mac_framework
|
||||
|
||||
# Uncomment following line if you want to enable udev for linux
|
||||
# linux*:CONFIG += qesp_linux_udev
|
||||
|
||||
# Note: you can create a ".qmake.cache" file, then copy these lines to it.
|
||||
# If so, you can avoid to change this project file.
|
||||
############################### *User Config* ###############################
|
||||
|
||||
defineReplace(qextLibraryName) {
|
||||
unset(LIBRARY_NAME)
|
||||
LIBRARY_NAME = $$1
|
||||
macx:qesp_mac_framework {
|
||||
QMAKE_FRAMEWORK_BUNDLE_NAME = $$LIBRARY_NAME
|
||||
export(QMAKE_FRAMEWORK_BUNDLE_NAME)
|
||||
} else {
|
||||
greaterThan(QT_MAJOR_VERSION, 4):LIBRARY_NAME ~= s,^Qt,Qt$$QT_MAJOR_VERSION,
|
||||
}
|
||||
CONFIG(debug, debug|release) {
|
||||
!debug_and_release|build_pass {
|
||||
mac:LIBRARY_NAME = $${LIBRARY_NAME}_debug
|
||||
else:win32:LIBRARY_NAME = $${LIBRARY_NAME}d
|
||||
}
|
||||
}
|
||||
return($$LIBRARY_NAME)
|
||||
}
|
||||
|
||||
TEMPLATE=lib
|
||||
include(src/qextserialport.pri)
|
||||
|
||||
#create_prl is needed, otherwise, MinGW can't found libqextserialport1.a
|
||||
CONFIG += create_prl
|
||||
|
||||
#mac framework is designed for shared library
|
||||
macx:qesp_mac_framework:qesp_static: CONFIG -= qesp_static
|
||||
!macx:qesp_mac_framework:CONFIG -= qesp_mac_framework
|
||||
|
||||
qesp_static {
|
||||
CONFIG += static
|
||||
} else {
|
||||
CONFIG += shared
|
||||
macx:!qesp_mac_framework:CONFIG += absolute_library_soname
|
||||
DEFINES += QEXTSERIALPORT_BUILD_SHARED
|
||||
}
|
||||
|
||||
#Creare lib bundle for mac
|
||||
macx:qesp_mac_framework {
|
||||
CONFIG += lib_bundle
|
||||
FRAMEWORK_HEADERS.files = $$PUBLIC_HEADERS
|
||||
FRAMEWORK_HEADERS.path = Headers
|
||||
QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS
|
||||
}
|
||||
|
||||
win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release build_all
|
||||
|
||||
#For non-windows system, only depends on QtCore module
|
||||
unix:QT = core
|
||||
else:QT = core gui
|
||||
|
||||
#generate proper library name
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
QESP_LIB_BASENAME = QtExtSerialPort
|
||||
} else {
|
||||
QESP_LIB_BASENAME = qextserialport
|
||||
}
|
||||
TARGET = $$qextLibraryName($$QESP_LIB_BASENAME)
|
||||
VERSION = 1.2.0
|
||||
|
||||
# generate feature file by qmake based on this *.in file.
|
||||
QMAKE_SUBSTITUTES += extserialport.prf.in
|
||||
OTHER_FILES += extserialport.prf.in
|
||||
|
||||
# for make docs
|
||||
include(doc/doc.pri)
|
||||
|
||||
# for make install
|
||||
win32:!qesp_static {
|
||||
dlltarget.path = $$[QT_INSTALL_BINS]
|
||||
INSTALLS += dlltarget
|
||||
}
|
||||
!macx|!qesp_mac_framework {
|
||||
headers.files = $$PUBLIC_HEADERS
|
||||
headers.path = $$[QT_INSTALL_HEADERS]/QtExtSerialPort
|
||||
INSTALLS += headers
|
||||
}
|
||||
target.path = $$[QT_INSTALL_LIBS]
|
||||
|
||||
features.files = extserialport.prf
|
||||
features.path = $$[QMAKE_MKSPECS]/features
|
||||
INSTALLS += target features
|
||||
Binary file not shown.
Reference in New Issue
Block a user