Hi all
I am using the SD card module in my project which is working very well. I have the need to ready from a certain position within a file, but notice the read commands appear to start at byte zero and auto increment with every subsequent read command.. Is the a way to specify a starting position (in byes) within a file to begin reading from?
Cheers
Lee
SD Card Read position
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: SD Card Read position
With the file already open, you can use FSeek() to position to a random position.
-
- Posts: 38
- Joined: Wed Nov 02, 2022 10:31 am
Re: SD Card Read position
Thanks Gerry
With regard to FSeek() and FilePtr(), do these reference from position 0 or from position 1?
IE does FSeek(0) reference the first byte in a file? Or is it FSeek(1)?
Also does FilePtr() reference the current position, or the next position?
IE
SD.openfile()
Var=SD.readbyte()
longVAR=FilePtr()
What would Long var be at this point?
Cheers
Lee
With regard to FSeek() and FilePtr(), do these reference from position 0 or from position 1?
IE does FSeek(0) reference the first byte in a file? Or is it FSeek(1)?
Also does FilePtr() reference the current position, or the next position?
IE
SD.openfile()
Var=SD.readbyte()
longVAR=FilePtr()
What would Long var be at this point?
Cheers
Lee
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: SD Card Read position
FSeek() and FilePtr() are 0-based, so the first byte is at position 0.
When you open a file, File.BytesRead is set = 0.
Each time you read or write a byte, File.BytesRead gets incremented.
The function FSeek() sets a new value for File.BytesRead.
So...
FilePtr() returns the value of SD.File.BytesReadAlso does FilePtr() reference the current position, or the next position?
When you open a file, File.BytesRead is set = 0.
Each time you read or write a byte, File.BytesRead gets incremented.
The function FSeek() sets a new value for File.BytesRead.
So...
Code: Select all
SD.openfile() // sets File.BytesRead=0
longVAR=FilePtr() // longVAR would be 0
Var=SD.readbyte() // returns current byte and increments File.BytesRead, so now File.BytesRead = 1
longVAR=FilePtr() // longVAR would be 1
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: SD Card Read position
I noticed in the comments that you have to use OpenFileRW() instead of OpenFile() if you want to use FSeek().
I haven't tested that... if you run across anything odd let me know.
I haven't tested that... if you run across anything odd let me know.
-
- Posts: 38
- Joined: Wed Nov 02, 2022 10:31 am
Re: SD Card Read position
Thanks JerryJerry Messina wrote: ↑Sat Sep 02, 2023 10:21 pmI noticed in the comments that you have to use OpenFileRW() instead of OpenFile() if you want to use FSeek().
I haven't tested that... if you run across anything odd let me know.
I will have to test that..
Cheers
Lee