26 November 2008

SD Card - Read CID/Serial number - Musings

Well I discovered that my .Net app does actually work on 32 bit operating systems too. Assuming I'm reading the data correctly, I can read CIDs in XP SP2, on an old Asus W5 laptop. It also has an integral card reader. BUT: it didn't work at first. DeviceIOControl returned "Invalid Function" (Win32 Error code 1). I went in to device manager and changed the driver over:




So, It looks like the driver plays an important role too...

So to read the CID, so far I've found:

1) You can't get it if the reader is a USB device. 2) You can't get it if the driver doesn't like the DeviceIOControl call.

CreateFile path for the Volume:

There are 2 choices mentioned on forums/in documentation. "//./X:" or "//./PhysicalDriveX". There's another one with a guid too.

I've been using "//./X:" as it worked. Maybe using the other path to get the handle will make a difference on the machine where I can't get it to work:

C:\Users\SEP>wmic diskdrive get name,size,model Model Name Size FUJITSU MHW2160BJ G2 \\.\PHYSICALDRIVE0 160039272960 SD Memory Card \\.\PHYSICALDRIVE1 8225280

Edit: I'm now on about version 5 of my program and I'm using C#! So, I've moved from C++/CLI -> VB.Net -> C#... It now works on the machine I mentioned above, and I'm using the physicaldrive string. I'm trying to get Overlapped to work on x64 and x32, it seems there are some problems with NativeOverlapped. This will allow the call to read the CID and CSD to run on another thread, and the user to be notified when the results come back. (Reading the CID takes a noticable amount of time.) It requires a pointer, hence the move to C#.


  1. I have implemented the sdcard id reading in C++, and then I have implemented in C# based in your code. However I'm experiencing some problems to achieve that because I'm always getting "Request not supported" when I make the IOCTL call...

    Have you any ideia about how to solve this issue?

  2. Where do you download the Microsoft driver for the reader, I seem to have the same problem for the driver so I would like to try to change the driver for the Ricoh reader..


  3. This comment has been removed by the author.

  4. On Windows 7:
    Go to Ricoh driver properties (double click on it in the Device Manager). In the properties window:
    Driver -> Update Driver -> Browse my computer for driver software -> Let me pick from a list of device drivers on my computer
    Select there "SDA Standard Compliant SD Host Controller", then "Next" etc.

  5. This comment has been removed by the author.

  6. It worked on my Windows 7 64-bit computer having a Ricoh SD card reader built in. I downloaded and extracted ReadCID.exe, followed the steps given in this page, then opened a DOS prompt text window. I set the path where ReadCID.exe resides using CD (change directory) command. The Ricoh SD card reader is assigned drive letter 'G' so I typed this in the command prompt:
    ReadCID //./G:
    then I hit the Enter key. A new text window pops up with the results contained in it. Special thanks to jo0ls and Gogelf.