PDA

View Full Version : serial port issues



jhowland
8th January 2009, 17:04
I have a need to read and write from a QT program to a serial port. I would like to maintain platform independence, although my primary platform at this point is Windows

Clearly, QextSerialPort is something I need to look at, and I am doing so, as you will see from questions below. But first...is this the only option available for serial ports and QT? And if so, what version should I be trying to use? It looks like some of the features in qextserialport-1.2win-alpha are not available in non-Windows environments. And needless to say, using "alpha" code is a little worrisome.

And what is the clear answer to whether the "ReadyRead" signal works in what versions and environments? I've been through the threads, and seen lots of conflicting information

Anyway, I am trying to compile the example qespta in the version 1.1 distribution. I am using VS 2005, and QT 4.4.2.

I typed qmake, and then nmake -F Makefile--MessageWindow.cpp gives me the following errors:


./MessageWindow.cpp(93) : error C2061: syntax error : identifier '{ctor}'
./MessageWindow.cpp(121) : error C2061: syntax error : identifier '{ctor}'

here is line 93


msgTextEdit.append(dynamic_cast<MessageEvent::MessageEvent* >(event)->msg);

here is line 121


QCoreApplication::postEvent(this, new MessageEvent::MessageEvent(qmsg));

the constructor for MessageEvent looks like this:


MessageEvent::MessageEvent(QString & msg):
QEvent(static_cast<QEvent::Type>(MessageWindow::MessageEvent))
{
this->msg = msg;
}

clearly this code works in some environments, but doesn't in mine. Has anybody seen it? I want to concentrate on my task, and not on the example code, but also want to be sure things are working

thanks very much in advance

Jonathan Howland

jpn
8th January 2009, 17:28
Try removing those extra "MessageEvent::" prefixes.

pherthyl
8th January 2009, 17:50
I have a need to read and write from a QT program to a serial port. I would like to maintain platform independence, although my primary platform at this point is Windows

Clearly, QextSerialPort is something I need to look at, and I am doing so, as you will see from questions below. But first...is this the only option available for serial ports and QT? And if so, what version should I be trying to use? It looks like some of the features in qextserialport-1.2win-alpha are not available in non-Windows environments. And needless to say, using "alpha" code is a little worrisome

Qextserialport is the best available, but it's pretty broken. On Windows, 1.1 needs a patch before it will even communicate properly (really slow receiving). Readyread has never worked for me, I just used a thread that does something like:


forever{
while(port->bytesAvailable() <= 0) msleep(10)
buffer = port->read(port->bytesAvailable())
// do stuff
}


I've alternated between using readLine and readAll but they are both kinda flaky sometimes. just plain read is still your best bet.

On linux the situation is worse. bytesAvailable() can't be trusted at all. Sometimes it returns 1 or 2 bytes available, sometimes it returns -1, and sometimes it returns the correct value. readAll() just hangs forever.
The only thing I could do on Linux was just try reading constantly. Something like


forever {
msleep(1)
buffer.append(devicePorts[DEVICE_WISP]->read(qMax(1, devicePorts[DEVICE_WISP]->bytesAvailable())));
}


Sure would be nice if the development of that lib picked up. Right now it's just marginally better than writing your own serial code for each platform.

jhowland
8th January 2009, 18:09
thanks for the speedy replies. No luckyet though.

I tried following jpn's suggestion of removing the

extra "MessageEvent::" prefixes

and the error message changed--now instead of the identifier being '{ctor}', it's 'MessageEvent'

In lots of cases, I have been able to avoid reading serial ports in QT by using a network device server to send my app UDP packets instead of serial data. But I can't always do that

Jonathan Howland

jpn
8th January 2009, 18:31
I tried following jpn's suggestion of removing the

extra "MessageEvent::" prefixes

and the error message changed--now instead of the identifier being '{ctor}', it's 'MessageEvent'
Do you have the appropriate include directive in place?

jhowland
8th January 2009, 19:16
Do you have the appropriate include directive in place?

I dont think so--what would that be?

jch

jpn
8th January 2009, 19:36
I meant including the header that declares MessageEvent. For example:

#include "messageevent.h"

Teuniz
12th January 2009, 13:38
I wrote my own serial port code for Linux and WIN32 some time ago.
I released it under the GPL v2 license.

http://www.teuniz.net/RS-232

It has been tested with GCC on Linux and MinGW on Windows XP/2000.
Handshaking or flowcontrol is not supported.
It uses polling to receive characters from the serial port.
Interrupt/event-based is not supported.
Baudrate is fixed at 115K2 but can be easily modified to other baudrates.
Without modifications, this code uses 115K2 8N1 (8 databits, no parity, 1 stopbit).

I use it in some data-aquisition programs using Qt on Linux and Windows.

Regards.