SD Card file in simulation

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

SD Card file in simulation

Post 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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: SD Card file in simulation

Post 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.

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: SD Card file in simulation

Post 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

Post Reply