Results 1 to 18 of 18

Thread: Raw data I/O

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Raw data I/O

    Hi
    I have developed a connector with Qt that send instruction to equipement on my site.
    This equipement located by it IP give an answer in three times
    the instruction is 2 byte 0801
    the response will be
    - 4 bytes 08010d01.
    - 32 bytes 00000..... (just zeros).
    - 237 bytes 00000..0100000000000001010101010101000000000000000 000000. ( the first byte with 01 is the 16th one and the series of next 01
    bytes are in position 101th.
    but data that i recieved is:
    - 4 bytes 08010d01.
    - 32 bytes 0e1f134ffe..
    - 237 bytes 000ffffffff0001deae8546796.......... (not expected data)

    this is an extract of my code:
    Qt Code:
    1. connect(socketts,SIGNAL(readyRead()),this,SLOT(recievedata()));
    2. void M10::recievedata()
    3.  
    4. {
    5. QDataStream in(socketts);
    6. taillemessage=socketts->bytesAvailable();
    7. ui->taillebuffer->append (tr("La taille de la socket est : ")+QString::number(taillemessage));
    8. int row = ui->Notification->rowCount();
    9. QByteArray bab,buffer;
    10. bab.resize(taillemessage);
    11. buffer.resize(500);
    12. int sizebab = in.readRawData(bab.data(),bab.size());
    13.  
    14. {
    15. buffer=bab.data();
    16. buffer.resize(taillemessage);
    17. if(buffer.size()>2)
    18. {
    19. ui->textBrowser_2->append(buffer.toHex());
    20. QStringList fields1;
    21. ui->Notification->setRowCount(row+1);
    22. fields1 <<buffer.toHex()<<QString::number(buffer.size());
    23. for(int i=0;i<fields1.count();++i)
    24. ui->Notification->setItem(row,i,new QTableWidgetItem(fields1[i]));
    25.  
    26. taillemessage=0;
    27. }
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    can you explain me why the data is not serialized correctly?
    Last edited by anda_skoa; 5th March 2016 at 10:56. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,324
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raw data I/O

    Your device has a different "endianess" from your PC for binary data? You also resize "bab" once and "buffer" twice, including after assigning bab.data() to it. Why?

  3. #3
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raw data I/O

    Thanks for reply
    ths taillemessage is defined by socket.bytesavailable, i try to use buffers to stock data incoming.
    can you give an element of response it seem working when i have one packet recieved but for other packets the data displayed is different to data that i have on wireshark.

  4. #4
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raw data I/O

    It seem s work with first packet but when other packets becomes i compare. Packets displayed and data packets on wireshark and they are completly different

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Raw data I/O

    How do you store the data until you have reached the necessary amount for interpretation?

    Or rather how do you plan on doing this, currently you seem to accumulate everything as text, which is likely not what you will end up using.

    Cheers,
    _

  6. #6
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raw data I/O

    I just recieve data becoming from the equipement who send me response..
    but response displayed doesnt match the data on the network.
    The data stored in bytearray is simply displayed on textbrowser just to make sure that i have recieved the data that i expected to ricieve.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Raw data I/O

    You wrote that "the first packet" works, but since TCP does not work with packets I assume you are referring to reponses.
    What your code currently doesn't show how you separate responses, i.e. where you determine that one response has endded and the next one has started.

    Cheers,
    _

  8. #8
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raw data I/O

    i dont have specific endword in my response from the controller that i m asking
    but if i send instruction 0x0801 automatically the controller will send the respnse in three times
    4 bytes 0X08010d01
    32 bytes 0000..... (Only zeros)
    237 bytes 000000010000000010101010101....01010000000000000.. .....
    i know exactly 01 positions but i dont know how can i get those two other packets because i only recieve the first packet authentic.
    The others are something like random packets .
    How can i get this issu resolved??


    Added after 8 minutes:


    More explanations
    If i recieve the first 4bytes packet i display it on my textbroxser widget . its ok
    The second other packets i display theire sizes and what are containing
    the size is fine but what contains is alrady something like efffff0000001111ddffffff00000
    and sometime when i refresh i get the right packets
    However the packets transmitted dont contains delimiter of end sending or something like that.
    Last edited by IODR100; 6th March 2016 at 15:30.

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Raw data I/O

    Well, if you know that the response has a defined size, then it doesn't need any delimiter.
    You can then check the number of received bytes to determine when the next response starts.

    My suggestion would be to assmble each response completely before attempting to display it.

    Cheers,
    _

Similar Threads

  1. Replies: 8
    Last Post: 16th July 2015, 19:44
  2. Replies: 1
    Last Post: 27th February 2015, 06:00
  3. Replies: 0
    Last Post: 25th February 2014, 16:17
  4. Replies: 0
    Last Post: 10th September 2011, 13:38

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.