PDA

View Full Version : QextSerialPort and waitForReadyRead problem



Ivan Wagner
20th September 2007, 16:41
Hi to everyone.

I'm currently using the QextSerialPort v1.1 and I've got a problem when trying to use the waitForReadyRead (like in QTcpSocket and other IODevices...). My application currently uses three threads (GUI, socket and serial port) and in fact I want to use the waitForReadyRead method because my thread uses a loop approach (not being a GUI thread...)

I'm giving the method a 5s timeout (value 5000 as argument) and what actually happens when I call the method is that it won't wait until the timeout (if not data has been received yet) but it returns immediately returning me a -1 value which means that an error occurred...

If I use a counter decremented until 0 and call bytesAvailable() I'm able to read everything correctly but the counter, which is a polling approach, wastes me time...

Did someone of you had problems with this waitForReadyRead method in QextSerialPort?


By the way my code looks like the following:



...
quint32 count = 800000;

serial_port->write(&cdata, 1);

//qDebug() << "Wait: " << serial_port->waitForReadyRead(5000);

while(count--);

qDebug() << "bytes available: " << serial_port->bytesAvailable();

serial_port->read(&cdata, 1);
...



The following is the non-working version using waitForReadyRead()


...

serial_port->write(&cdata, 1);

if(!serial_port->waitForReadyRead(5000)){

qDebug() << "Error";

}else{

qDebug() << "bytes available: " << serial_port->bytesAvailable();

serial_port->read(&cdata, 1);

}
...



It would be great if someone could be able to help me.

Cheers.

Ivan Wagner
21st September 2007, 09:53
Is there anyone able to help me?

Thank you.

Stephan Puri-Jobi
7th April 2009, 15:21
waitForReadyRead is not implemented in the QextSerialPort. When calling the method waitForReadyRead, in fact the method of the QIODevice is called. This method just returns false. Since waitForReadyRead in QIODevice is virtual you can overwrite it with your own implementation in the QextSerialPort.

SteveH
8th April 2009, 21:50
Hi,

If you are using qextserialport just for windows I've a version that I re-wrote myself that gives the functions you need plus a few others. It's still a work in progress but everything so far works (without the bugs of qextserialport). If it would be any use post a note back on this thread and I will zip the current state of play as a reply (note - not many comments added yet that explain all the workings) .

guchangyuan
4th September 2009, 13:57
Hi,

If you are using qextserialport just for windows I've a version that I re-wrote myself that gives the functions you need plus a few others. It's still a work in progress but everything so far works (without the bugs of qextserialport). If it would be any use post a note back on this thread and I will zip the current state of play as a reply (note - not many comments added yet that explain all the workings) .

thank you, can you post it. or send a copy to me at guchangyuan@yahoo.com, thank you again.

SteveH
4th September 2009, 22:20
Hi,

Please find attached a zip file with the necessary files. Note that WinComPort.h and WinComPort.cpp are the only files that you would need to include. The other files are a test program using Creator to exercise the comport in the form of a terminal. The coding style still needs to be cleaned up to Qt standards which I will do as the nights draw in and I get more free time.

Note - be careful when debugging (with gdb) - if you don't shut the port down properly it will lock your computer and require a hard reset (and swearing !)

I have just started a remote telemetry project that will use my WinComPort program to service a radio data stream over the ISM band (I have also designed the remote hardware using a PIC micro).

If you have any feedback or problems please post it back here so that it is opwen to all.

SteveH
10th September 2009, 22:59
oops !

Noticed a problem with my WinComPort program - any port setup changes made while the port is closed didn't get used when the port first opened. Latest copy attached here fixes that.

SteveH
26th September 2009, 21:25
Hi to those few looking at my WinComPort program,

I've found and fixed another bug - when accessing comports higher than COM9 you need to use the following prefix "\\.\" ie COM10 should be addressed as "\\.\COM10". To further complicate issues in order to get the backslashes right in C code the prefix needs to be entered as "\\\\.\\". This prefix actually works for all comports from 1 to 255.
I've uploaded the latest version here.

oriadne
22nd December 2009, 13:48
Hi, if COM do not exit the program fault, to prevent this change default to:

checkValidPorts() ;
//check valid default
int i=0;
while(!setPortNumber(i)&& i<255) i++; // make some default settings


My english is very bad, sorry.

LoomVortex
19th February 2010, 07:49
Hi, thank you for the wincomport.cpp. It´s working good, but i have little problem and i´m not sure if it is related to wincomport or to my (crappy) code.

I´m reading lots of data from serial port and data is scanned and passed to different QLineEdit boxes. It works great about a minute but then comes very slow and finally crashes. It seems that some buffer gets full but what buffer? I´m counting bytes from "RxBuffer" and when it´s larger than 32 it clears it. So it can´t be it... but what then? Any suggestions?

SteveH
19th February 2010, 17:18
Hi,

The only buffers my code uses is the ones internal to the windows api. I've not had a problem recieving too much data but I have had a crash once when sending a large block and flooding the write buffer. I've used my wincomport class in a number of projects now without any problems (engine dyno, kart telemetry, kart remote control) which have a continuous rx data stream at 9600 or 19200 baud, although I have updated it to split out the setup dialog into a seperate class. If you post your code I'll have a look and I'll also zip up my latest version and put it online.

Regards
SteveH

LoomVortex
23rd February 2010, 06:26
Hi, thank you for the info. I got it work, there was a memory leak in my search code what caused that.

omegas
20th August 2010, 07:52
hi there,

I used qextserialport in linux and also got memory leak problem with serial port(I guess). could you explained more in details about your memory leak problem. Thanks

omegas