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)
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.
Comments
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?
usb.filesize(string("song.mp3")) 'size of the song.
usb.readFromFile(2_035_712, 2_033_664, 0)'size of the song in bytes.