Go Down

Topic: Read .BMP file using Ch376 (Read 968 times) previous topic - next topic

syadav2

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. "https://github.com/djuseeq/Ch376msc/blob/master/examples/basicUsageHwSerial/basicUsageHwSerial.ino"

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




djusee

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

flashDrive.setFileName("OHM.PNG");
        flashDrive.openFile();
                //read data from flash drive until we reach EOF
        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
           Serial.write(adatBuffer[f]);
          }
        }
        flashDrive.closeFile();

imranaalam


imranaalam

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
            Serial.write(adatBuffer[f]);
          }
        }
        flashDrive.closeFile();               //at the end, close the file
        printInfo("Done!");
        break;


and thanks for the writeRaw() function too.


uint8_t writeRaw(uint8_t* buffer, uint8_t b_size);

djusee

#4
Mar 19, 2020, 12:34 pm Last Edit: Mar 19, 2020, 12:39 pm by djusee
Thank you for your feedback. ;)  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.  :(  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.

Go Up