Main Site Documentation

Cobra II SD-Card - second mount fails


#1

Hi, I am trying to make my Cobra II behave while writing to the SD-Card. Why does the below code fail the second time, it works great first time…

This code is called in a event from the motionsensor…with this exception:

    
 #### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1)     
 #### Message: 
 #### GHI.Premium.IO.PersistentStorage::.ctor [IP: 0000] ####
 #### GadgeteerApp11.Program::motion_Sensor_Motion_Sensed [IP: 0025] ####


Debug.Print("Saving to SD card now...");
if (PersistentStorage.DetectSDCard())
    sdPS = new PersistentStorage("SD"); // <- This line sends it to Nirvana at second execution...
sdPS.MountFileSystem();
FileStream outPutFileStream = null;
outPutFileStream = new FileStream(@ "SD\image" + DateTime.Now.Ticks.ToString() + ".jpg", FileMode.Create);
outPutFileStream.Write(picture, 0, picture_size);
outPutFileStream.Close();
outPutFileStream.Dispose();
sdPS.UnmountFileSystem();
outPutFileStream = null;
Debug.Print("Save to SD finished");


#2

try setting sdPS to null, and then do GC. See if that helps.