It has been used on the EMX for along time on Win7
// if USB Power is ON (VBUS, IO Pin)
if (VBUS.Read())
{
try
{
// Attach SD Card as MassStorage
USBC_MassStorage ms = USBClientController.StandardDevices.StartMassStorage();
look -> Thread.Sleep(100);
sdPS = new PersistentStorage("SD");
ms.AttachLun(0, sdPS, " ", " ");
ms.EnableLun(0);
// wait to connect to PC
while (USBClientController.GetState() != USBClientController.State.Running)
{
Debug.Print("Waiting to connect to PC...");
Thread.Sleep(1000);
}
Debug.Print("PC Connected");
Thread.Sleep(1000);
// Wait for PC disconnect
while (VBUS.Read())
{
// Blink MassStorage and Button LED
LED_Y.Write(!LED_Y.Read());
Thread.Sleep(1000);
}
// Disable MassStorage
Debug.Print("PC is disconnected...");
ms.DisableLun(0);
sdPS.Dispose();
}
finally
{
PowerState.RebootDevice(false);
}
}
Note: Look ->
I this location I had used a delay of 1000 msec for a long time.
On ealier versions on NETMF this stopped an Exception, that shoved up from time to time on EMX.
Reducing it to 100 ms, makes it work on Win8 and win7.
This break might no longer be nessary - but I keep it to be sure. It hate periodic exceptions.
It seem that Win8 have shorter timeouts than Win7 - properly to make it faster.
this we know from Visualstudio, the debugger timeout = coffe break.