Announcement

Collapse
No announcement yet.

Unknown value when reading from text file on SD card

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

  • Unknown value when reading from text file on SD card

    Hello,

    I first posted under a different category, but this one makes more sense. I'm trying to read in values from a text file on an SD card. I can successfully read values from the file using the following:
    Code:
    charsRead := file_GetS(tempString, 5, templates);
    When I try to use the value in the tempString variable, I can't figure out how to read it properly. The tempString variable displays a correct value of 11 if I use print([STR]tempString), but if I try to pass the tempString value into another variable, it comes out as 0 or 206 or 226 but never 11.

    Would anyone have any idea why that could be happening?

    Thank you!

  • #2
    Hello,

    Are you reading just the 1 byte from the SD card or more as the size 5 suggests. Would mychar := file_GetC(templates) ; work better for so you could just handle the 1 byte you are reading.

    Best regards

    Paul

    Comment


    • #3
      Hi Paul,

      Thanks for your response. I made a text file for testing that looks like the following:
      Code:
      11
      22
      33
      44
      55
      66
      77
      88
      99
      I am trying to read in the whole line at a time. Eventually I will want to read values from 0 to 99 and even text strings, so I didn't think the file_GetC function would work. What do you think?

      Thanks again.

      Comment


      • #4
        Good day umich,

        Here is what I can suggest:

        For your first post, I suggest when you are going to transfer the tempString to another variable (where you intend it to be a integer) you need to use the str_GetW function to properly store the string into a variable and read it as an integer.

        For your second post, you can still use the file_GetS() function. The function reads a string and stops when it detects a Newline or EOF, the function also automatically moves the pointer. You will just need to use different variables to store your data.

        Example:
        file_GetS(data1, 5, templates);
        file_GetS(data2, 5, templates);

        Comment

        Working...
        X