Write to start of sd card file

For general Flowcode discussion that does not belong in the other sections.
BenR
Matrix Staff
Posts: 1707
http://meble-kuchenne.info.pl
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Write to start of sd card file

Post by BenR »

Hello,

$(scrdir) is the project file source directory and so will look for files in the same directory as the .fcfx file you opened. Glad you have found the issue, let us know if you find anything further.

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Write to start of sd card file

Post by WingNut »

I've had another look at this. I've added retval and watched to see if the opnefile macro returned 0 but it never does
No matter where I put the files (test.txt and filetest.fcfx) and open them from, retval never changes. I just dont understand this. In my own program the file i updated with the data I am logging ok so its definitely finding my own cfg file but if I could get your file to work I might be able to figure out what I'm doing wrong.
Is it a windows 11 environment variable or something?
Attachments
FileTest(1).fcfx
(11.73 KiB) Downloaded 36 times

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

Re: Write to start of sd card file

Post by mnfisher »

Hi,

Something is odd - I can run this AOK.. I changed the FileSystem->RootDirectory to R:\ and it works perfectly. I wonder if there is a limit on the path length ?

Martin

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

Re: Write to start of sd card file

Post by BenR »

Hello Wingnut,

The console may help in diagnosing your problem.

I had a look and it looks like your path is missing the final \

Code: Select all

C:\Users\Norma\Documents\Flowcode files
but probably should instead be

Code: Select all

C:\Users\Norma\Documents\Flowcode files\
My clue was this line in the console.

Code: Select all

Open File: C:\Users\BenR\Documents\Flowcode Filestest.txt - Error File Not Found
On adding the slash

Code: Select all

Open File: C:\Users\BenR\Documents\Flowcode Files\test.txt - OK - Filesize: 167 Bytes
I might see if I can auto add the slash if it's missing so this problem goes away.

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

Re: Write to start of sd card file

Post by BenR »

I've now fixed the problem in the component and it now auto adds the slash if it's missing.

Fingers crossed this works for you.

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

Re: Write to start of sd card file

Post by BenR »

Also added a further mod which does the same thing for open folder and also fixes a bug I just spotted where the open folder simulation would only allow you to go one level deep.

Also applied these fixes to the App Inventor File component.

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Write to start of sd card file

Post by WingNut »

Great Ben. I'll test it out when I get home.
My names not norma by the way - typo setting up new pc.
Its Betty but you can call me Al. :)

N

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Write to start of sd card file

Post by WingNut »

Tried it straight away and still wouldn't work so I added the other variables to the "watch variable" in simulation debugger so I could see it step by step reading in the string but it wouldn't write the incremented number back. I disabled 'update filesector and added write filesector and it works! At all speeds too. Now to try it in my own program. Not sure what the issue is with update filesector

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

Re: Write to start of sd card file

Post by BenR »

Hello,

Glad there's some progress :D

Write file sector will add data to the file header, it will update the file length by 512 bytes by adding a new sector to the file. If the file is a newly created fresh file then it will add the first sector to the file complete with the data in the buffer.

Update file sector won't modify the header and will just overwrite the current sector with the data in the buffer. If the file is a newly created fresh file then the sector will not be added to the file and the file will still appear as being empty.

At least that's what should be happening :lol:

WingNut
Posts: 254
Joined: Tue Jul 13, 2021 1:53 pm
Has thanked: 33 times
Been thanked: 23 times

Re: Write to start of sd card file

Post by WingNut »

Ok Thanks Ben. I did get some success with write file sector in my own program last night but not quite what i was expecting and that may be partly my own fault and partly what you have described above. I'll have another go with update file sector tonight

Post Reply