Serial number of the usb on windows Ce 6.0 in c#

好久不见. 提交于 2019-12-08 11:52:25

问题


I need to get the serial number of a usb stick connected to a windows ce 6.0 device. I tried with KernelIoControl and i get the serial number of the window ce 6.0 device but not the usb connected to it.

    private static string GetDeviceID()
    {
        // Initialize the output buffer to the size of a  
        // Win32 DEVICE_ID structure. 
        byte[] outbuff = new byte[20];
        Int32 dwOutBytes;
        bool done = false;

        Int32 nBuffSize = outbuff.Length;

        // Set DEVICEID.dwSize to size of buffer.  Some platforms look at 
        // this field rather than the nOutBufSize param of KernelIoControl 
        // when determining if the buffer is large enough.
        BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
        dwOutBytes = 0;

        // Loop until the device ID is retrieved or an error occurs. 
        while (!done)
        {
            if (KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero,
                0, outbuff, nBuffSize, ref dwOutBytes))
            {
                done = true;
            }
            else
            {
                int error = Marshal.GetLastWin32Error();
                switch (error)
                {
                    case ERROR_NOT_SUPPORTED:
                        throw new NotSupportedException(
                            "IOCTL_HAL_GET_DEVICEID is not supported on this device",
                            new Win32Exception(error));

                    case ERROR_INSUFFICIENT_BUFFER:

                        // The buffer is not big enough for the data.  The 
                        // required size is in the first 4 bytes of the output 
                        // buffer (DEVICE_ID.dwSize).
                        nBuffSize = BitConverter.ToInt32(outbuff, 0);
                        outbuff = new byte[nBuffSize];

                        // Set DEVICEID.dwSize to size of buffer.  Some 
                        // platforms look at this field rather than the 
                        // nOutBufSize param of KernelIoControl when 
                        // determining if the buffer is large enough.
                        BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
                        break;

                    default:
                        throw new Win32Exception(error, "Unexpected error");
                }
            }
        }

When i connect the usb stick to the windows ce 6 device, it shows me a new hard disk recognize, i need to come to the properties of this new device registered, get control of the usb ports available on my windows ce 6 device.


回答1:


What you're probably looking for is USB_DEVICE_DESCRIPTOR. In big windows, you would use SetupDiGetDeviceProperty to get this information, but in CE this value is only available to the driver. I don't think there is a generic way of getting this information back from the driver in CE. Your driver may contain a special IOCTL_ to get that information, though. Contact your OEM.



来源:https://stackoverflow.com/questions/14360478/serial-number-of-the-usb-on-windows-ce-6-0-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!