Shop OBEX P1 Docs P2 Docs Learn Events
Datalogger Help? — Parallax Forums

Datalogger Help?

G3ek4EvurG3ek4Evur Posts: 10
edited 2011-05-20 20:33 in Propeller 1
My question is based off of the following object: http://obex.parallax.com/objects/237/. On the "readFromFile" method, what does offset mean?

Comments

  • G3ek4EvurG3ek4Evur Posts: 10
    edited 2011-05-20 20:18
    Alright maybe not as well explained as it can be so.


    PUB readFromFile(buf,num,offset): YesNo | c
    '/**
    ' * Read bytes from file opened for read.
    ' *
    ' * @param buf Array to hold the read bytes.
    ' * @param num Number of bytes to read. Must not exceed the number of remaining bytes in the file.
    ' * Call method filesize prior to opening the file and adjust num so it will not read beyond EOF.
    ' * @param offset Startindex in buf to write bytes to.
    ' * @return True if command succesful.
    ' */
    writeByte("R")
    writeByte("D")
    writeByte("F")
    writeByte(" ")
    writeByte(num.byte[3])
    writeByte(num.byte[2])
    writeByte(num.byte[1])
    writeByte(num.byte[0])
    writeByte(CR)
    repeat while num > 0
    c := readByte
    if c <> -1
    byte[buf+offset] := c
    offset++
    num--
    return receivePromptOrError(1000)


    My question before was what is offset?
  • Mike GMike G Posts: 2,702
    edited 2011-05-20 20:29
    You're writing to a buffer. If the buffer address starts at 10 and you have an offset of 10 then the write starts at 10+10 or 10 bytes from the start of the buffer. You might use an offset because there is data in the buffer that you do NOT want to overwrite, you just want to append to the existing buffered data.
  • G3ek4EvurG3ek4Evur Posts: 10
    edited 2011-05-20 20:33
    Alright so would this code work with the DataloggerSPI program.

    usb.filesize(string("song.mp3")) 'size of the song.
    usb.readFromFile(2_035_712, 2_033_664, 0)'size of the song in bytes.
Sign In or Register to comment.