PDA

View Full Version : Writing Decimal Values to SD



dermot
11-03-2011, 05:20 PM
Hi

Is is possible to write a decimal value directly to an SD card using Kwabena W. Agyeman SD card driver? I have tried sdfat.writebyte(count), where count has bee assigned a value. A character instead of the number is been stored.

Sariel
11-03-2011, 05:31 PM
My first guess is that instead of writing the actual number, it is dumping it as an ASCII code, thus displaying the character instead of the number. Have you tried:



sdfs.writeData(addressToGet, count)

Mike Green
11-03-2011, 05:33 PM
.writebyte is doing exactly what it's supposed to do. Some of the other SD card objects have a routine (.dec) that takes a value and converts it to an ASCII decimal string, then outputs it to the SD card a character at a time. Here's one such routine that you can use:
pub writeDec(value) | i ' Output a decimal value
if value < 0
-value
sdfat.writebyte("-")
i := 1_000_000_000
repeat 10
if value => i
sdfat.writebyte(value / i + "0")
value //= i
result~~
elseif result or i == 1
sdfat.writebyte("0")
i /= 10

Kye
11-03-2011, 07:27 PM
The example code comes with a rountine that writes decimal and hexadecimal values also.

dermot
11-04-2011, 10:54 AM
Thank you for sample code works brilliant.

Is it possible to check if a file exists before opening??

Kye
11-04-2011, 06:47 PM
No need. Please read up on the documentation here: http://www.parallaxsemiconductor.com/an006

You can just open the file. Catch the error string and check the error code. If the error code is that the file does not exist then you know it does not exist.