Announcement

Collapse
No announcement yet.

Read string from a txt file on sd card

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

  • umich
    replied
    Hello,

    I'm trying to do something similar. I can pull values from a text file on my SD card using the following:
    Code:
    charsRead := file_GetS(tempString, 5, templates);
    When I try to use the tempString value, though, I can't seem to figure out how to read it. The value shows up properly with a value of 11 if I use print([STR]tempString), but if I try to pass that value into another variable, it comes out as 0 or 206 or 226 but never 11. Would you have any idea why that could be happening?

    Thank you!

    Leave a comment:


  • ESPsupport
    replied
    The doco for str_Find() talks about receiving a string pointer and advancing it. It can only advance it if you give it the address of the location of the string pointer.
    i.e what you need is
    Code:
    if(str_Find(&q, "Hello") )

    Leave a comment:


  • JacquesJJ
    replied
    Please see Attached file
    Attached Files

    Leave a comment:


  • ESPsupport
    replied
    Use File, zip project and attach it here

    Leave a comment:


  • JacquesJJ
    replied
    The Screen still restarts after I added
    if(str_Find(str_Ptr(buffer1), "Hello")

    Leave a comment:


  • JacquesJJ
    replied
    My buffer1 is just a global var called

    var buffer1[100];

    Leave a comment:


  • ESPsupport
    replied
    I can't see how buffer1 is defined.

    Also I think
    Code:
    if(str_Find(buffer1, "Hello") )
    should be
    Code:
    if(str_Find(str_Ptr(buffer1), "Hello") )

    Leave a comment:


  • JacquesJJ
    replied
    I've already tried that pdf and every time I touch the button it restarts the screen.
    1. Save file
    2. Add content to file
    3. Read File content and print
    4. Trying now to add if statement

    Here is my code

    if (n == iWinbutton3)

    img_Show(hndl, iWinbutton3); // show button, only do this once
    img_SetWord(hndl, iWinbutton3, IMAGE_INDEX, state); // where state is 0 for up and 1 for down

    //////////////////


    // Write to SD card
    file_Mount();
    if(file_Exists("test.txt"))file_Erase("test.txt");
    hndl1 := file_Open("test.txt", 'w');

    file_Write(str_Ptr("Hello"),5, hndl1);

    file_Close(hndl1);


    var readData[20];
    var j ;

    hndl1 := file_Open("test.txt",'r');

    file_Read(readData,28,hndl1 );

    txt_MoveCursor(0,1);

    to(buffer1); putstr(readData); // save string to buffer1
    txt_MoveCursor(3,0);
    q:=str_Ptr(buffer1); // assign q as pointer
    str_Printf(" ", buffer1);




    if(str_Find(buffer1, "Hello") )
    print("Passssssed");
    endif


    endif


    Please tell me what I'm doing wrong

    Leave a comment:


  • ESPsupport
    replied
    This app note should help http://www.4dsystems.com.au/appnote/4D-AN-00056/

    Leave a comment:


  • JacquesJJ
    started a topic Read string from a txt file on sd card

    Read string from a txt file on sd card

    Hello!

    I created a text file called test.txt by using hndl1 := file_Open("test.txt", 'w'); and wrote some text in it by using file_Write(str_Ptr("Hello"),5, hndl1);
    Now what I want to do is create a if statement to search for the word/string "Hello" in the txt file I created, it should then print "Found Hello".

    This is just a simple example to give you more or less an Idea on what I want to do.

    Any advice/code or link will help.

    Thanks.

    JacquesJJ
Working...
X