Results 1 to 4 of 4

Thread: QByteArray datas arrive splitted

  1. #1
    Join Date
    May 2017
    Posts
    6
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Post QByteArray datas arrive splitted

    Hi everyone,
    i have a probleme while recieving datas in a QByteArray when i use readAll from QSerialPort, i recieve datas like that when i use qDebug << datas.size() << datas;
    (datas is a QByteArray)
    512 "1101011111110100000101000001010000010100000101000 00101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001010000010 10000010100000101000001010000010100000101000001010 00001010000010100000101000001010000010100000101000 00101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001010000010 10000010100000101000001010000010100000101000001010 00001010000010100000101000001010000010100000101000 00101000001010000010100000101000001010000010100000 1010000010100"

    6 "0001\r\n"

    after recieving the frame i extract the different information, but it doesn't come entirely so the data extraction is not correct, it works only if the frame is less than 512 bits

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QByteArray datas arrive splitted

    So is your frame always terminated with CRLF? If so, then you simply keep appending each new QByteArray onto a second, "frame" byte array until you receive a QByteArray of data from readAll that is correctly terminated. At that point, you have a complete frame in the "frame" byte array and can process it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2017
    Posts
    6
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QByteArray datas arrive splitted

    I tried to add a CRLF and i use the indexOf function in a while loop, so it reads data until the function returns anything else than -1 (because the length of the frame is defined in the frame itself, and i cannot know it by another way) . the problem is that the function always return -1 .

    Edit :
    I found how to use inexOf for the CRLF but it finds it in the "second part" of the frame... it changes anything, maybe I am doing it wrong.
    Last edited by oazive; 3rd May 2017 at 10:05.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray datas arrive splitted

    This is normal symptom. Serial port is just a pipe that knows nothing about the data structure. You have to concatene data after every readAll() with previous and then split them into protocol-compliant records.
    The problem was explained many times on the forum.

  5. The following user says thank you to Lesiok for this useful post:

    oazive (3rd May 2017)

Similar Threads

  1. Paint QTextDocument splitted by pages 1/5 and edit txt
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2017, 13:14
  2. Replies: 3
    Last Post: 21st September 2010, 22:14
  3. Replies: 1
    Last Post: 11th June 2010, 10:47
  4. Replies: 5
    Last Post: 18th December 2008, 14:58
  5. Printing RGB datas into widget
    By agsrinivasan in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2007, 10:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.