@ Alex Bilityuk - I ask what your end goal is when using an SD card so I can write an example for you that does not use SDCard. You cannot use SDCard in a Gadgeteer program with the FEZ Cerbuino Bee, FEZ Cerbuino Net, or FEZ Cobra II Eco because they work with SDCard internally and provide Gadgeteer wrappers for you.
John, my full project is on Gadgeteer. I control the robo using WiFly module, and send commands on it. You mean if i need to control SdCard Mount() and UnMount() methods i should use a Microframework project instead of Gadgeteer?
@ Alex Bilityuk - No, you can use SD cards through Gadgeteer. You just cannot use the SDCard class on the Cerbuino mainboard. The SDCardMounted event on the Mainboard object gives you a Gadgeteer.StorageDevice object that you can use to read and write files. That object is valid until you receive an SDCardUnmounted event.
John, can you do me a favour? post a code snippet please⌠how to use SDCardMounted event on the mainboard object to mount and unmount SD card in Gadgeteer project⌠thank you.
How to fire Mainboard_SDCardMounted event it never fires when the SDCard insertedâŚ
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.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using GHI.IO;
using GHI.IO.Storage;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using System.Text;
namespace SDTest
{
public partial class Program
{
void ProgramStarted()
{
Mainboard.SDCardMounted += Mainboard_SDCardMounted;
Mainboard.SDCardUnmounted += Mainboard_SDCardUnmounted;
while (Mainboard.IsSDCardInserted)
{
while (Mainboard.IsSDCardMounted)
{
Mainboard.MountStorageDevice(Mainboard.SDCardStorageDevice.Volume.Name.ToString());
Thread.Sleep(1000);
}
Thread.Sleep(1000);
}
}
void Mainboard_SDCardUnmounted(GHIElectronics.Gadgeteer.FEZCerbuinoBee sender, EventArgs e)
{
Debug.Print("SD is Unmounted");
}
void Mainboard_SDCardMounted(GHIElectronics.Gadgeteer.FEZCerbuinoBee sender, GT.StorageDevice device)
{
Debug.Print("SD is mounted");
//device.WriteFile("Test.txt", Encoding.UTF8.GetBytes("Hello, world!"));
}
its an event - if it is triggered, it will fire. If you think the way youâre using the device is not triggering that event then explain what you did to let others know - Dat or John @ GHI will be able to validate what they see versus what you see. But you have to get rid of that while() loop in your program started and go back to Johnâs original code
Ok, i just want to trigger SDCardMounted event automatically. How to do that? When i insert SD to slot this event is not triggerd.
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.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using GHI.IO;
using GHI.IO.Storage;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using System.Text;
namespace SDTest
{
public partial class Program
{
void ProgramStarted()
{
Mainboard.SDCardMounted += Mainboard_SDCardMounted;
Mainboard.SDCardUnmounted += Mainboard_SDCardUnmounted;
}
void Mainboard_SDCardUnmounted(GHIElectronics.Gadgeteer.FEZCerbuinoBee sender, EventArgs e)
{
Debug.Print("SD is Unmounted");
}
void Mainboard_SDCardMounted(GHIElectronics.Gadgeteer.FEZCerbuinoBee sender, GT.StorageDevice device)
{
Debug.Print("SD is mounted");
//device.WriteFile("Test.txt", Encoding.UTF8.GetBytes("Hello, world!"));
}
The event should be triggered automatically when the card is inserted. It will not trigger if the card is already inserted when you power up the board.
In my case it doesnât trigger not after nor before the power is upâŚi tried to insert the card before power up and after power up, insert/eject during power is up but with no sucess. Instead of Sd is mounted in output window i see this exception