Announcement

Collapse
No announcement yet.

Incrementing File Name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • emg
    replied
    Thanks Joseph, it worked perfectly!

    Leave a comment:


  • Joseph Herrera
    replied
    Hi emg,

    You can try adding this one:

    to(fname); putstr("I_12_22.txt") ;
    fname_ptr := str_Ptr(fname); // add this one

    I have attached a sample code that uses that filename and prints the little content. .txt file is also attached (remember to put into SD card.

    Code:
    var mystring[20];
    var file_hndl;
    
    var fname[10];
    var fname_ptr;
    var fname2;
    
    func main()
    
        putstr("Mounting...\n");
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    
        hndl := file_LoadImageControl("read.dat", "read.gci", 1);
    
         to(fname); putstr("I_12_22.txt") ;
         fname_ptr := str_Ptr(fname);
    
         //fname2 := "I_12_22.txt";                        // you can also try this one instead
         //file_hndl := file_Open(fname2, 'r');      // this as well
    
         file_hndl := file_Open(fname_ptr, 'r');
         file_GetS(mystring, 10, file_hndl);   // size depends
         putstr(mystring);                                  // prints hello
         file_Close(file_hndl);
    
        repeat
        forever
    endfunc
    Best Regards,
    Attached Files

    Leave a comment:


  • emg
    replied
    Hi folks,
    I am trying to do about the same using designer. I want generate a string, store in a buffer and use the buffer in file_Open.
    It never open the correct file. If I read the file, no error but wrong data.

    ex:
    to(fname); print("I_12_22.txt") ;
    hndl := file_Open(fname,'r') ;

    What am I missing? Thks

    Leave a comment:


  • Joseph Herrera
    commented on 's reply
    Hi Chessmaster,

    Have you tried file_Open(namebuf, 'w'); instead of appending, 'a' ?
    Could you also try putting a delay temporarily in the loop to test if the problem still occurs.
    Also, remember to take note that writing a string should be 'null terminated', it might cause continuous writing if it does not have the terminating character.

  • Chessmaster
    replied
    Hi Joseph,

    Thank you! That did it! It now writes without corrupting the files.

    However, I seem to have come across another problem. On the third file that I wrote to the uSD card it some reason took the data from the previous couple files and added it to the beginning of the third file. The data is approximately collected at 45 Hz and I ran each test for 10 seconds. For some reason in the third file there was 30 seconds worth of data. The only thing that I could think of that is causing this is that I had opened the first two files in Excel and had saved over the old ones on the uSD card. Could this have caused that? The file names of the files I saved were the same as what they were originally outputted by the 4Duino.

    The second file only had 10 seconds worth of data so I am suspicious that maybe for some reason using Excel to re-save the files caused the third file to end up like that.


    Thanks!

    Leave a comment:


  • Joseph Herrera
    replied
    Hi Chessmaster,

    Tried this one:
    Code:
    void loop()
    {
    // put your main code here, to run repeatedly
      word handle1;
      handle1 = Display.file_Open(namebuf,'a');
    //The loop section of the sketch will read the X,Y and Z output rates from the gyroscope and output them in the Serial Terminal.
    //Lines below added for delta calculation:
      String DeltaX = "100";
      String DeltaY = "200";
      String DeltaZ = "300";
    //Lines added below for calculating change in Deg/s: (NOTE: Assuming gyro2 (Address with 68) is on calf, gyro1 on shoe)
      double Deltax, Deltay, Deltaz;
    
    //Lines Below Added for Delta Calculation:
      char DeltaXC[64];
      DeltaX.toCharArray(DeltaXC, 64);
      char DeltaYC[64];
      DeltaY.toCharArray(DeltaYC, 64);
      char DeltaZC[64];
      DeltaZ.toCharArray(DeltaZC, 64);
    
     //Print the output rates to the terminal, seperated by a TAB character.
      Display.file_PutS(DeltaXC,handle1);
      Display.file_PutC('\t',handle1);
      Display.file_PutS(DeltaYC,handle1);
      Display.file_PutC('\t',handle1);
      Display.file_PutS(DeltaZC,handle1);
      Display.file_PutC('\t',handle1);
      // Removed file_write
      Display.file_Close(handle1);
    
      Display.print("Write done \n");
      delay(2000);
      //Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.)
    }
    I tried to manually set the string values and removed the file_Write temporarily and the result in the sd card was:

    ANK35.TXT
    100 200 300 100 200 300

    fIle_Write according to the internal functions manual, Writes the number of bytes specified by "size" from the source buffer into the file referenced
    by "handle".
    Example, res := file_Write(memblock, 20, hndl1);

    Hope this helps,

    Leave a comment:


  • Chessmaster
    replied
    Hi Joseph,
    I tried the zip file that you had added. It never corrupted any of the files in it. Here is the code that I have written. Any help would be greatly appreciated!

    Thanks!
    Attached Files

    Leave a comment:


  • Joseph Herrera
    replied
    Hi Chessmaster,

    Have you tried plugging and unplugging the device using the project in the zip file w/out modifications? Did it cause corruption as well?

    Could you post your code here so we could check further? It may have something to do with the filename or file open/close.

    Regards,

    Leave a comment:


  • Chessmaster
    replied
    Joseph, thank you for the help! That code now works. However, I run into one more problem. The first time I plug in the device, the file is created and the gyroscope data is saved to the uSD card. However, when I unplug it and re plug it in, the second file that it is creating becomes corrupted. What could be causing it to corrupt the file. This has happened every time I have tried it. Any help would be great!

    Leave a comment:


  • Joseph Herrera
    replied
    Hi Chessmaster,

    Attached here is a modfied version of the sample project.

    forgot to include the handle. =)

    Code:
    word hndlclose;
    // .
    // .
     hndlclose = Display.file_Open(namebuf,'w');
    
     Display.file_Close(hndlclose);
    Attached Files

    Leave a comment:


  • tonton81
    replied
    you might need to use str_GetWord(namebuf) as the typedefs are different

    Leave a comment:


  • Chessmaster
    replied
    Thank you for the help that is exactly was I was looking for. There is only one problem that I get with it. The error that occurs is this:

    word file_Close(word Handle);

    ^

    exit status 1
    invalid conversion from 'char*' to 'word {aka unsigned int}' [-fpermissive]

    Completed RC=1



    For some reason it does not like this line of the code:
    Display.file_Close(namebuf);

    Do you know why it is giving me that error?

    Leave a comment:


  • Joseph Herrera
    replied
    Hi Chessmaster,

    I have attached a sample 4duino project that performs the the file-saving requested above. Take note of the '8dot3' Filename format followed by the displays. This means the filename created should only have a maximum of 8 characters. I changed the 'FileName' to 'FName' to have space for the number stored on eeprom.

    Maybe you could try something like this one:
    Code:
    #include "EEPROM.h"
    
    word hndl ;
    int i;
    
    int address = 0;
    int value;
    
    String FileName = "FName";
    char namebuf[15];
    
    // void setup
    
     value = EEPROM.read(address);
     value = value + 1;
    
     Display.print(value);
     Display.print("\n") ;
    
     EEPROM.write(address,value);
     Display.print(value);
     Display.print("\n") ;
    
     FileName = FileName + String(value)+ ".txt";
    
     FileName.toCharArray(namebuf,15);
    
     Display.putstr(namebuf);
    
     Display.file_Open(namebuf,'w');
     Display.file_Close(namebuf);
    Hope this helps,
    Attached Files

    Leave a comment:


  • Chessmaster
    started a topic Incrementing File Name

    Incrementing File Name

    Hi all,

    I am trying to create a program that writes a text file every time the 4Duino -24 is rebooted. However, I want that text file name to be incremented by 1 every time it is rebooted. For example:

    First time turned on - FileName01
    Second time turned on - FileName02

    Here is my code that I have so far. It does not work yet. I get several errors when running it. Any help would be appreciated! I seem to be having problems in the file_open command. Trying to get the .txt in the file name is where I am having problems. Thanks!

    int address = 0;
    int value;

    value = EEPROM.read(address);
    value = value + 1;

    String FileName;
    FileName += String(value .txt); //THIS LINE PRODUCES ERRORS

    EEPROM.write(address,value);

    word handle;
    handle = Display.file_Open(FileName,'w'); //THIS LINE PRODUCES ERRORS
Working...
X