PDA

View Full Version : HowTo use QextSerialPort classes



freely
28th July 2010, 09:04
As I've said I'm providing here more one howto
How to build attach and use in your QT application [ Qt 4.6.3 ( latest ) ]
External serial port classes:
1. Download qextserialport-1.2win-alpha archive
2. Unpack the archive to <serport classes path>
3. Open .pro file that in the unpacked folder
4. Make it next:

PROJECT = qextserialport
TEMPLATE = lib

CONFIG += debug_and_release

CONFIG += qt
CONFIG += warn_on
CONFIG += thread

CONFIG += dll
CONFIG += staticlib

QT -= gui

OBJECTS_DIR = build/obj
MOC_DIR = build/moc
DEPENDDIR = .
INCLUDEDIR = .
HEADERS = qextserialbase.h \
qextserialport.h \
qextserialenumerator.h
SOURCES = qextserialbase.cpp \
qextserialport.cpp \
qextserialenumerator.cpp

unix: HEADERS += posix_qextserialport.h
unix: SOURCES += posix_qextserialport.cpp
unix: DEFINES += _TTY_POSIX_


win32:HEADERS += win_qextserialport.h
win32:SOURCES += win_qextserialport.cpp
win32: DEFINES += _TTY_WIN_

win32:LIBS += -lsetupapi


DESTDIR = build
DESTDIR = examples/enumerator/debug
DESTDIR = examples/qespta/debug
DESTDIR = examples/event/debug

CONFIG(debug, debug|release) {
TARGET = qextserialportd
} else {
TARGET = qextserialport
}

unix: VERSION = 1.2.0

5. build the serial port classes project assosiated with the .pro file in debug and in release mode
6. building process should produce next files: qextserialportd.dll, qextserialport.dll,libqextserialport.a in /build directory of the project
7. Each time you create new Qt project add next lines to the .pro file:

INCLUDEPATH += <serport classes path>qextserialport-1.2win-alpha
QMAKE_LIBDIR += <serport classes path>qextserialport-build-desktop\build
CONFIG(debug, debug|release):LIBS += -lqextserialportd
else:LIBS += -lqextserialport
unix: DEFINES = _TTY_POSIX_
win32: DEFINES = _TTY_WIN_

in appropriated positions in your application .pro file

8. Enjoy using RS232 with Qt
Pavel
pmazniker@gmail.com

Handi
29th July 2010, 04:01
I've tried this but I haven't had any luck on win7.

I get the following error with both QextSerialPort and QSerialDevice:
:: error: cannot find -lqextserialportd

Neither can I manage to access the serial port using straightforward winapi, it gives the error file not found when I'm trying to open the port COM1.

Right now I can only manage to make it work on visual basic, I need help :confused:


EDIT: actually, I've managed to build a project now by following your steps more throughly (there were some problems with directories) but whenever I'm trying to run the program, it crashes with error code -1073741515. I've tried both the enumerator and event programs provided in the examples.

freely
29th July 2010, 15:59
<< I get the following error with both QextSerialPort and QSerialDevice:
:: error: cannot find -lqextserialportd
>>is there extserialportd.dll in build directory? Did you build in release or in debug? What .pro file did you use?
<<EDIT: actually, I've managed to build a project now by following your steps more throughly (there were some problems with directories) but whenever I'm trying to run the program, it crashes with error code -1073741515. I've tried both the enumerator and event programs provided in the examples.
>>Try Linux hhh

Handi
29th July 2010, 19:59
Ok, I finally managed to make it work.
I'm new to Qt, so I still don't know very well how .pro files behave.

If you are having problems to make the examples work in windows 7 do the following:

1 - Create a new Qt project (Qt Console Application) in the folder myQext (you can put it anywhere)

2 - copy all the .h and .cpp files from the "qextserialport-1.2win-alpha" folder to the myQext folder. That should be 10 files.

3 - copy the PortListener.h and PortListener.cpp files from "qextserialport-1.2win-alpha/examples/event/"

4 - Add all those 12 files to your project.

5 - replace the contains of your main.cpp file by the main.cpp file in the event folder.

6 - Save all. Run qmake. Build all. Execute.

*note: you do not need to edit the .pro file.

freely
30th July 2010, 10:43
Great!
It is good way to use QextSerialPort
Actually you can build your project in different ways - you can attach classes to your project or you can build classes separeted into static or dynamica library and then attach them to your project by editing .pro file and using the libraries
What if you need to attach more weighted third party project to your one?
For example QWT?

freely
30th July 2010, 10:53
I've found other classes developed in 2009 by some Russian developer to work with Serial Port in Qt:
http://qt-apps.org/content/show.php?content=112039

this is alternative to QextSerialPort

what do you think about it?
Did you try to use it?
What is more reliable and robust QextSerialPort or QSerialDevice?

freely
30th July 2010, 10:54
Today I have the same problem with mingw when I try to compile QextSerialPort
mingw32-make: *** [makefile] Error -1073741819

why?

Handi
30th July 2010, 18:32
From my experience, I've got those errors either when a pointer wasn't initialized properly or when there was a mess in a .pro file.

If you are using Qext as a dll I don't know what to advise you. Anyway I've attached a serial console I've made, it might help. It is very straightforward.

Handi
30th July 2010, 19:04
Also, I've tried QSerialDevice but I didn't have any luck compiling it so I gave up on it.

cazc
22nd August 2010, 23:24
Hey people.

first off all, i will say that, im building a program in QT creator 2 (4.7) on win 7, a part of the program should could control the RTS and DTR or just turn the port on off.

after following concret instructions from handi (and others), i get tons off errors (139 to be specific) trying to build it.
Most off the errors or in/regarding posix.serialport.h and .cpp
its errors like, termios.h no such file...
and Posix_CommConfig not declared in this scope.

and so on.

thanks you so far.

cazc
23rd August 2010, 09:43
Okay i finaly got it all working.

I followd freely's guide. im working on a windows 7 ultimate 32 bit.

thank you.

cazc
24th August 2010, 18:31
Hello.

Im trying to make a simple program to turn a com port on/off with a button.
also a button to turn DTR on/of , and a button for the RTS on/off, but im having a hard time understanding the documentation to qext. (its by the way working like a charm)

hope you guys can help me a little.

freely
29th September 2010, 08:14
Hi
You are right
It is possible to have such errors.
I've tried to build all QextSerialPort classes to external dll or .lib and use them in next projects as nessesary
BUT!
Because of possible erorrs as from feedback here and from my personal exp. using classes DIRECTLY in you project will minimize possible errors to zero and 'll help you to understand how such serial port driver works
So unless thie you have conditional compilation directives in QextSerialPort classes ( such as #ifdef etc.) you should have no problems with crossplatform use
You can delete by hand all POSIX includes ( that are for LINUX) as I made in my project

freely
29th September 2010, 08:17
I've begun new project using QExtSerialPort
I use QExtSerialPort classes directly without build them to .dll or to .lib as one guy adviced me here and it works pretty good at least in WinXP
I've maid some custom changed to QExtSerialPort classes to work only for Windows
I still have small drawbacks in how that classes work. ( It takes to much time to read for example)
Lets discuss.

mssue
15th July 2011, 16:54
I was able to use Handi's instructions without any problems.

Thanks.

nat
1st October 2014, 16:14
hello,
I am using QT4,
I did not find posix* files in this archive
where could I get this Class for Linux?


thank you in advice

Lesiok
2nd October 2014, 07:03
This is full code (https://code.google.com/p/qextserialport/) (Windows, Linuks, Mac) of QExtSerialPort.