Page 3 of 4

Re: Write to start of sd card file

Posted: Wed Aug 10, 2022 11:43 am
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.

Re: Write to start of sd card file

Posted: Sun Aug 14, 2022 4:22 pm
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?

Re: Write to start of sd card file

Posted: Sun Aug 14, 2022 10:24 pm
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

Re: Write to start of sd card file

Posted: Mon Aug 15, 2022 10:20 am
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.

Re: Write to start of sd card file

Posted: Mon Aug 15, 2022 10:37 am
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.

Re: Write to start of sd card file

Posted: Mon Aug 15, 2022 11:07 am
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.

Re: Write to start of sd card file

Posted: Mon Aug 15, 2022 11:10 am
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

Re: Write to start of sd card file

Posted: Mon Aug 15, 2022 6:33 pm
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

Re: Write to start of sd card file

Posted: Tue Aug 16, 2022 10:23 am
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:

Re: Write to start of sd card file

Posted: Tue Aug 16, 2022 11:12 am
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