Results 1 to 13 of 13

Thread: QextSerialPort and waitForReadyRead problem

  1. #1
    Join Date
    Sep 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QextSerialPort and waitForReadyRead problem

    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:

    Qt Code:
    1. ...
    2. quint32 count = 800000;
    3.  
    4. serial_port->write(&cdata, 1);
    5.  
    6. //qDebug() << "Wait: " << serial_port->waitForReadyRead(5000);
    7.  
    8. while(count--);
    9.  
    10. qDebug() << "bytes available: " << serial_port->bytesAvailable();
    11.  
    12. serial_port->read(&cdata, 1);
    13. ...
    To copy to clipboard, switch view to plain text mode 


    The following is the non-working version using waitForReadyRead()
    Qt Code:
    1. ...
    2.  
    3. serial_port->write(&cdata, 1);
    4.  
    5. if(!serial_port->waitForReadyRead(5000)){
    6.  
    7. qDebug() << "Error";
    8.  
    9. }else{
    10.  
    11. qDebug() << "bytes available: " << serial_port->bytesAvailable();
    12.  
    13. serial_port->read(&cdata, 1);
    14.  
    15. }
    16. ...
    To copy to clipboard, switch view to plain text mode 


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

    Cheers.

  2. #2
    Join Date
    Sep 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    Is there anyone able to help me?

    Thank you.

  3. #3

    Default Re: QextSerialPort and waitForReadyRead problem

    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.

  4. #4
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    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) .

  5. #5
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    Quote Originally Posted by SteveH View Post
    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.

  6. #6
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    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.
    Attached Files Attached Files

  7. The following user says thank you to SteveH for this useful post:

    Rocken (12th March 2012)

  8. #7
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: QextSerialPort and waitForReadyRead problem

    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.
    Attached Files Attached Files

  9. #8
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: QextSerialPort and waitForReadyRead problem

    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.
    Attached Files Attached Files

  10. The following 2 users say thank you to SteveH for this useful post:

    LoomVortex (3rd November 2010)

  11. #9
    Join Date
    Dec 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: QextSerialPort and waitForReadyRead problem

    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.

  12. #10
    Join Date
    Aug 2009
    Location
    Finland
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QextSerialPort and waitForReadyRead problem

    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?

  13. #11
    Join Date
    Jan 2009
    Location
    Midlands UK
    Posts
    62
    Thanks
    6
    Thanked 9 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    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

  14. #12
    Join Date
    Aug 2009
    Location
    Finland
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QextSerialPort and waitForReadyRead problem

    Hi, thank you for the info. I got it work, there was a memory leak in my search code what caused that.

  15. #13

    Default Re: QextSerialPort and waitForReadyRead problem

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.