Shop OBEX P1 Docs P2 Docs Learn Events
DataloggerSPI output formating — Parallax Forums

DataloggerSPI output formating

KschulzKschulz Posts: 11
edited 2008-12-27 17:33 in Propeller 1
I am trying to create a table of comma delimited data with commas separating the columns and carriage returns separating the rows. I am using the Parallax Datalogger (#27937). I have the Parallax Datalogger test program working using the DataloggerSPI code from the object exchange. The test program clearly shows how to write strings of data, so adding in the comma delimitation and data is easy. I can't figure out how to create a carrage return in the *.txt file. Does anyone know how to do this? Here is an example...

If I use this code:
logger.writeToFile(string("ABCDE, "),7,0)
logger.writeToFile(string("ABCDE"),5,0)

I get the following in my *.txt file:
ABCDE, ABCDE

I need a way to get:
ABCDE, ABCDE
ABCDE, ABCDE

I tried the code:
logger.writeToFile(string("ABCDE, "),7,0)
logger.writeToFile(string("ABCDE"),5,0)
logger.writeToFile(CR,2,0)
logger.writeToFile(string("ABCDE, "),7,0)
logger.writeToFile(string("ABCDE"),5,0)

This obviously didn't work. I tried a bunch of other strings that also didn't work. I know there is a simple way to do this. Please help.

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2008-12-27 09:41
    Hello K,

    as a very quick suggest try

    logger.writeToFile(13,1,0)

    edited: maybe it's nescessary to write the combination of Linefeed and carriagereturn
    the ASCII-Code for Linefeed is 10

    so it would be

    logger.writeToFile(10,1,0)
    logger.writeToFile(13,1,0)

    or maby it's possible this way
    logger.writeToFile(string(" ",10,13)....


    best regards

    Stefan

    Post Edited (StefanL38) : 12/27/2008 11:15:20 AM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-12-27 10:35
    The method description is very clear:
    PUB writeToFile(buf,num,offset): YesNo
    · '/**
    · ' * Write bytes to file opened for write.
    · ' *
    · ' * @param buf Array holding the bytes to write.
    · ' * @param num Number of bytes to write. Make sure the number is valid or it may lead to disk full.
    · ' * @param offset Startindex in buf to read bytes from.
    · ' * @return True if command succesful.
    · ' */

    Just place CR,LF into a buffer (can be a word)
    VAR
    · word CRLF

    CRLF = $0A0D 'CR in lowbyte, LF in highbyte
    writeToFile(@CRLF,2,0)

    You could also append \r\n to a string:
    string("ABCDE\r\n")
    Not·sure, but I believe \t (horizontal tab) and \f (formfeed) are also supported in string command.

    regards peter

    Post Edited (Peter Verkaik) : 12/27/2008 10:49:57 AM GMT
  • KschulzKschulz Posts: 11
    edited 2008-12-27 15:53
    Thanks so much.

    Peter - your correct it worked great using CRLF = $0A0D.
    I also tried the \r\n sugestion but it returned "ABCDE\r\nABCDE". The other way works great though; problem solved.

    Stefan38 - I tried your suggestion, but it didn't work. I am guessing this is because the command needs to be in hex???

    Thanks again
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-12-27 17:33
    Strange that \r\n does not work.
    The first debug call in DataloggerSPI_test program
    · debug.cprintf(string("Datalogger Test Program for Spin Stamp\r"),0,true)
    uses \r and that works.
    Perhaps only \r·is supported in string command.

    Stefans example does not work because it tries to pass the print value,
    but expected is an address where·the print values are stored.

    regards peter

    Post Edited (Peter Verkaik) : 12/27/2008 5:39:46 PM GMT
Sign In or Register to comment.