Auto-detecting SD card insertion


N

Noble Bell

Hello all,

Can someone point me in the direction to some c# code for auto-detecting
when a user inserts an sd card into a device?
 
Ad

Advertisements

C

Christopher Fairbairn

Hi,

Noble Bell said:
Can someone point me in the direction to some c# code for auto-detecting
when a user inserts an sd card into a device?

One technique would be to P/Invoke a function called
RequestDeviceNotifications (documented on MSDN at
http://msdn2.microsoft.com/en-us/library/ms919831.aspx).

The OpenNETCF library has a pre-made wrapper around this API within the
OpenNETCF.Net.DeviceStatusMonitor class. See the documentation at
http://www.opennetcf.com/library/sdf/html/07b50991-2568-a408-0be0-75d435285e09.htm

For the first parameter to the DeviceStatusMonitor constructor you might
like to pass in DeviceStatusMonitor.STORE_MOUNT_GUID which will notify you
whenever a new storage device becomes available to the storeage manager.

Here's an example demonstrating the use of this API.

using OpenNETCF.Net;

DeviceStatusMonitor monitor = new
DeviceStatusMonitor(DeviceStatusMonitor.STORE_MOUNT_GUID, false);
monitor.DeviceNotification += new
DeviceNotificationEventHandler(monitor_DeviceNotification);
monitor.StartStatusMonitoring();

void monitor_DeviceNotification(object sender, DeviceNotificationArgs e)
{
MessageBox.Show(e.DeviceName, e.DeviceAttached ? "attached" :
"disconnected");
}

Hope this helps,
Christopher Fairbairn
 
S

Simon Hart [MVP]

I find that API a bit flakey, sometimes it doesn't fire when re-inserting the
card!
 
C

Christopher Fairbairn

Hi,

Simon Hart said:
I find that API a bit flakey, sometimes it doesn't fire when re-inserting
the card!

I haven't personally used the API for SD card detection.

I do however use it to detect the presence of a device being inserted into
our PDA. Our custom device driver written to control the device has the
nesscary settings to advertise itself via this API. It works well in that
scenario.

Thanks,
Christopher Fairbairn.
 
S

Simon Hart [MVP]

Sounds interesting. I tend to find this flakeyness takes place on WM5 devices
pre WM5 are OK. Not tried WM6 much, but we have a whole bunch of new WM6
devices coming in soon so will test those.

This device driver, was it written in unmanaged code?
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com
 
Ad

Advertisements

C

Christopher Fairbairn

Hi,
Sounds interesting. I tend to find this flakeyness takes place on WM5 devices
pre WM5 are OK. Not tried WM6 much

Thanks for that info. It's always good to find out these kinds of
things, as they can suck up a lot of time if you only discover them late
into a debugging session...
This device driver, was it written in unmanaged code?

Yes it's written in C. It's for a custom PCMCIA based camera module we
have developed with medical applications in mind -
http://www.aranzmedical.com/

Thanks,
Christopher Fairbairn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top