Shop OBEX P1 Docs P2 Docs Learn Events
Writing Decimal Values to SD — Parallax Forums

Writing Decimal Values to SD

dermotdermot Posts: 26
edited 2011-11-04 10:47 in Propeller 1
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.

Comments

  • SarielSariel Posts: 182
    edited 2011-11-03 09:31
    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 GreenMike Green Posts: 23,101
    edited 2011-11-03 09:33
    .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
    
  • KyeKye Posts: 2,200
    edited 2011-11-03 11:27
    The example code comes with a rountine that writes decimal and hexadecimal values also.
  • dermotdermot Posts: 26
    edited 2011-11-04 02:54
    Thank you for sample code works brilliant.

    Is it possible to check if a file exists before opening??
  • KyeKye Posts: 2,200
    edited 2011-11-04 10:47
    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.
Sign In or Register to comment.