Results 1 to 2 of 2

Thread: Binary file data read/write using serial communication

  1. #1
    Join Date
    Jan 2021
    Posts
    20
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Binary file data read/write using serial communication

    Using serial communication between PC & a device, I am sending & Receiving pre-defined serial data frame. As part of this I need to program a binary file into a flash,

    From PC, In request command sending
    - a binary file size in bytes,
    - chunk size [ex:65535 ] - How can calculate chunk size here?

    Based on response from the device,
    - response = success/failure
    - chunk size

    On the successful response, I would send next request file data write command to the device as below from PC,

    I want to do this following command execution until all data is written or error
    ===============================
    request command
    - chunk id
    - chunk size
    - actual binary file data

    response
    - result = success/failure
    - chunk id (that has (not) been written)
    ===============================


    How can I implement this loop mechanism in the serial sender part? How to handle file operation I mean read()/write API's or also saw QDataStream to perform file operation?
    Should I read complete binary file first and store it in big buffer or directly from the file?
    I am running my GUI on Windows.

    Best Regards,
    Anita

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Binary file data read/write using serial communication

    Quote Originally Posted by anita.niharika@gmail.com View Post
    How can I implement this loop mechanism in the serial sender part?
    Probably a simple state machine with transitions triggered by readyRead(), bytesWritten(), and errorOccurred() from your QSerialPort, and the end of file indication.
    How to handle file operation I mean read()/write API's or also saw QDataStream to perform file operation?
    A basic QFile object and the QIODevice interface should suffice.
    Should I read complete binary file first and store it in big buffer or directly from the file?
    That depends on the size of the files concerned.

Similar Threads

  1. Replies: 8
    Last Post: 8th May 2012, 09:39
  2. Read/write data from file
    By Insomnium in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2010, 07:35
  3. Replies: 2
    Last Post: 2nd November 2010, 05:15
  4. Replies: 4
    Last Post: 10th July 2010, 17:34
  5. Replies: 1
    Last Post: 16th June 2009, 09:09

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.