Ok, i set the using GHI.IO and GHI.IO.Storage references also include GHI.hardware reference to the project. Also i changed PersistentStorage class on SdCard class.
It seems like the SDCard initialization on Cerbuino bee is under the hood.
I am trying to create
SDCard sd = new SDCard();
and use sd.Mount() and sd.UnMount() methods but it throws an exception.
How to handle this events on Cerbuino bee? I want to eject and insert sd during the programm runing on the device and after i want to write some data to sd.
How to make it work:
SDCard sd = new SDCard();
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
RemovableMedia.Insert += RemovableMedia_Insert;
RemovableMedia.Eject += RemovableMedia_Eject;
}
void RemovableMedia_Eject(object sender, MediaEventArgs e)
{
sd.Unmount();
}
void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
sd.Mount();
}
if we have an exception right there, it is usually:
- Connection is not good, check wire, socket....
- The device is not happy with this SD (rarely), replace by different card.
If we have exception in
```cs]sd.Mount();[/code
Usually:
- The SD card need to be formatted (PC can do that).
- Change the clock lower
And,
```cs
RemovableMedia.Insert += RemovableMedia_Insert;
RemovableMedia.Eject += RemovableMedia_Eject;
I don’t think they are used for SD, and they are raised after we mounted, if I remember correctly :d
I also get an exception when I try to execute [em]new SDCard()[/em]. In the past few weeks there were some complaints about it (do a search within this forum). I understood that we don’t need to use it anymore, we should use events and properties that reside in Mainboard class instead. E. g. [em]Mainboard.IsSDCardMounted[/em]. But I am not 100% sure here.
Yes, sure! I want to be able to eject and insert sd card when the programm is running on the device.
Now i turn the power on, send command to capture image, image saves on sd and everything is fine before i eject the sd and insert it back. After sd insertion am trying to capture the image and save it on sd one more time, but it throws an exception. It seems like SD not Mounted properly.
Hi, jeeshenlee! Thank you for the code snippet, but i don’t have IsCardInserted and IsCardMounted properties in GHI.IO.Storage.SdCard class. Also SdCard class doesn’t have Mounted and Unmounted events to be fired… What dll do you use?
i suppose that you are using connectable SDCard module in you case. And you declare the SDCard variable setting up the socket number like SDCard sd = new SdCard(3).
But i am trying to set up the onboard FEZ Cerbuino bee SDCard, it doesn’t have a socket number in constructor and it of the class: GHI.IO.Storage.Sdcard. Because of it your code doesn’t work in my scenario… thank you anyway.
Dat, is this a good approach ? Is it consistent across all devices ? And can I suggest documenting an established “pattern” of how to achieve this reliably ?
Yes, we have to do that on all devices. As I know, reading some basic information about the SD is done before mounting. Renew the object is the best way in case we mounted an SD then take it out, re-insert a different one.
Sorry Dat, I am not sure I agree with how this should be considered - is this a 4.3 framework change? I always look at the SD card as really the abstraction of the hardware device that allows you to read cards, plural. I should be able to instantiate the hardware (once) and wait for card(s) to come to me… When I load a card, that’s the point I should get volume info and a file system etc, but until that time I’m just waiting around. I shouldn’t have to dispose the SD card object and re-instantiate this every time - and the reason it should be before any physical media info is collected is exactly the same one you quote, you can’t predict what an end-user would insert!