Shop OBEX P1 Docs P2 Docs Learn Events
FSRW @ incrementing file names: bytes, longs, pointers and things. — Parallax Forums

FSRW @ incrementing file names: bytes, longs, pointers and things.

HughHugh Posts: 362
edited 2012-01-09 03:41 in Propeller 1
I have a brain like cold porridge at the moment and tinkering with a prop is something like occupational therapy.

What I am trying to do is to name files created on an SD card with incremental file numbers, e.g., 1.csv, 2.csv, 3.csv ... etc.,

I am using the Propeller Eeprom object to store/recover the last used number from Eeprom - that works fine.

The file number gets converted to a string via the 'dec' method of the simple_numbers object.

".CSV0" gets added to this and the file is opened - except it doesn't, it just stops when it attempts to open the file...
[B]OBJ[/B]
LCD     :      [COLOR=#b22222] "Debug_Lcd" [/COLOR]           [COLOR=#800000] ' Driving Parallax 2977 LCD[/COLOR]
sdfat   :      [COLOR=#b22222] "fsrw"[/COLOR]                 [COLOR=#a52a2a] ' v2.6 of FSRW[/COLOR]
num     :       [COLOR=#b22222]"simple_numbers"[/COLOR]
eeprom  :      [COLOR=#b22222] "Propeller Eeprom"[/COLOR]
gps     :       [COLOR=#b22222]"GPS_Float_Lite"[/COLOR]
FS      :       [COLOR=#b22222]"FloatString"[/COLOR]

[B]VAR[/B]:
[B]long [/B]Fi[[COLOR=#008000]20[/COLOR]], fileName
[B]byte [/B]L

[B]PUB [/B]main
callStartWrite

[B]PUB [/B]callStartWrite

Fi := num.dec(fileName)
L  := [B]StrSize[/B](Fi)


[B]byte[/B][Fi[COLOR=#006400]+[/COLOR]L]   :=[COLOR=#b22222] "."[/COLOR]
[B]byte[/B][Fi[COLOR=#006400]+[/COLOR]L[COLOR=#006400]+[/COLOR][COLOR=#008080]1[/COLOR]] := [COLOR=#b22222]"C"[/COLOR]
[B]byte[/B][Fi[COLOR=#006400]+[/COLOR]L[COLOR=#006400]+[/COLOR][COLOR=#008080]2[/COLOR]] := [COLOR=#b22222]"S"[/COLOR]
[B]byte[/B][Fi[COLOR=#006400]+[/COLOR]L[COLOR=#006400]+[/COLOR][COLOR=#008080]3[/COLOR]] := [COLOR=#b22222]"V"[/COLOR]
[B]byte[/B][Fi[COLOR=#006400]+[/COLOR]L[COLOR=#006400]+[/COLOR][COLOR=#008080]4[/COLOR]] := [COLOR=#b22222]"0"[/COLOR]
sdfat.mount_explicit([COLOR=#008080]12[/COLOR], [COLOR=#008080]13[/COLOR], [COLOR=#008080]14[/COLOR], [COLOR=#008080]15[/COLOR])   
sdfat.opendir
sdfat.popen([COLOR=#006400]@[/COLOR]Fi, [COLOR=#ff0000]"a"[/COLOR])


If I send variable 'Fi' to the LCD it shows "1.CSV0" - the zero being something of a surprise to me, as I expected it to be ignored. If I replace the last line with
sdfat.popen([B]string[/B][COLOR=#b22222]("DATA.CSV"[/COLOR]),[COLOR=#b22222] "a"[/COLOR])

it works fine.

Any ideas or suggestions would be gratefully received.

FWIW, this project is to provide some backup information for my boat:
  • one cog sits there monitoring the number of pulses from a fuel flow sensor that generates a pulse every 0.5 ml;
  • another cog monitors the input switches (used for changing modes, entering initial fuel and number of people on board, etc.,);
  • the rest of the code displays information (e.g., fuel flow rate, fuel remaining and GPS data) to the user and logs everything to the SD card.
The aim is not only to log everything, but to build up a picture of how fuel flow rate varies with speed.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-01-09 01:37
    Hugh wrote: »
    If I send variable 'Fi' to the LCD it shows "1.CSV0" - the zero being something of a surprise to me, as I expected it to be ignored.
    I assume that zero is supposed to be the string terminator. In this case simply assign 0 (not "0", the character).

    Edit: Also, num.dec returns a pointer to an array which is private to the simple numbers object, i.e. your byte[Fi ... modifications affect another object's buffer. While that in itself isn't a major crime (provided you know that you're doing this) popen should then use Fi and not @Fi.
  • HughHugh Posts: 362
    edited 2012-01-09 03:41
    Thank you - you were right in both respects and it now works as I intended.

    Cheers!

    Hugh
Sign In or Register to comment.