Results 1 to 4 of 4

Thread: qextserialport is taking its sweet time for sending data

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default qextserialport is taking its sweet time for sending data

    Hi!

    I'm using qextserialport as a solution for serial communication on Windows with an FTDI chip over a USB port. I'm exchanging approx. 60 bytes packets with a device every 12 ms.

    Well I measured the performance and it turns out that while sending out the 60 bytes is below 1 ms, reading them takes over 30 ms. Here is my port config:

    Qt Code:
    1. port = new QextSerialPort("COM4");
    2. port->setBaudRate(BAUD115200);
    3. port->setFlowControl(FLOW_OFF);
    4. port->setParity(PAR_NONE);
    5. port->setDataBits(DATA_8);
    6. port->setStopBits(STOP_1);
    7. port->setTimeout(0,1);
    To copy to clipboard, switch view to plain text mode 

    I'm explicitely setting the timeout to 0,1 otherwise the reading takes over 500ms!!! If I set the timeout to 0,0 the read() never returns. Does anyone have an explanation why reading is so slow? Is there something I can do to make it faster?

    I already set the latency of the COM port in the device manager to the minimum of 1 ms.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qextserialport is taking its sweet time for sending data

    How exactly do you perform the read?

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qextserialport is taking its sweet time for sending data

    The read looks like this:

    Qt Code:
    1. port->open(QIODevice::ReadWrite);
    2.  
    3. char receiveBuffer[1024];
    4. int bytesRead = port->read(receiveBuffer, qMin(port->bytesAvailable(), 1024));
    To copy to clipboard, switch view to plain text mode 

    I don't think there is anything more you can do there.

    I got a hint from the mailing list that opening the port in unbuffered mode might do the trick:

    Qt Code:
    1. port->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
    To copy to clipboard, switch view to plain text mode 

    And it's true. It reads lighning fast now. However, you don't get a nice packet stream anymore, where one read returns one or more complete packets, but some kind of byte mess of random sizes that you have to glue together to whole packets. This is not a problem though, it's just a couple of lines of code and it works reliably and faster than ever.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qextserialport is taking its sweet time for sending data

    You shouldn't do the reading that way. If there is nothing to read, your application will freeze and wait until the operating system decides it's time to let your application know there is actually something waiting in the file descriptor. You should only call read() when you have checked bytesAvailable() reports any data waiting to be read.

Similar Threads

  1. Replies: 7
    Last Post: 29th August 2008, 10:24

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.