No announcement yet.

Parameter file on SD card

  • Filter
  • Time
  • Show
Clear All
new posts

  • Parameter file on SD card


    Sorry if my question seems obvious but I'm a total newbie with 4DGL, and more generally with embedded programming and low-level languages.

    I need to be able to store parameters for my program within a PARAM file in my microSD card. The parameters, stored in plain text, will likely be separated by CRLF, but without a fixed length.

    Since the file_Read() function will only allow me to retrieve the whole content of the file at once, how can I retrieve the individual parameters? In my opinion, splitting the read string in substrings cut at each CRLF would be the fanciest solution, but I can't find any documentation about a function which can do that.
    Another way would be to read every parameter in the file one by one, but how can I stop the reading when reaching a CRLF?

    Thank you for your help

  • #2

    Welcome to the forum!

    I made a simple project that is related to your concern. This project demonstrates how to create a PARAM file, reads/displays the contents of the file in the terminal, retrieve the parameter and it is a good start in your case.

    I used ViSi Environment.

    You could try the simple project I have attached, if you have time.
    Also, if you have questions regarding with the project, please don't hesitate to ask.

    Hopefully, this will help you.

    Best regards,
    Attached Files


    • #3
      Thank you a lot for your answer, I haven't thought of reading every character one by one. I have two remaining questions:
      - Since my buffer will be an array of characters, I guess I can use the whole array as a string, like [STR]buffer0?
      - The file is never closed by the file_Close() function. Is it on purpose?

      Best regards


      • #4
        Hello again,

        Oh! anytime, willing to help you.

        Since my buffer will be an array of characters, I guess I can use the whole array as a string, like [STR]buffer0?
        Unfortunately, it is not possible because the buffer0 is an array of characters and used to stores values by indexes.

        Unless if an array doesn't use indexes to store values as like shown below:

        var buffer[5];
        putstr("hello ");
        Thus, you can use "chardata" array to convert "buffer0" array as a string as shown below:
        var chardata[20];   // 20 character buffer for  a source string
        var ptr,i;
         for(i:=0; i<=varCount; i++)
         str_PutByte(ptr + i,buffer0[i]);

        The file is never closed by the file_Close() function. Is it on purpose?
        Basically, file_Close(...) function will ensure that the file is closed to avoid data corruption after the writing.

        I have attached the modified version of the demo project.

        Best regards,
        Attached Files
        Last edited by kayven@4d; 7th November 2018, 06:15 PM.


        • #5

          Thanks your answer.

          However I still don't manage to properly get char and transform them to string. Perhaps I'm missing a file_Seek to initialize the pointer at a position 0?

          I've noticed the file_GetS function in the documentation. It apparently gets the whole line as a string until a line feed is reached. Wouldn't it be a better fit? Is CR included in the read string in that scenario?

          Best regards


          • #6

            Welcome back to the forum!

            file_Seek(...) function can be set at different address.

            And Yes, you're right, file_GetS(...) function will include the "CR" character
            with the whole string.

            This function will stop reading the file when it encounters a newline character.

            Intentionally, "CR" character is an indicator especially if you have a file that contains multi double-space text.
            Thus, file_GetS(...) is not recommended to use if a file contains more than newline character.

            Best regards,
            Last edited by kayven@4d; 4th January 2019, 10:42 AM.