Page 1 of 1

SD Card file in simulation

Posted: Tue Jul 19, 2022 11:53 pm
by mnfisher
This had me scratching my head for a while :(

FileSD::CreateFile(filename)
FileSD::OpenFile(filename)
FileSD::AppendString("Some data")
FileSD::ReadByteFromIndex [0..n] "Some data" back (doesn't work if run.)

This worked correctly if single stepping the code. However, if the code was 'run' then it didn't work.
Note that the 'logic' of the program was to open a file and read some initial config data from it. If the file didn't exist then it would be created - initial data written - and then continue with the read.

Adding a 1s delay after CreateFile solved the problem ? (Note the file was created on a ram disk)

Martin

Re: SD Card file in simulation

Posted: Wed Jul 20, 2022 1:15 pm
by BenR
Hi Martin,

Thanks for letting us know. The CreateFile command should also open the file so maybe Opening again before the file is ready is somehow causing some kind of a problem. The delay required might also vary per system but you would think a second or two would cover most cases.

Re: SD Card file in simulation

Posted: Wed Jul 20, 2022 2:35 pm
by mnfisher
Yes - though I haven't tested it on hardware (it's probably just be a simulation issue?) The tooltip for CreateFile specifies that the file must be opened using Open_File (sic) before writing any data (I don't think Create leave it open - the tooltips are wrong though - for example CreateFile shows as CreateFile(<number>) Delete as Delete(<number>) etc - although they take a filename).
I noticed I got an empty file on times when I ran the program and correct data on stepping through (all looks good!)

I used a ramdisk (trying to maximise life of the SSD (especially when using ESP32!) - but this might be misguided) - and did wonder if slower media would need more of a delay? I'll maybe test using a USB stick as the destination and see if a longer delay is needed.

Martin