Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:30 23 Oct 2024 Privacy Policy
Jump to

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.

Forum Index : Microcontroller and PC projects : CMM2: Question on using MM.INFO$(SDCARD) (and tiny error in manual)

Author Message
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 352
Posted: 04:31pm 21 Oct 2024
Copy link to clipboard 
Print this post

Hi all,

I'm trying to monitor the removal and insertion of an SD Card into my CMM2 (for my file manager).

I've been using MM.INFO$(SDCARD) (as noted below from the manual).



It works great to start with. I can see that the SD Card is "Ready" when it's in. When I remove it, it changes to "Not present" - but when I put it back in again - it changes to "Unused". It stays at "Unused" and I can't see a way to get it back to "Ready". Any file actions I try and take on this "Unused" SD Card generate an I/O error.

P.S. The tiny error in the manual is that the returned states are not all capitalised - they start with a capital and are then lower case (e.g. "Ready", "Unused"). Not a big deal - I quickly found the issue by using "PRINT MM.INFO$(SDCARD)" when my logic failed to find "READY".

Here's the code I've been using to test this behaviour. This displays the SD Card status each time it changes. Pop the SDCard out and then pop it back in again and you'll see what I mean.

The code does create a folder on your drive call "GUI" just as a test of the file I/O. That will fail when the card is "Unused".

OPTION EXPLICIT
DIM STRING SDCardStatus

'Main loop
DO
 ReadInsertedSDCard
LOOP

'Subroutine to check SD card
SUB ReadInsertedSDCard
 IF MM.INFO$(SDCARD)=SDCardStatus THEN EXIT SUB ' Nothing has changed

 SDCardStatus=MM.INFO$(SDCARD)
 PRINT "New SD Card status:" + SDCardStatus

 IF SDCardStatus<>"Ready" AND SDCardStatus<>"Unused" THEN
   EXIT SUB
 END IF

 ' If we are here, then the SD card is okay
 IF MM.INFO(EXISTS DIR "A:\GUI")=0 THEN
   MKDIR "A:\GUI"
 ENDIF
END SUB
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9006
Posted: 05:07pm 21 Oct 2024
Copy link to clipboard 
Print this post

From what I remember the CMM2 doesn't support card removal and replacement inside a program. I assume if you do this at the command line it works?
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 352
Posted: 05:16pm 21 Oct 2024
Copy link to clipboard 
Print this post

Thanks Peter. Yes, I can confirm that it works fine from the command line.

Not to worry. I was hoping to use it to copy files between SD Cards using a RAM disk. i.e. I would store the directory being copied into graphics memory (as binary data) swap disks and then write the directory back down to the second SD Card.

But, if it doesn't support it, then it's not a problem. I do have a plan B, which is maybe even better.  

Thanks for looking into it and clarifying.
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1051
Posted: 09:49pm 21 Oct 2024
Copy link to clipboard 
Print this post

I don't know if this is helpful or not but I set/reset a flag "No_SD_Flag" using the up & down keys on a connected keyboard or IR remote.
All routines accessing the SD card check the flag first. If no SD card, Exit Sub
I press the down arrow, wait for the screen message & then remove the card. When finished, reinsert the card & press the UP arrow key. The sub routine does check that the card is actually there.

If you insert a different card, you will need another flags & commands.

 '==================================================================================================
SUB SD_Card_Rem  'Set flag if removed. If inserted, update data as necessary
 FONT 2
 No_SD_Flag = 1               'set flag to stop R/W. Card can be removed
 TEXT 1700, 940, "REMOVE SD CARD ", "LT", 2, 1, RGB(RED), RGB(BLACK):PRINT @(0,0)
END SUB
 
 '=====================================================================================================
 
SUB SD_Card_Ins  'Set flag if removed. If inserted, update data as necessary
 FONT 2
 print @(1700, 960) mm.info(sdcard) "     "
 if MM.INFO(sdcard) <> "Not present" then
   No_SD_Flag = 0
   Data_Flag = 0      'data_Flag & SD Card inserted
   TEXT 1700, 940, "SD Card OK     ", "LT", 2, 1, RGB(green), RGB(BLACK):PRINT @(0,0)
   Check_SD
 endif
END SUB
 
 '=======================================================================================================
 
SUB Data_Save     'saves most screen data daily every 5 mins to SD card.
 FONT 2
 if No_SD_Flag = 1 then exit sub
.
.
.


Brian
ChopperP
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024