![]() |
Forum Index : Microcontroller and PC projects : Armmite F4 SD card file problems
Author | Message | ||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5089 |
Dear matherp, While creating the tetris game I ran into some things I could need some guidance with. It relates to the SD card file handling. I want to create a file on SD card, and write data in it, and read it back again. There are 2 problems I ran into: 1/ According to the manual I should be able to write multiple variables in one print statement. I cannot get it to work. I tried all options (variables separated by space, comma, semicolumn, combinations), see below program, but none seem to work except individual writes (print #). By the way, this problem also exists for individual reads (input #). 2/ When audio is playing, it opens a file handle to the SD card. Not documented, I think this is file handle #1, since when I play audio, I cannot use #1 anymore. Test code: Print "test for SD card file access on Armmite F4" a=100:b=200:d=300:e=400:c=-12 Print MM.Device$;" version";MM.Ver;" (version 5.05.10)" Print "original variables : " Print a,b,c,d,e Print "individual write and individual read from file" write5individual read5individual Print "write 5 using print #1,a,b,c,d,e " write5comma read5individual Print "write 5 using print #1,a,;b,;c,;d,;e " write5commacol read5individual Print "write 5 using print #1,a;b;c;d;e " write5col read5individual Print "write 5 using print #1,a b c d e " write5space read5individual Print "individual write and individual read from file while playing sound" Play wav "tet16cut.wav" write5individual read5individual End Sub read5individual Open "AA" For input As #1 Input #1,a Input #1,b Input #1,c Input #1,d Input #1,e Print a,b,c,d,e Close #1 End Sub Sub write5comma Open "AA" For output As #1 Print #1,a,b,c,d,e Close #1 End Sub Sub write5commacol Open "AA" For output As #1 Print #1,a,;b,;c,;d,;e Close #1 End Sub Sub write5col Open "AA" For output As #1 Print #1,a,b,c,d,e Close #1 End Sub Sub write5space Open "AA" For output As #1 Print #1,a b c d e Close #1 End Sub Sub write5individual Open "AA" For output As #1 Print #1,a Print #1,b Print #1,c Print #1,d Print #1,e Close #1 End Sub Terminal Output: test for SD card file access on Armmite F4 ARMmite F407 version 5.051 (version 5.05.10) original variables : 100 200 -12 300 400 individual write and individual read from file 100 200 -12 300 400 write 5 using print #1,a,b,c,d,e 100 0 0 0 0 write 5 using print #1,a,;b,;c,;d,;e 100 0 0 0 0 write 5 using print #1,a;b;c;d;e 100 0 0 0 0 write 5 using print #1,a b c d e 100 0 0 0 0 individual write and individual read from file while playing sound [71] Open "AA" For output As #1 Error: File number already open > Am I doing something wrong ? Or should these be documented ? This is Armmite F4. Edited 2020-08-02 22:51 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
I got bitten by a version of this 2 days ago. INPUT wants its variables to be comma-separated. My problem was that I had commas in the text data I was trying to read. It's not in the manual, but the solution is to enclose text which includes commas in quotes: "Now, it works" This gives what you're looking for with comma-separated numbers: Sub write5commaSep Open "AA" For output As #1 Print #1,a;",";b;",";c;",";,d;",";e Close #1 End Sub Then you can read back with: Input #1,a,b,c,d,e (I don't know what playing sound might do to it) ~ Edited 2020-08-03 01:01 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Microsoft BASICs and others had a "Write" command for exactly this. it would write out comma separated values with a CRLF on the end which did precisely what you want (probably for the exact same reason) e.g. Write#2,10,20,30,a,b,c,d,e would result in the line (e.g. with a-e = 1-5) 10,20,30,1,2,3,4,5 can't remember if strings written out were surrounded in quotes... think they were http://www.cpcwiki.eu/index.php/Locomotive_BASIC#WRITE_.5B.23st.2C.5D_v.5B.24.5D.2C_v.5B.24.5D https://www.qb64.org/wiki/WRITE_(file_statement) https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/writestatement It would not be easy to write a general SUB to WRITE that handled anything you threw at it due to the arbitrary number of things and types you might want to WRITE out. Best approach is exactly as lizby shows above - a SUB that deals with the problem onto a target. Edited 2020-08-03 01:33 by CaptainBoing |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |