Shop OBEX P1 Docs P2 Docs Learn Events
question re Use of input string as a filename for SD Card — Parallax Forums

question re Use of input string as a filename for SD Card

Paul_HPaul_H Posts: 85
edited 2007-11-22 18:24 in Propeller 1
Happy Thanksgiving Everyone! I hope you all enjoy this favorite holiday of mine!


I unfortunately left my protoboard at the office yesterday and won;t be going back until Monday so am without a testbed this weekend, hence my question instead of a trial and error effort.

I am using Rokiki's SD card routines for datalogging, but would like to use an input string as the filename on the SD card rather than the fixed name in the DAT section of the standard SD routines. (I'll be using the GPS-provided date string in this case).

How can I use a returned variable string, ie:

variableinfo := gps.date()



in place of the @Filename in:

DAT

  FileName   byte     "DATALOG.TXT", 0                             ' Name of file that we will write to

PUB LOGIT

  Modem.startx(RX_Pin, TX_Pin, Mode, BaudRate)                      ' Start serial port for gps
  sdfat.mount(SD_base)                                              ' mount the SD card on pins P0 to P3 
  sdfat.popen(@FileName, "a")                                       ' Open the file for append

  ..etc...





Thanks for your suggestions. As long as I have been programming SPIN, I still haven't gotten the hang of that @sign...

Paul

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-22 00:23
    The "@" just means that you want the address of the variable that follows the "@" (which is FileName in this case). "@FileName" simply means that you want to pass the address of the first byte of the array with the name "FileName". That's all.

    Spin has very limited string manipulation. You can basically copy a sequence of bytes from one place to another (with BYTEMOVE) and you can compare two strings for equality (with STRCOMP). You can also do other manipulation one byte at a time by writing your own code to do so. I don't know what gps.date returns, but you need to convert it to an 8 character sequence of bytes, preferably ASCII digits and letters. This needs to be copied over the 1st 8 characters of the FileName variable or you need to pass the address of whatever you use instead of the address of FileName to the sdfat.popen routine.
  • Paul_HPaul_H Posts: 85
    edited 2007-11-22 03:11
    Hey there Mike,

    Thanks for the reply - the @<mem addy> is what I had thought, but I hadn't quite settled on it. Thanks for the clarification.

    Sorry I wasn't clear in my question about my functions - gps.date() returns the value of an array containing the current date information that has been previously parsed and zero terminated. It is in bytes. So in the case:

    "variableinfo" below is assigned by the gps.data PUB to a value like "071121", (representing Nov 11, 2007).

    So...if I get this @ thing correct, I should use:

    ...
    sdfat.popen(@variableinfo, "a")
    ...
    
    



    to point to the memory location of my gps.date()-assigned variable, just like it did when the routine used a fixed DAT-assigned value.

    I hope Im on the right track! Thoughts?

    Paul
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-22 03:39
    That looks right from this direction...

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

    — Calvin, of 'Calvin and Hobbes.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-22 06:37
    Yep.

    Remember that the filename will be whatever is in that string, so it won't have ".txt" or the like unless you put it there.
  • Goran (Sweden)Goran (Sweden) Posts: 68
    edited 2007-11-22 08:51
    Paul H,
    I used the code below in a datalogging prog I am working on.
    If you want I can mail the whole spinprog.

    PUB Createfile 'Creates a filename with todays date and Time and write a timestamp in the created file

    DateForSDcard
    char:=0

    Filnamnet 'PUB which creates the filename se below

    'nedan fungerar f
  • Paul_HPaul_H Posts: 85
    edited 2007-11-22 18:16
    Goran,

    This is just what I am working towards. Your post makes it clear how you are creating the filename from the variable information. I'll work through your example and work this concept into my routine. When complete I'll post the code back here.

    Mike - understood on the naming. I'll be adding the file extension myself. It'll start as ".txt" and move to ".xml" when I get my XML heading program together.

    Thanks Everyone!
    Paul

    Post Edited (Paul H) : 11/22/2007 6:21:03 PM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-22 18:24
    There's a bunch of code in PropDOS for SD operations with strings that may be useful.
    I'd also take a look at FemtoBASIC. It was a valuable source for information when I created
    PropDOS
    http://forums.parallax.com/showthread.php?p=683157

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

    — Calvin, of 'Calvin and Hobbes.
Sign In or Register to comment.