SD card .txt file need help with line feed
Tony_tsi
Posts: 98
I building a data logger as a school project. I want to log into a txt file in the following manner
Time,data,
Time,data,
Time,data,
But instead end up with this
Time,data,time,data,time,data
I have everything working great except for the line feed or carriage return(not sure what to call it)
So my question is what do u do to make the txt file line feed?
Things I have tried
13
"13"
"^13"
"\n
"\n"
"\|"
"EOL"
"LF"
"NL"
"\r"
"\rl"
I am using the micro sd file from the object exchange
Time,data,
Time,data,
Time,data,
But instead end up with this
Time,data,time,data,time,data
I have everything working great except for the line feed or carriage return(not sure what to call it)
So my question is what do u do to make the txt file line feed?
Things I have tried
13
"13"
"^13"
"\n
"\n"
"\|"
"EOL"
"LF"
"NL"
"\r"
"\rl"
I am using the micro sd file from the object exchange
Comments
this fixed all of my problems but I still have a curiosity question......
Why will it not line feed without a carriage return?
If I type sdfat.pputs(string(13)) it should return to the next line but not go to the left side of the page. But it does not do this.
Lets say i have 4 long variables called x, month, day, year
Month:=5
Day:=25
Year:=2013
What I want to do is somthing like this
X:=String(month,"_"'day,"_",year,".txt")
So that when I make a file the file name would be
5_25_2013.txt
For Windows, you use 13 (CR), then 10 (LF). The 13 (CR) will do a carriage return, returning the cursor to the left margin while the 10 (LF) will get you a vertical line space.
For the MacOS, you use 13 (CR) to do both a carriage return and a line feed. An additional 10 (LF) will get you another vertical line space without returning the cursor to the left margin.
For Linux, you use 10 (LF) to do both a carriage return and a line feed (a 'new line').
Thank you this clears things up a lot.
OBJ num : "Numbers"
Then you'd do something like
sdfat.pputs(num.dec(month))
sdfat.pputc("_")
sdfat.pputs(num.dec(day))
sdfat.pputc("_")
sdfat.pputs(num.dec(year))
sdfat.pputs(string(".txt"))
This would write the file name out to the file. If what you want to do is construct a file name from the date, I'd do it differently.
VAR byte filename[11]
filename[0] := month/10+"0" ' two digit month value
filename[1] := month//10+"0"
filename[2] := day/10+"0" ' two digit day value
filename[3] := day//10+"0"
filename[4] := (year//100)/10+"0" ' rightmost two digits of year value
filename[5] := (year//100)//10+"0"
bytemove(@filename+6,string(".txt"),5) ' moves ".txt" plus a final zero byte to the end
The former accepts a character like "_" while the latter requires the address of a zero-byte terminated string which string("_") supplies.
If you want the underlines in my 2nd example, use
VAR byte filename[13]
bytemove(@filename,string("00_00_00.txt"),13)
filename[0] += month/10 ' two digit month value
filename[1] += month//10
filename[3] += day/10 ' two digit day value
filename[4] += day//10
filename[6] += (year//100)/10 ' rightmost two digits of year value
filename[7] += (year//100)//10
You'd want to subtract 2000 from your YEAR value before running the method, so that it's 2 digits instead of 4. Or modify the method to convert 4 digits instead of two.
Good luck to ya!
I just wanted to offer a different way to look at the problem here. Everyone always helps me out so I'm happy to attempt the same if I can.
I am having trouble plugging this into my code
Bytemove is a new command to me, I did read up on it in the manual. It appears to me that each byte in the filename array is written as a character from "00_00_00.txt" like so
Filename[0]=0
Filename[1]=0
Filename[2]=_
Filename[3]=0
Filename[4]=0
Filename[5]=_
Filename[6]=0
Filename[7]=0
Filename[8]=.
Filename[9]=t
Filename[10]=x
Filename[11]=t
And then the following lines rewrite the zeros into the correct numbers
Is this correct?
Why 13 elements?
If so how do I pull this together into one string?
x:=string( )
You don't. It's already done. A string is a sequence of non-zero bytes terminated by a zero which we just prepared in the filename byte array. So all you need is x := @filename[0].