Results 1 to 20 of 22

Thread: Number of bytes receives not the same after each cycle

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jul 2014
    Posts
    26
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Number of bytes receives not the same after each cycle

    Quote Originally Posted by Lesiok View Post
    This is normal symptom for each data stream device (serial port, TCP socket etc.). 9 characters in packet is your private assumption. Data stream device do not know about it. You should read stream of data, analyze it and divide for logical packets.
    By the way your protocol is very weak. How do you know that for example 01 is the number of the next packet and not its content ?
    Thank you for your reply,

    my protocol is :
    _ID________ |______ Data______
    01_______________8 bytes_____ (always)
    02_______________8 bytes_____
    03_______________8 bytes_____
    04_______________8 bytes_____
    05_______________8 bytes_____
    06_______________8 bytes_____
    ..

    Quote Originally Posted by anda_skoa View Post
    Work with a local buffer.

    All data that comes in is appended to the buffer.
    Then you loop over the combined buffer, take chunks of 9 bytes until that is no longer possible.

    Cheers,
    _
    thanks for your reply

    what do you mean about local buffer ?

    Quote Originally Posted by kuzulis View Post
    Qt Code:
    1. Foo::readyRead()
    2. {
    3. static const int expectedPacketSize = 9; // your 9 bytes
    4. if (port->bytesAvailable() < expectedPacketSize)
    5. return; // do nothing
    6. QByteArray data = port->read(expectedPacketSize);
    7.  
    8. // do domething processing of your packet
    9. }
    To copy to clipboard, switch view to plain text mode 

    Of course, I'm skip the parsing and synchronization of incoming packets from an incoming data stream.


    Thanks for your reply

    I will try this monday,
    with this code, i will lose some packets no ?
    Last edited by AUDI_ENG; 5th July 2014 at 11:01.

Similar Threads

  1. Replies: 4
    Last Post: 23rd October 2012, 08:40
  2. Qt EventLoop Duty Cycle (Blocking vs Spinning)
    By bob2oneil in forum Qt Programming
    Replies: 5
    Last Post: 20th July 2011, 22:06
  3. Replies: 2
    Last Post: 9th June 2010, 16:08
  4. MainWindow::resizeEvent - Infinite Cycle
    By metRo_ in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2010, 23:33
  5. How use Model view with a tree wich have Cycle ?
    By weepdoo in forum Qt Programming
    Replies: 2
    Last Post: 9th December 2008, 17:05

Tags for this Thread

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.