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
Re: Binary file data read/write using serial communication
Quote:
Originally Posted by
anita.niharika@gmail.com
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.
Quote:
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.
Quote:
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.