Results 1 to 5 of 5

Thread: Qserialdevice 2.0 waitForBytesWritten halfduplex question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 43 Times in 42 Posts

    Default Re: Qserialdevice 2.0 waitForBytesWritten halfduplex question

    Do not use call waiting with a "while", because of this, you're slow/freeze Qt event loop.

    Use signals and slots.

    To find out about the possibility of reading the first 15 bytes, for example, can after first emitted signal readyRead(), make to run QTimer, with wait timeout limit. Thus, after each emitting readyRead() to check the number of bytes available for reading bytesAVailable(), and if it is >= 15 then reset QTimer and read the data; if <15 then do nothing (wait for the next readyRead()). If worked signal from QTimer, then the limit has expired timeout - then do something.

    Ie this approach the analysis and reading the input data will be executed asynchronously, as if with a delay in phase relative to their real receive.

    So it must be done!

  2. #2
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qserialdevice 2.0 waitForBytesWritten halfduplex question

    Thanks for your help, this works without the timer. Going to add in a timeout if I don't get the message in (baud_rate*numbytes) time to reset msgsize back to zero. I will never use while loops in a slot.

    void MainWidget:rocSerialDataReceive()
    {
    if (this->initTraceWidget() && this->serial && this->serial->isOpen()) {

    if ((msgsize == 0) && (serial->bytesAvailable() >= 1))
    {
    QByteArray msg_size = this->serial->read(1);
    msgsize = msg_size[0];
    }
    if ((msgsize != 0) && (this->serial->bytesAvailable() >= msgsize))
    {
    QByteArray data = this->serial->read(msgsize);
    msgsize = 0;
    this->traceWidget->printTrace(data, true);
    }
    }
    }

Similar Threads

  1. QSerialDevice enumerator deletion question
    By marcvanriet in forum Qt Programming
    Replies: 4
    Last Post: 28th December 2011, 01:48
  2. QSerialDevice on Symbian
    By hubbobubbo in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2011, 19:00
  3. QSerialDevice
    By clinisbut in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 13:30
  4. question about QSerialDevice (baudrate)
    By mastupristi in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2009, 08:54
  5. waitForBytesWritten
    By smalls in forum Qt Programming
    Replies: 8
    Last Post: 1st March 2006, 16:42

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
  •  
Qt is a trademark of The Qt Company.