How can I read SD card ID or similar information?

C

chrkon

Hello everybody,
our software (c# on .CF) must handle different sd cards. So I need a SD card
specific information to identify a SD card.

My first idea was to use "IOCTL_STORAGE_GET_DEVICEID" via P/Invoke
(DeviceIoControl).
This works fine on a Windows Mobile 5 Hardware (Archer, Juniper Systems).
Unfortunatedly our customers have still older handheld hardware (Panasonic
CF-P1 with Pocket PC 2002). On these devices calling the DeviceIoControl
funktion with the "... _GET_DEVICEID" parameter fails with SD cards (Error
0x57 - wrong parameter). On the same system the function will work with
CF-Cards. So I assume, that this is an issue of the device. But I have no
chance to get a patch from Panasonic for this (old device).

So I have to find an other way to identify the different SD cards.
(I don't want to create additional files, because it would be possible to
exchange these files manually between the cards.)

My second idea was to use the Volume ID of the SD Card. Most SD Cards use
the FAT Filesystem. And this filesystem has an ID. You can see it if you call
the "dir" command on the comand shell. This information will be changed if
the SD card is formatted, but for our needs it is OK.
On the desktop PC there is the API call "GetVolumeInformation" which deliver
this information. But I have not found something like this for mobile
systems.

Does anybody know how I can read this ID?
A different way to get a "SD card specific ID" would fine, too.

Kind regards,
Christof Konstantinopoulos

(Dortmund, Germany)
 
D

davidknechtges

Hello everybody,
our software (c# on .CF) must handle different sd cards. So I need a SD card
specific information to identify a SD card.

My first idea was to use "IOCTL_STORAGE_GET_DEVICEID" via P/Invoke
(DeviceIoControl).
This works fine on a Windows Mobile 5 Hardware (Archer, Juniper Systems).
Unfortunatedly our customers have still older handheld hardware (Panasonic
CF-P1 with Pocket PC 2002). On these devices calling the DeviceIoControl
funktion with the "... _GET_DEVICEID" parameter fails with SD cards (Error
0x57 - wrong parameter). On the same system the function will work with
CF-Cards. So I assume, that this is an issue of the device. But I have no
chance to get a patch from Panasonic for this (old device).

So I have to find an other way to identify the different SD cards.
(I don't want to create additional files, because it would be possible to
exchange these files manually between the cards.)

My second idea was to use the Volume ID of the SD Card. Most SD Cards use
the FAT Filesystem. And this filesystem has an ID. You can see it if you call
the "dir" command on the comand shell. This information will be changed if
the SD card is formatted, but for our needs it is OK.
On the desktop PC there is the API call "GetVolumeInformation" which deliver
this information. But I have not found something like this for mobile
systems.

Does anybody know how I can read this ID?
A different way to get a "SD card specific ID" would fine, too.

Kind regards,
Christof Konstantinopoulos

(Dortmund, Germany)

How about the API GetStoreInfo? You can get the device name and store
name from that.

Would that work?

David
 
C

chrkon

Hello David,

many thanks for your reply.
I didn't know anything about the GetStore API before. So I have take a look
to the MSDN description. Unfortunatedly you only get the Names. I assume,
that both informations are equal if you use two SD Cards from one vendor.

But I have not tested it. To use P/Invoke I have to implement the signature
of this function, but I don't know in which .dll I will find this GetStore /
OpenStore function.

Kind regards,

Christof



davidknechtges said:
Hello everybody,
our software (c# on .CF) must handle different sd cards. So I need a SD card
specific information to identify a SD card.

[... removed by chrkon (repost should be short) ...]

Does anybody know how I can read this ID?
A different way to get a "SD card specific ID" would fine, too.

Kind regards,
Christof Konstantinopoulos

(Dortmund, Germany)

How about the API GetStoreInfo? You can get the device name and store
name from that.

Would that work?

David
 
C

chrkon

Hello David,

many thanks for your reply. Until now I have not heard anything about this
GetStoreInfo API. So I take a look into the MSDN.
As you wrote, you get back the device name and the store name, but I assume,
that I will receive equal values if I use two different SD cards from the
same vendor. So this way is no solution for me.

I have not tested this function, because I don't know in which .dll I will
find it. To use P/Invoke I have to know this.

Kind regards,
Christof


[... some parts removed by chrkon, reply should be small :) ... ]
 
D

davidknechtges

Hello David,

many thanks for your reply.
I didn't know anything about the GetStore API before. So I have take a look
to the MSDN description. Unfortunatedly you only get the Names. I assume,
that both informations are equal if you use two SD Cards from one vendor.

But I have not tested it. To use P/Invoke I have to implement the signature
of this function, but I don't know in which .dll I will find this GetStore /
OpenStore function.

Kind regards,

Christof

davidknechtges said:
Hello everybody,
our software (c# on .CF) must handle different sd cards. So I need a SD card
specific information to identify a SD card.
[... removed by chrkon (repost should be short) ...]
Does anybody know how I can read this ID?
A different way to get a "SD card specific ID" would fine, too.
Kind regards,
Christof Konstantinopoulos
(Dortmund, Germany)
How about the API GetStoreInfo? You can get the device name and store
name from that.
Would that work?

It looks like it is in coredll. However, a warning about using this
API..... The Compact Framework does not support custom marshaling of
structures like the desktop framework does. This means that you would
have to marshal the structure in, and then get the pieces yourself,
writing custom marshaling code. This custom marshaling, however, may
not be necessary for the szDeviceName and szStoreName items that you
would be interested in. You would just have to try it.

If it is needed, instead of pinvoking this API directly, I would write
a native wrapper DLL that exports the pieces that you want, and then
pinvoke that. So, the wrapper DLL might have a method called
GetDeviceName, which returns a TCHAR *. Then you would pinvoke that
from C#. This would get rid of the need to write the custom marshaling
code, which is very tricky.

If you want to see how difficult the custom marshaling really is, take
a look at the OpenNETCF library under reflector and look at the
OpenNETCF.Net.NetworkInformation.NetworkInterface class. Open the
GetAdapterInfo method and look at the byte manipulation that is done
to get the data out of this structure.

David
 
C

chrkon

Hello Davis,

many thanks for your hints. I was out for some days, so my answer is late,
but I will check this ASAP. I think the OpenNETCF framework is a great piece
of work. I will take a look into it.

Kind regards,

Christof


davidknechtges said:
Hello David,

many thanks for your reply.
I didn't know anything about the GetStore API before. So I have take a look
to the MSDN description. Unfortunatedly you only get the Names. I assume,
that both informations are equal if you use two SD Cards from one vendor.

But I have not tested it. To use P/Invoke I have to implement the signature
of this function, but I don't know in which .dll I will find this GetStore /
OpenStore function.

Kind regards,

Christof

davidknechtges said:
Hello everybody,
our software (c# on .CF) must handle different sd cards. So I need a SD card
specific information to identify a SD card.
[... removed by chrkon (repost should be short) ...]
Does anybody know how I can read this ID?
A different way to get a "SD card specific ID" would fine, too.
Kind regards,
Christof Konstantinopoulos
(Dortmund, Germany)
How about the API GetStoreInfo? You can get the device name and store
name from that.
Would that work?

It looks like it is in coredll. However, a warning about using this
API..... The Compact Framework does not support custom marshaling of
structures like the desktop framework does. This means that you would
have to marshal the structure in, and then get the pieces yourself,
writing custom marshaling code. This custom marshaling, however, may
not be necessary for the szDeviceName and szStoreName items that you
would be interested in. You would just have to try it.

If it is needed, instead of pinvoking this API directly, I would write
a native wrapper DLL that exports the pieces that you want, and then
pinvoke that. So, the wrapper DLL might have a method called
GetDeviceName, which returns a TCHAR *. Then you would pinvoke that
from C#. This would get rid of the need to write the custom marshaling
code, which is very tricky.

If you want to see how difficult the custom marshaling really is, take
a look at the OpenNETCF library under reflector and look at the
OpenNETCF.Net.NetworkInformation.NetworkInterface class. Open the
GetAdapterInfo method and look at the byte manipulation that is done
to get the data out of this structure.

David
 
C

chrkon

Hello Simon,

thank you for this hint! I will check it out.

Kind regards,
Christof
 

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