Shop OBEX P1 Docs P2 Docs Learn Events
uSD P2 FlexBASIC — Parallax Forums

uSD P2 FlexBASIC

RsadeikaRsadeika Posts: 3,824
edited 2021-12-13 17:05 in BASIC (for Propeller)

I am trying to open a file, in a COG, and have something written there. But, in my program, nothing is happening. Not sure what I am missing.

Ray

' test2sd.bas

OPTION EXPLICIT                              ' 
CONST HEAPSIZE = 8192                        ' lots of elbow room

mount ("/sd", _vfs_open_sdcardx(5,4,3,2))  ' mount the file system at /SD node

dim s$ as string

dim stack_dlog1(64)

dim cpuID_4 as long

cpuID_4 = cpu(dataLog(),@stack_dlog1(1))

do 
    pausems 2000

loop


end

'COGed datalog
sub datalog

    open "/sd/dlog1.txt" for input as #8
    print #8, "Datalog" 
    print "Debug, in datalog"
do
    print #8, "a";chr$(13)  
    pausesec 1  ' Pause for five minutes.
loop

end sub
'''''''''''''''

Comments

  • Only one COG at a time can use any set of pins, including the SD card pins. My recommendation would be to use the main COG for any file I/O, but if you really need to do file I/O in another COG (why??) then you'd have to do the mount in that COG as well.

  • What I was thinking about is testing the idea of, one COG would be collecting the data, and storing in a file, while another COG would be able to open the file, and do some sort of analysis of the data collected, if at all possible.

    Ray

  • I am experimenting with the program below, and in a COG, the values that are being written are not what I am expecting.

    Does this mean that when you mount in different COG, the uSD function works differently?

    Ray

    ' test2sd.bas
    
    OPTION EXPLICIT                              '
    CONST HEAPSIZE = 8192                        ' lots of elbow room
    
    'mount ("/sd", _vfs_open_sdcardx(5,4,3,2))  ' mount the file system at /SD node
    
    dim s$ as string
    
    dim stack_dlog1(64)
    
    dim cpuID_4 as long
    
    
    
    '   open "/sd/dlog1.txt" for output as #8   
    '   print #8, "Datalog" 
    '   close #8
    cpuID_4 = cpu(dataLog(),@stack_dlog1(1))    
        'print "Debug, in datalog"
        dim a as integer
    do 
        pausems 2000
    '   open "/sd/dlog1.txt" for append as #8
    '   print #8, a;
    '   print #8 chr$(13)
    '   a = a + 1
    '   close #8
    '   pausesec 1  ' Pause
    
    loop
    
    
    end
    
    'COGed datalog
    sub datalog
    mount ("/sd", _vfs_open_sdcardx(5,4,3,2)) 
        open "/sd/dlog1.txt" for output as #8   
        print #8, "Datalog" 
        close #8
        dim a as integer
    do 
        'pausems 2000
        open "/sd/dlog1.txt" for append as #8
        print #8, a;
        print #8 chr$(13)
        a = a + 1
        close #8
        pausesec 1  ' Pause
    
    loop
    
    end sub
    '''''''''''''''
    
    ( Entering terminal mode.  Press Ctrl-] or Ctrl-Z to exit. )
    mounted SD card as /sd
    mounted host file system as /host
    cmd> type /sd/dlog1.txt
    Datalog
    -167363576
    -167363575
    cmd> 
    
    
  • pik33pik33 Posts: 2,350
    edited 2022-02-21 19:56

    Don't mix this kind of operations between cogs. It can be a source of hard to find bugs.

    Another question: can a channel number be 8? The FlexBasic help says this has to be 0 to 7, where 0 and 1 is reserved. Maybe this #8 is the source of the bug.

    Edit: I found in the source code that max file# is 9, not 7

  • pik33pik33 Posts: 2,350

    if you really need to do file I/O in another COG (why??)

    Now I know why. My main cog is doing SD "file manager" while another one wants to play .wav This is of course not possible with this architecture - now I need to write a "file access" cog driver with its own mailbox type API

    Is there something like "unmount"?

Sign In or Register to comment.