我试图使用GHI Gadgeteer SDCard module调试一些意外行为,从而无声地将文件保存到SDCard会导致文件无法显示。
可以使用SDCard模块的源代码(从the root导航到Main/Modules/GHIElectronics/SDCard/Software/SDCard/SDCard_42/SDCard_42.cs)。我的代码中的行没有按照我的预期进行
sdCard.GetStorageDevice().WriteFile("picture.bmp", picture.PictureData);
查看GHI源代码GetStorageDevice()
很简单:
public StorageDevice GetStorageDevice()
{
return _device;
}
和_device
被声明为
private StorageDevice _device;
下载代码我看到_device
的类型为Gadgeteer.StorageDevice
。我在哪里可以找到该类的源代码?
答案 0 :(得分:1)
您必须先装载sdCard
才能使用它:
sdCard.MountSDCard();
为了确保您看到这一点,您应该事先“连接”Mounted和Unmounted事件处理程序,但是:
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");
}
如果这些都不是您的问题,我建议按以下方式分解您的GetStorageDevice()
电话:
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;
如果您无法使用Bitmap.Save Method,则可以使用其他传统的StreamWriter技术。
我实际上无法测试它是否有效,但是,因为我没有这些SD卡模块。我刚看了SD Card Module Tutorial上的示例代码。
如果有帮助,请将其投票。如果它解决了您的问题,请将其标记为答案。
答案 1 :(得分:1)
我得到了an answer on the TINYCLR forum。它位于Main/GadgeteerCore/Gadgeteer42/Utilities.cs
当前版本(撰写本文时)为:http://gadgeteer.codeplex.com/SourceControl/changeset/view/24955#200043