Archive for January 16th, 2009

QT and QExtSerialPort

So I’ve successfully compiled and built the QT framework on my Windows Laptop using MinGW C/C++ compiler and installed QT Creator 0.9 alpha as my IDE. I originally got complimation working with Eclipse but opted for QT Creator as it looks handy since it made especially for QT.

I am not going to go straight into coding without designing my program first, what is needed etc so I decided I’d be best working out how to do serial I/O. Serial I/O is very simple on Linux since everything on Linux is a file! /dev/ttySxx is usually the file associated with the serial charactor device. But this is no good on my Windows PC so I searched for a POSIX based Serial I/O class or library. Luckly a POSIX library for Serial Comm was developed for QT. The project is located at I downloaded version 1.1 to see how easy it would be to do serial communication.

So I took at a look at the QT project file and saw TEMPLATE = lib so this project builds a library what is expected. I navigated to the directory and done a qmake to create the Makefile and a mingw32-make.exe to build the library using MinGW and QT. (I had to set my path to ensure that all the minGW bin utilities were found system wide set PATH=%PATH%;C:\MingGW\bin. After the building I found two files in the build folder: qextserialport.dll and libqextserialport.a.

Built files of QExtSerialPort

Built files of QExtSerialPort

So now it was time to create a project and test it.

I created a test QT console project. I copied the two library files into the root directory of my project. I also copied in the required header files that are required by the compiler during complimation time. All these files are found in the QExtSerialPort root directory. There’s a few of them there. So now ready to start using them.

To use the files wasn’t as easy as just including the header file, qextserialport.h. I also had to modify the QT Project file in order to include the library for use:

I had to include these few lines:

INCLUDEPATH += C:/Documents and Settings/Donal/Desktop/Applications/qextserialport-1.1/qextserialport
QMAKE_LIBDIR += C:/Documents and Settings/Donal/Desktop/Applications/qextserialport-1.1/qextserialport/build

LIBS += -lqextserialport

I wrote some basic code to open the serial port and send a command to the ECUEmu program. I had problems opening the com port, (Com13) however. Under further investigation it is actually \\\\.\\COM13 i had to use as the port name since it > Com 8 ( However, I changed my USB->Serial adaptor to COM8 (a free one) to save hassle in other programs that only allowed to select from 1 – 8.

The code is as follows:

#include <QtCore/QCoreApplication>
#include <QtCore/QString>
#include <qextserialport.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
QCoreApplication a(argc, argv);

PortSettings portSettings;
portSettings.BaudRate = BAUD9600;
portSettings.DataBits = DATA_8;
portSettings.Parity = PAR_NONE;
portSettings.StopBits = STOP_1;
portSettings.FlowControl = FLOW_OFF;
portSettings.Timeout_Millisec = 0;

QextSerialPort* port = new QextSerialPort(“COM8″,portSettings);

bool res = false;
res = port->open(QextSerialPort::ReadWrite);

qDebug(“Connection failed!!\n”);

QString message(“010C\r”);
int total = port->write(message.toAscii(),message.length());
qDebug (“Total written = %d”, total );

return a.exec();


QExtSerialPort Test Program

QExtSerialPort Test Program

Friday, January 16th, 2009 QT Embdedded Programming 7 Comments