SerialPort

Serial port

An important feature of a serial port library is a notification when the available serial ports change, e. g. because a USB-to-serial adapter is connected or disconnected. This is particularly important when the currently used port becomes unavailable. The program must then indicate that the connection has been closed and attempt to reconnect.

Available libraries

There seem to be a number of relevant, portable, serial port libraries that are integrated with Qt:

  • QExtSerialPort: provides a signal when the available ports change.
  • QSerialDevice: forked from QExtSerialPort, and has a different interface. Provides a signal when the available ports change. Superseeded by QtSerialPort.
  • QtSerialPort: successor to QSerialDevice, official Qt addon. Integrates nicely with Qt and has a nice interface, but does not provide a signal when the available ports change (potentially due to the dependency on a private header).

QExtSerialPort and QSerialDevice don't compile with some 4.7 Qt versions due to a missing private header (qwineventnotifier_p.h). While a library should not depend on a private Qt header, this may be the only way to get notifications on Windows. This does not seem to be an issue with Qt 4.8 and Qt 5 is reported to have a public QWinEventNotifier.

Library choice

The library of choice would be QtSerialPort (due to its nice interface and good Qt integration), but it does not provide a signal when the available ports change. Therefore, its predecessor, QSerialDevice, is used. Since this library is not maintained any more (because it has been succeeded by QtSerialPort), it is included in the startkladde source tree under 3rdpary/qserialdevice. Fortunately, it provides a CMakeLists.txt which makes integration with our build system easy.

When (if) an available-ports-changed notification is added to QtSerialPort, we may want to use that library instead.

Other libraries

  • boost::asio is said to support serial ports. Being a boost library, it is portable and probably high-quality, although it does not seem simple to use. It is unknown whether it provides a notification when the available ports change. Not being a Qt library, it may not integrate with a Qt application as nicely.

Related

Wiki: Home