Trouble with Ch376msc flashDrive using the #include <Ch376msc.h>

I am trying to build a data logger that will enter a new line in a TXT or a CSV file on a memory stick.
So I built a function inspired from the examples, "append".

void Append (char Write[])
{ 
 printInfo("COMMAND2: Append data to file: " );               // Append data to the end of the file.
        flashDrive.setFileName("MITCHFIL.TXT");  //set the file name
        if(flashDrive.openFile() == ANSW_USB_INT_SUCCESS){               //open the file
          flashDrive.moveCursor(CURSOREND);     //if the file exist, move the "virtual" cursor at end of the file, with CURSORBEGIN we actually rewrite our old file
          //flashDrive.moveCursor(flashDrive.getFileSize()); // is almost the same as CURSOREND, because we put our cursor at end of the file
        }
     if(flashDrive.getFreeSectors())
     { //check the free space on the drive
            flashDrive.writeFile(Write, strlen(Write)); //string, string length
           Serial.println (Write);
          } else {
            printInfo("Disk full");
          }
         
        
        flashDrive.closeFile();               //at the end, close the file
        printInfo("Done!");
}

Weird things are happening next:
First of all, the file name does not end in TXT but in some weird character...MITCHFIL.TXÄ

Also, instead of appending a new line to the same file, I am creating a new file with the same name. The data inside the file is correct. But this is not what I need.

Here is the example from the library, it works fine.

 case 50: //2
        printInfo("COMMAND2: Append data to file: TEST1.TXT");               // Append data to the end of the file.
        flashDrive.setFileName("TEST1.TXT");  //set the file name
        if(flashDrive.openFile() == ANSW_USB_INT_SUCCESS){               //open the file
          flashDrive.moveCursor(CURSOREND);     //if the file exist, move the "virtual" cursor at end of the file, with CURSORBEGIN we actually rewrite our old file
          //flashDrive.moveCursor(flashDrive.getFileSize()); // is almost the same as CURSOREND, because we put our cursor at end of the file
        }
        for(int a = 0; a < 20; a++){          //write text from string(adat) to flash drive 20 times
          if(flashDrive.getFreeSectors()){ //check the free space on the drive
            flashDrive.writeFile(adat2, strlen(adat2)); //string, string length
           Serial.println (adat2);
          } else {
            printInfo("Disk full");
          }
        }
        flashDrive.closeFile();               //at the end, close the file
        printInfo("Done!"

What am I doing wrong?
Thanks ,
Mitch

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.