Shop OBEX P1 Docs P2 Docs Learn Events
Embarassing question about writting to a uSD — Parallax Forums

Embarassing question about writting to a uSD

SteveJoSteveJo Posts: 2
edited 2013-02-16 11:49 in General Discussion
I've worked with a uSD with my propeller for well over a year without problem. Unfortunately, the text wraps and edits need to be made to a text file before it can be read into Excel without loss of data.
Lately my files have been hundreds of lines long, which can be managed, but, soon they'll be moving to thousands of lines long.
I have not been able to figure out how to write a carraige return to the end of one of my lines, but, have tried the following:

sdfat.pputs(string(13)
sdfat.pputs(string("\r"))
sdfat.pputc(13)
sdfat.pputs(13)

... and none of them work. I use the fsrw Object.

Does anyone have suggestions??

Thanks,
Steve

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-02-15 07:28
    Excel wants both a carriage return (13) and a new line (10) character.

    I haven't used fsrw for a while, but I think it could be done like this:
    sdfat.pputc(13)
    sdfat.pputc(10)
    


    The carriage return by itself would work if you saved the file first as a .txt file and then "imported" into Excel. If the file is a .csv file, Excel expects to see both the characters mentioned above.
  • max72max72 Posts: 1,155
    edited 2013-02-15 07:31
    windows expects CR+LF, di you try writing 13 (carriage return) and the 10 (line feed)?
    Otherwise if you only write 10 (the line feed) you can open it with wordpad (the text editor inside windows), it should look correct, and then save it back.
    With your setup it could work too...
    For reference check also:
    http://en.wikipedia.org/wiki/Newline

    Massimo
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-15 07:34
    To save some program memory, define a DAT section like this
    DAT
    crlf   byte   13,10,0
    
    Then you can just write sdfat.pputs(@crlf)
  • SteveJoSteveJo Posts: 2
    edited 2013-02-15 08:22
    Thanks Duane, max72, and Mike. I tried Duane's code and it worked. Probably saved me 4 hours this weekend alone! This is a great Forum, I barely had time to eat breakfast and had three answers!!:smile:
  • varnonvarnon Posts: 184
    edited 2013-02-15 17:55
    Huh. I noticed the same problem... sometimes.
    I didn't know that windows wanted a 10.

    When I did have this problem, I just had a python script read a file in, and save it again - with zero changes. As long as I did this on a windows platform, that computer could read it.

    I seem to have only had that problem with .txt files, .csv files worked fine.
    I'll read up on it more. Thanks for making me aware of this Steve et al.
  • max72max72 Posts: 1,155
    edited 2013-02-16 02:26
    Steve,
    I forgot to welcome you!!

    Having used the prop for over a year you probably have been around the forum for some time, but nonetheless a welcome is in order.

    Massimo
  • doggiedocdoggiedoc Posts: 2,243
    edited 2013-02-16 04:11
    Mike Green wrote: »
    To save some program memory, define a DAT section like this
    DAT
    crlf   byte   13,10,0
    
    Then you can just write sdfat.pputs(@crlf)
    Elegant solution. I'll have to remember that technique.
  • sidecar-racersidecar-racer Posts: 82
    edited 2013-02-16 11:49
    I'm working with a data logger, creating an .csv file on the SD-card. I can unplug (not elegant:)) and put in PC, then open with excel, no problems.
    The way I did it was making two DAT entries, one is the excel header (created by making a blank spreedsheet with lables only), and one with data. The program fills the second DAT area with varibles (location of varible in string is a set of pointers. When a new file is created, first the header is written, then each logger update is written (100ms steps). When vehicle stops (below 5mph) logging stops, file is closed. Ready for next file.
    These writes are all string writes. I'm using fswr 2.6 so my limit is 32 files which works fine for my needs.
    Search projects for sidecar, my code is zipped there.
Sign In or Register to comment.