Announcement

Collapse
No announcement yet.

file_PutW ?

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

  • file_PutW ?

    Hello everyone!

    I'm happy user of uLCD- 35DT, and currently I'm working on data storage on the uSD card.
    My goal is to save data (var) every second, while the uLCD is on.
    Here's my code:
    Code:
    #platform "uLCD-35DT"
    
    #inherit "4DGL_16bitColours.fnc"
    
    func main()
    
        putstr("Mounting...\n");
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
        gfx_Cls();
    
        gfx_ScreenMode(LANDSCAPE) ; 
    
        if(file_Exists("test1.txt"))file_Erase("test1.txt");
    
        sys_SetTimer(TIMER0,1000);
    
        repeat                      
        sys_SetTimerEvent(TIMER0,okres);
        forever                     
    
    endfunc
    
    func okres()
    
        var hndl1;
    
        hndl1 := file_Open("test1.txt", 'a');
    
        file_PutW(120,hndl1);
        file_PutC('\n',hndl1);
    
        file_Close(hndl1);
    
        print("Data Written\n");
    
        sys_SetTimer(TIMER0,1000);
    
    endfunc
    I have a problem with file_PutW, here's what I got in the test.txt:

    Code:
    x 
    x 
    x 
    x 
    x
    I appreciate any help



  • #2
    Hi m.jazwinski,

    I tried your example in some uLCD- 35DT lying around here without modyfying anything..
    and when I opened the sd card in a text editor in windows, I saw: " 7800 0a " which was the first okres().

    '78' stood for 120 while '0a' was for \n. I guess this was the correct expected output.

    Have you tried other sd cards? make sure it is FAT16 formatted and SPI compatible.

    Can you also try some FAT16 examples? They can be found in 'File' - 'Samples' - 'Picaso Designer' - 'PICASO - FAT16'. You may have to change the target device to your display.

    Best Regards,

    Comment


    • #3
      Hello,

      thanks for the answer. I haven't tried other sd card, but I solved my problem using other functions. Here's my code, maybe someone find it useful
      Code:
      #platform "uLCD-35DT"
      
      #inherit "4DGL_16bitColours.fnc"
      
      var buf;
      var hndl1;
      var i;
      
      func main()
      
          putstr("Mounting...\n");
          if (!(file_Mount()))
              while(!(file_Mount()))
                  putstr("Drive not mounted...");
                  pause(200);
                  gfx_Cls();
                  pause(200);
              wend
          endif
          gfx_Cls();
      
          gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
      
          if(file_Exists("test4.txt"))file_Erase("test4.txt");
      
          buf:=mem_Alloc(6);
          to(buf); print("START\n");
      
          hndl1 := file_Open("test4.txt", 'w');
          file_Write(str_Ptr(buforek),6,hndl1);
          file_Close(hndl1);
      
          mem_Free(buf);
      
          print("Data Written\n");
      
          sys_SetTimer(TIMER0,1000);
      
          sys_SetTimerEvent(TIMER0,okres);
      
          repeat
          forever
      
      endfunc
      
      func okres()
      
          buf:=mem_Alloc(4);
          to(buf); print([DEC3Z]i,"\n");
      
          hndl1 := file_Open("test4.txt", 'a');
          file_Write(str_Ptr(buf),4,hndl1);
          file_Close(hndl1);
      
          mem_Free(buf);
      
          print(i++,"\n");
      
          if(i<11)
              sys_SetTimer(TIMER0,1000);
          else
              print("End\n");
          endif
      
      endfunc

      Comment

      Working...
      X