Frage

I'm trying to debug some unexpected behaviour with the GHI Gadgeteer SDCard module whereby saving a file to an SDCard silently results in no file appearing.

The source code for the SDCard module is available (from the root navigate to Main/Modules/GHIElectronics/SDCard/Software/SDCard/SDCard_42/SDCard_42.cs). The line in my code that's not doing what I expect is

sdCard.GetStorageDevice().WriteFile("picture.bmp", picture.PictureData);

Looking at the GHI source code GetStorageDevice() is simple:

public StorageDevice GetStorageDevice()
{
    return _device;
}

and _device is declared as

private StorageDevice _device;

Downloading the code I see that _device is of type Gadgeteer.StorageDevice. Where do I find the source code for that class?

War es hilfreich?

Lösung 2

I got an answer on the TINYCLR forum. It is in Main/GadgeteerCore/Gadgeteer42/Utilities.cs the current version (at the time of writing) is: http://gadgeteer.codeplex.com/SourceControl/changeset/view/24955#200043

Andere Tipps

SD Card Module

You must first mount the sdCard before you can use it:

sdCard.MountSDCard();

To make sure you see this, you should "wire up" the Mounted and Unmounted event handlers beforehand, though:

void ProgramStarted() {
  sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
  sdCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(sdCard_SDCardUnmounted);
}

void sdCard_SDCardUnmounted(SDCard sender) {
  Debug.Print("The SD card has been unmounted");
  Debug.Print("DO NOT try to access it without mounting it again first");
}

void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard) {
  Debug.Print("SD card has been successfully mounted. You can now read/write/create/delete files");
  Debug.Print("Unmount before removing");
}

If none of these are your problems, I would suggest breaking down your GetStorageDevice() call as follows:

string rootDirectory = sdCard.GetStorageDevice().RootDirectory;
// What format is `picture`?
// I am going to assume System.Drawing.Bitmap for this example.
picture.Save(rootDirectory + "\\picture.bmp", ImageFormat.Bmp;

If you can not use the Bitmap.Save Method, you would use other conventional StreamWriter techniques.

I can not actually test this to see if it works, however, as I do not have one of these SD Card Modules. I just looked at the sample code on the SD Card Module Tutorial.

If it helps, vote it up. If it solves your problem, mark it as the answer.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top