Read .BMP file using Ch376

Hello Guys,
Please help me!!!
I am trying to open and read the .bmp file using the CH376S USB Read/Write module with Arduino mega 2560.

I am using this example to open and read .bmp file but no luck. “Ch376msc/basicUsageHwSerial.ino at master · djuseeq/Ch376msc · GitHub

In the above example, I have just updated the file extension from .txt to .bmp.

Hi Syadav2. In that example i focused to text manipulate. I added a new function readRaw(), so instead using char array buffer, use a byte array and this function. e.g.

byte adatBuffer[255];        

                //read data from flash drive until we reach EOF
        	flashDrive.readRaw(adatBuffer, sizeof(adatBuffer));
          for(int f = 0; f < sizeof(adatBuffer); f++){ // here i print the raw image data to the serial port

Does this code work?

yes, I have tested the redraw it’s working.

case 51: //3
printInfo(“COMMAND3: Read File: OHM.PNG”); // Read the contents of this file on the USB disk, and display contents in the Serial Monitor
flashDrive.setFileName(“OHM.PNG”); //set the file name
flashDrive.openFile(); //open the file
while (!flashDrive.getEOF()) {
flashDrive.readRaw(adatBuffer, sizeof(adatBuffer));
for (int f = 0; f < sizeof(adatBuffer); f++) { // here i print the raw image data to the serial port
flashDrive.closeFile(); //at the end, close the file

and thanks for the writeRaw() function too.

uint8_t writeRaw(uint8_t* buffer, uint8_t b_size);

Thank you for your feedback. :wink: Meanwhile i found an error, the return value of these functions is a boolean value that gives information if there is no more readable data (End Of File). That was good when i focused just to read-write NULL terminated strings. But with the readRaw function, we really have no information when reach the EOF, whether our buffer is completely loaded with data or just e.g. 10 byte is a valid data the rest are old. I need to change these functions to return byte with the count of totally read out bytes number. But that can make trouble for those users who already use this lib in their code. :frowning: Or intermediate solution is to write a new function which one return the read out bytes number, but the former seems to me better and more logical.