How to detect Windows Mobile 5 Device Serial Numbe

2019-06-14 04:30发布

问题:

We have several devices where I work (mostly Datalogic 4420 Falcon), and someone is always leaving one off the base. The battery runs dry, then they bring them back to get setup all over. (There's supposed to be a way to configure a file on the SD card to reload upon such an error, but it doesn't work very well)

When someone saves changes on the device (using my app that writes data to the SQL Server), the Serial Number is sent along with it so we can track what devices are in use where.

Each device has a Serial Number, and I have to physically (i.e. manually) write that into the Device name field, which I can read. Working code here if anyone wants to know how:

static string deviceId = null;

public static string DeviceName {
  get {
    if (String.IsNullOrEmpty(deviceId)) {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Ident", true)) {
        try {
          deviceId = key.GetValue("Name", "[Unnamed]").ToString();
        } catch (Exception e) {
          ErrorWrapper("GetDeviceName", e);
          deviceId = Dns.GetHostName();
        } finally {
          key.Flush();
          key.Close();
        }
      }
    }
    return deviceId;
  }
}

I do not like the manual (i.e. Fat Finger prone) Serial Number entry. Is there some call to query the device's Serial Number, or is that vendor specific?

Datamax does make an SDK that is specific to their devices, but we don't want our applications tied down to any one manufacturer (we are already tied down to VS2008).

回答1:

I'd start by trying to P/Invoke to get the device ID (KerneIoControl with IOCTL_HAL_GET_DEVICEID) and see if it matches the serial number you're after. Here's an example.



回答2:

I don't know about your Datalogic 4420 Falcon device, but I work with Intermec CK30 & CK60 and I have their itc50.dll file. Here is snippet:

[DllImport("itc50.dll")]public static extern int ITCGetSerialNumber(StringBuilder Snumber, int buffSize);

StringBuilder hwSN = new StringBuilder(12);

if (ITCGetSerialNumber(hwSN, hwSN.Capacity) >= 0)
{
    ;
    ;
}