Announcement

Collapse
No announcement yet.

Using ini files on sd cards

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

  • Using ini files on sd cards

    I'm trying to create and store a config file on my sd card.
    The config file will have 7 lines like this:
    $1.50
    $1.00
    127.0.0.1
    1
    0
    0
    0
    the file name is config.cfg

    this is the code I'm using to generate the config file:

    func Generate_Config_file()
    var current_price_to_playbuff[3];
    var vip_price_to_playbuff[3];
    var current_host_ip_addressbuff[10];
    var current_screen_flipbuff[1];
    var current_sound_levelbuff[1];
    var play_statebuff[1];
    var device_typebuff[1];
    var line1,line2,line3,line4, line5, line6, line7;

    if(!file_Mount())
    print("Cannot mount uSD card");
    repeat forever
    endif

    print("uSD mounted\n");

    /* If the configuration file does not exist, create default values */
    if(!file_Exists("config.cfg"))
    print("config.cfg does not exist\n");
    print("setting default values\n");
    to(current_price_to_playbuff); putstr("$1.50\n");
    to(vip_price_to_playbuff); putstr("$1.00\n");
    to(current_host_ip_addressbuff); putstr("127.0.0.1\n");
    to(play_statebuff); putstr("1\n");
    to(device_typebuff); putstr("0\n");
    to(current_screen_flipbuff); putstr("0\n");
    to(current_sound_levelbuff); putstr("0\n");

    ConfigFile := file_Open("config.cfg", 'w');

    line1 := file_PutS(current_price_to_playbuff, ConfigFile);
    line2 := file_PutS(vip_price_to_playbuff, ConfigFile);
    line3 := file_PutS(current_host_ip_addressbuff, ConfigFile);
    line4 := file_PutS(play_statebuff, ConfigFile);
    line5 := file_PutS(device_typebuff, ConfigFile);
    line6 := file_PutS(current_screen_flipbuff, ConfigFile);
    line7 := file_PutS(current_sound_levelbuff, ConfigFile);

    file_Close(ConfigFile);
    file_Unmount();
    endif
    endfunc

    when I try to open the config file using notepad I get garbage data.
    I'm using the code from
    http://www.4dsystems.com.au/code/index.php?node=77&id=84

    What am I doing wrong?
    Thank you for your help,
    -Halim













  • #2
    Hi Halim,

    Please try making some of your buffers a little longer, eg:-

    to(current_price_to_playbuff); putstr("$1.50\n");

    is actually 7 character long as the string is terminated with a zero.

    var current_price_to_playbuff[3]; // is only 6 chars.


    The zero is stripped off by file_PutS

    If that doesnt fix it we'll set it up and see whats happening.



    Regards,
    Dave

    Comment


    • #3


      I tried increasing all buffers to 20 (40 characters) but I'm still getting the same result.
      var current_price_to_playbuff[20];
      var vip_price_to_playbuff[20];
      var current_host_ip_addressbuff[20];
      var current_screen_flipbuff[20];
      var current_sound_levelbuff[20];
      var play_statebuff[20];
      var device_typebuff[20];

      Comment


      • #4
        The following code works fine on my uVGA-II. If this doesn't work, check to make sure you have the latest PmmC installed......

        #platform "uVGA-II_GFX2"#inherit "4DGL_16bitColours.fnc"
        func Generate_Config_file() var current_price_to_playbuff[20]; var vip_price_to_playbuff[20]; var current_host_ip_addressbuff[20]; var current_screen_flipbuff[20]; var current_sound_levelbuff[20]; var play_statebuff[20]; var device_typebuff[20]; var line1,line2,line3,line4, line5, line6, line7; var ConfigFile; if(!file_Mount()) print("Cannot mount uSD card"); repeat forever endif
        print("uSD mounted\n");
        /* If the configuration file does not exist, create default values */ if(!file_Exists("config.cfg")) print("config.cfg does not exist\n"); print("setting default values\n"); to(current_price_to_playbuff); putstr("$1.50\n"); to(vip_price_to_playbuff); putstr("$1.00\n"); to(current_host_ip_addressbuff); putstr("127.0.0.1\n"); to(play_statebuff); putstr("1\n"); to(device_typebuff); putstr("0\n"); to(current_screen_flipbuff); putstr("0\n"); to(current_sound_levelbuff); putstr("0\n");
        ConfigFile := file_Open("config.cfg", 'w');
        line1 := file_PutS(current_price_to_playbuff, ConfigFile); print("Line1 = ",line1,"\n"); line2 := file_PutS(vip_price_to_playbuff, ConfigFile); print("Line2 = ",line2,"\n"); line3 := file_PutS(current_host_ip_addressbuff, ConfigFile); print("Line3 = ",line3,"\n"); line4 := file_PutS(play_statebuff, ConfigFile); print("Line4 = ",line4,"\n"); line5 := file_PutS(device_typebuff, ConfigFile); print("Line5 = ",line5,"\n"); line6 := file_PutS(current_screen_flipbuff, ConfigFile); print("Line6 = ",line6,"\n"); line7 := file_PutS(current_sound_levelbuff, ConfigFile); print("Line7 = ",line7,"\n");
        file_Close(ConfigFile); file_Unmount(); endifendfunc
        func main() Generate_Config_file(); repeat foreverendfunc
        _______________
        Best Regards,
        Howard

        Comment


        • #5


          An interesting note:
          The results look different on my system when opening in Notepad vs Wordpad ()
          In Wordpad, each entry is correctly shown on a separate line. In Notepad, the newline character is ignored and the results appear all on one line1.50$1.00127.0.0.11000
          However the newline character must still be there, since if I copy and paste it here it correctly puts each entry on a new line......
          _______________
          Best Regards,
          Howard

          Comment


          • #6


            I still have the same issue as before. I think it's something to do with my unit not able to write properly to the sd card. I sent the same code to a friend with a different display unit, it worked fine.
            Thank you all.
            -Halim

            Comment


            • #7


              Back to basics time.

              Try reading and writing sectors to and from the uSD card and checking what you are seeing.

              How are you powering the display? The uSD card is the most susceptable part to a marginal power supply.
              Mark

              Comment


              • #8


                Hi,
                My display is usb powered.

                -Halim

                Comment


                • #9


                  Is it straight from USB, or via a hub? (if so the hub should be powered)
                  What quality are the USB cables? (lots of cheap cables have very high resistances)
                  Try on another computer (Some reputable brand name computers skimp on the power available to USB, thinking they are making a 'green' computer)
                  Mark

                  Comment


                  • #10


                    Also, try another mfg of uSD card, such as Sandisk or PNY......
                    _______________
                    Best Regards,
                    Howard

                    Comment

                    Working...
                    X