Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
Chopperp Guru Joined: 03/01/2018 Location: AustraliaPosts: 1106
Posted: 11:58am 14 Apr 2018
Copy link to clipboard
Print this post
Hi I can Write & Read single variables OK to the SD card using OPEN FOR RANDOM & SEEK. But I am having a great deal of trouble reading more than one variable from the card. I also store lots of data OK with OPEN FOR APPEND, so I assume one would use OPEN FOR INPUT to get data back but I have nor worked out how to do it. It is obviously simple but I am missing the plot some where. I only want to read two variables back again. Any help appreciated. The Appendix on Random File I/O looks rather complicated for more than one variable or record. (Give me 6502 machine code any day )
Thanks ChopperP
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9750
Posted: 02:41am 15 Apr 2018
Copy link to clipboard
Print this post
You can keep your 6502 code!
Assuming you are reading and writing at random locations within a file on the card, then you would read back from the file using:
OPEN "FILE.TXT" FOR RANDOM AS #1 (for example) - See page 23 of the MM+ manual.
That done, use SEEK to position the file pointer within the file to the byte you want to start reading from: SEEK #1,200 for example.
Now, read the byte(s) at the pointer location: D$=INPUT$(5,#1), which will read in five bytes from byte 200, and stick them into D$ in this example. MMBASIC will increment the file pointer by however many bytes you want to read, but I THINK that the pointer will return to whatever you last set it to following the read - you would need to test that.
Smoke makes things work. When the smoke gets out, it stops!
Chopperp Guru Joined: 03/01/2018 Location: AustraliaPosts: 1106
Posted: 02:51am 15 Apr 2018
Copy link to clipboard
Print this post
Thanks Groggs. Will see if that works on the CMM later today. ChopperP
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9750
Posted: 02:56am 15 Apr 2018
Copy link to clipboard
Print this post
Oh, I missed the bit about the CMM.... Hopefully though, SD card access is pretty standard across all the versions. (false logic?)Smoke makes things work. When the smoke gets out, it stops!
Chopperp Guru Joined: 03/01/2018 Location: AustraliaPosts: 1106
Posted: 12:45pm 15 Apr 2018
Copy link to clipboard
Print this post
I knew it was easy but took a long while to get something working. In a nutshell Storing: Open file for RANDOM AS # whatever Seek #, position 1 Print Data1 Seek #, position 2 Print Data2 Close #
Retrieving: open again seek # position 1 input #, Data1 seek # position 2 input #, Data2 close #ChopperP