I have an SD card connected to socket 9 on a Raptor board which is mounted at startup and can be read and written without problems.
For external access to the files on the SD card I am exposing it as USB client mass storage by the following method (newest SDK 4.3 2014 R5), which is called in a btn_TapEvent routine after tapping a button on the T43 touch screen:
public static void AttachAsMassStorage()
{
if (sdCard.IsCardMounted)
sdCard.Unmount(); // can't be used as USB client mass storage while mounted for appl. usage
if (ms == null)
ms = new MassStorage();
Controller.ActiveDevice = ms;
GHI.IO.Storage.SDCard sdAsMSC = new GHI.IO.Storage.SDCard();
ms.AttachLogicalUnit(sdAsMSC, 0, "", "");
ms.EnableLogicalUnit(0); // enable external access
ModalResult msgBoxResult = Glide.MessageBoxManager.Show("Message", "Title", ModalButtons.Ok);
// user has finished file access via PC now ->
// detach mass storage and remount SD card to the application
ms.DisableLogicalUnit(0); // after this, drive is shown on PC but can't be accessed
Controller.ActiveDevice = null; // should remove the drive completely
}
Exposing the SD card to an external PC via AttachLogicalUnit() and EnableLogicalUnit() and accessing it from there works fine, DisableLogicalUnit() also works as expected.
My problem is, that I can’t get it managed to detach the USB client mass storage and re-mount the SD card for further use by the application.
Setting Controller.ActiveDevice = null executes without exception and the corresponding drive letter is removed from the PC’s explorer window, but after property assignment it always takes around 10 sec. and the Raptor does an unintended reset.
It doesn’t make a difference, if I place the above codelines there or, maybe more favourably, in the sdCard_Unmounted event:
The device is always resetted around 10 sec. later as a result of the Controller.ActiveDevice = null property assignment, so I don’t have the chance to sdCard.Mount() again. If I try to re-mount the card without nulling the Controller.ActiveDevice property, #### GHI.IO.Storage.SDCard::NativeConstructor [IP: 0000] #### exception is thrown.
I am not sure whether it’s maybe a similar issue as stated in #9 in https://www.ghielectronics.com/community/forum/topic?id=17121&page=1 or if I’m just doing something wrong. Any working approach for detaching USB mass storage client and remounting the SD card to the application would be very welcome.
[em]Addition:[/em] I found that setting the Controller.ActiveDevice to a new CDC() (instead of detaching the MSC by nulling it) works as a temporary workaround. After subsequent disposal of the GHI.IO.Storage.SDCard object (sdAsMSC) I then can remount the SD Card to the application (w/ sdCard.Mount) and repeat the procedure as often as necessary without any issue.
But the “reboot problem”, triggered by setting Controller.ActiveDevice = null remains, independently of VS 2012 Debug or Release mode or running as Release w/out VS.