I’ve been trying to get either an SD-based of USB-based pseudo-flashdrive to work on a FEZ Spider (4.2 libraries).
I’ve got the following HW configuration:
FEZ SPider
USBClientDP (wired to socket 1)
USBHost (wired to socket 3)
RS232 (wired to socket 11)
The USBHost and Client are connected in the IDE to the FEZ Spider. THe RS232 is not, as it’s just for debugging.
The code :
using System;
using System.IO;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.USBHost;
using GHI.Premium.IO;
using GHI.Premium.System;
namespace GadgeteerApp1
{
public partial class Program
{
static PersistentStorage ps;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
RemovableMedia.Insert += RemovableMedia_Insert;
RemovableMedia.Eject += RemovableMedia_Eject;
// Subscribe to USB events
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
}
static void DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.MassStorage)
{
Debug.Print("USB Mass Storage detected...");
ps = new PersistentStorage(device);
ps.MountFileSystem();
}
}
static void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is inserted.");
Debug.Print("Getting files and folders:");
if (e.Volume.IsFormatted)
{
string[] files = Directory.GetFiles(e.Volume.RootDirectory);
string[] folders = Directory.GetDirectories(e.Volume.RootDirectory);
Debug.Print("Files available on " + e.Volume.RootDirectory + ":");
for (int i = 0; i < files.Length; i++)
Debug.Print(files[i]);
Debug.Print("Folders available on " + e.Volume.RootDirectory + ":");
for (int i = 0; i < folders.Length; i++)
Debug.Print(folders[i]);
}
else
{
Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
}
}
static void RemovableMedia_Eject(object sender, MediaEventArgs e)
{
Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
}
}
}
the program starts fine, but when I plug in the USB flash drive to the USBHost Module, an exception is thrown:
Program Started
USB Mass Storage detected…
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (4) ####
#### Message:
#### GHI.Premium.IO.PersistentStorage::PersistentStorage_Helper [IP: 0000] ####
#### GHI.Premium.IO.PersistentStorage::.ctor [IP: 0011] ####
#### GadgeteerApp1.Program::DeviceConnectedEvent [IP: 001b] ####
#### GHI.Premium.USBHost.USBH_DeviceConnectionEventHandler::Invoke [IP: 8017e487] ####
#### GHI.Premium.USBHost.USBHostController::nativeEventDispatcher_OnInterrupt [IP: 0037] ####
#### GHI.Premium.System.InternalEvent::nativeEventDispatcher_OnInterrupt [IP: 0054] ####
A first chance exception of type ‘System.InvalidOperationException’ occurred in GHI.Premium.IO.dll
An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHI.Premium.IO.dll
This is actually the same behavior that PersistentStorage gives with SD cards (using, of course, those examples).
I’m beginning to believe that something’s wrong in the Premium.IO library - but don’t know how to debug it. Any thoughts/help?
Also, if this belongs in another forum, please let me know…)