Results 1 to 2 of 2

Thread: Binary file data read/write using serial communication

  1. #1
    Join Date
    Jan 2021
    Qt products

    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

    - 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,

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

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

    Don't double-post. You asked the identical question last week in the Newbie section.

    Not only that, but you have been given answers and advice on how to handle these serial communications several times already in your previous posts. Go back and re-read those posts and you will see that in every case, you need to design a system that queues up a set of commands, executes one of them, waits for a successful reply, then executes the next until the queue is empty.

    It does not matter if you read the complete file into a buffer or read and send the file in chunks. The point is that however you decide to do it, you need to implement the handshaking protocol between your PC and your device that allows you to send the information in the sizes the device wants, wait for it to tell you it is ready for the next chunk, send it, and repeat until there are no more chunks. You can't do this in a single function with a loop; you have to implement an event-driven system where you send, wait for a reply, and send again, based on the signals issued by the serial port.

    Qt's file I/O mechanisms have all of the signals and slots needed to accomplish this. Qt has many example projects for serial port communication. This one looks like it is applicable to your problem.
    <=== 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.

Similar Threads

  1. Binary file data read/write using serial communication
    By in forum Newbie
    Replies: 1
    Last Post: 22nd February 2021, 06:52
  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


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.