Announcement

Collapse
No announcement yet.

How to save variables(integers) in SDcard in .txt file?

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

  • jcas
    replied
    The above code has been helpful. Hopefully someone can help me with some additional functionality:

    Let's say I want to go back and overwrite the Time 2: slot. How would I do this?
    I want to seek to a certain line number based on the passed argument 'n' and then append what is written on the line.
    Initially I was trying to file_Seek, but that wasn't working so instead I tried looping newlines to get to the line number desired.
    This goes to the correct line number, but overwrites everything in its path, but overwrites preceding lines in the process.

    func writeuSD (var n)
    var y ;
    str_GetW(&i, &d) ;
    hndl1 := file_Open("Config.txt", 'a');
    to (string); print(d);
    //res := file_Seek(hndl1, 0x0000, 0x0005*n ) ;
    res := file_Seek(hndl1, 0x0000, 0x0000) ;
    for (y :=0 ; y<=n ; y++)
    res := file_PutC('\n', hndl1) ;
    next
    res := file_PutS(string, hndl1);
    res := file_Close(hndl1);
    n := 0 ;
    endfunc

    Regards,
    Justin

    Leave a comment:


  • Something
    commented on 's reply
    Thank you so much, Paul. This work!!!!

  • pauleilio
    replied
    Hi

    This is the better way.

    var memblock[100];

    hndl1 := file_Open("data.txt", 'r');
    res := file_Read(memblock, 20, hndl1); // read and store in variable.
    print([STR] memblock);
    res := file_Close(hndl1);

    Best regards

    Paul

    Leave a comment:


  • pauleilio
    replied
    Hi

    This work's but I am sure there is a better way

    var memblock[100];

    hndl1 := file_Open("data.txt", 'r');
    res := file_Read(memblock, 20, hndl1); // read and store in variable.
    res := file_Close(hndl1);

    var n;
    for(n := 0; n < 20; n++)
    putch((memblock[n]) & 0xff);
    putch((memblock[n] >> 8) & 0xff);
    next

    or you could use this,

    var n;
    hndl1 := file_Open("data.txt", 'r');
    for(n := 0; n < 20; n++)
    putch(file_GetC(hndl1));
    next
    res := file_Close(hndl1);

    I hope this helps

    Best regards

    Paul

    Leave a comment:


  • Something
    replied

    Thanks Paul. I tried using
    Code:
    var memblock;
    hndl1 := file_Open("data.txt", 'r');
        res := file_Read(memblock, 20, hndl1);  // read and store in variable.
        print(memblock);             // print the stored value
        res := file_Close(hndl1);
    The data.txt file contains the word "Hello".
    But the code prints "0".
    I also tried
    Code:
    file_GetC(hndl1);
    This prints out "72", which is the ASCII code for "H".

    What am I doing wrong?

    My code: memoryRead_deletable.zip

    Leave a comment:


  • pauleilio
    replied
    Hi,

    You would have to use thr file_Read command to get the inividual bytes from the file.


    res := file_Read(memblock,20, hndl1);

    I hope this helps

    Paul

    Leave a comment:


  • Something
    replied
    I tried that. It only displays the content of the SD card. I want the content of the .txt file in the SD card, if thats possible.

    I tried
    Code:
    x := file_Open("qwe.txt", 'r');
    print(x);
    But it prints
    15788
    or some other number.

    Leave a comment:


  • Noel
    replied
    Something,

    There is an application note which can help you in your task.
    ViSi Read and Write to microSD:

    Please study the source file inside the Zipped project.
    http://www.4dsystems.com.au/appnote/4D-AN-00077/

    Best regards,

    Leave a comment:


  • Something
    replied
    Now the only question remains is if it possible to read content of the .txt file from the display?

    Leave a comment:


  • Something
    replied
    I figured it out!!!
    Instead of using
    Code:
    res := file_PutC("\n", hndl1);
    I used
    Code:
    res := file_PutS("\r\n", hndl1);
    Because windows notepad doesn't recognize "\n" as line break character. We have to use something called a Windows carriage returns "\r\n".

    Leave a comment:


  • Something
    commented on 's reply
    It writes:
    Time: 1/Time: 2/Time: 3/Time: 4/

  • pauleilio
    replied
    Hi,

    This also works

    res := file_PutC('/n', hndl1);

    Best regards

    Paul

    Leave a comment:


  • pauleilio
    replied
    Hi,

    Could you try using this instead,

    res := file_PutC(10, hndl1);


    Best regards

    Paul

    Leave a comment:


  • Something
    commented on 's reply
    Great. It works.
    But the
    res := file_PutC("\n", hndl1);
    doesn't seem to work.

    This is what I get:
    "Time: 1Time: 2Time: 3Time: 4Time: 5Time: 6Time: 7"
    It won't create a new line. Instead it ll make a vertical double arrow (I tried pasting it here but it doesn't seem visible, the arrow is right after the number.).

    Similar problem with \t (tab). It writes capital "R" instead. I get:
    "Time: 1RTime: 2RTime: 3R"

    If I put the "\n" in
    "res := file_PutS("Time: \n", hndl1);"
    It ignores the "\n".
    If I put a "\t" there, it works.

    What can I do to fix this?
    Last edited by Something; 27th April 2017, 10:59 PM.

  • pauleilio
    replied
    Hi,

    This function may work for you.

    var string[10];
    var buffer;

    hndl1 := file_Open("qwe.txt", 'a');
    res := file_PutS("Time: ", hndl1);
    buffer := x;
    to (string); print(buffer);
    res := file_PutS(string, 1, hndl1);
    res := file_PutC("\n", hndl1);
    res := file_Close(hndl1);

    I Hope this helps

    Best regards

    Paul

    Leave a comment:

Working...
X