c#中windows Ce 6.0上usb的序列号 [英] Serial number of the usb on windows Ce 6.0 in c#

查看:26
本文介绍了c#中windows Ce 6.0上usb的序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取连接到 Windows ce 6.0 设备的 USB 记忆棒的序列号.我尝试使用 KernelIoControl 并且我得到了 window ce 6.0 设备的序列号,但没有连接到它的 USB.

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");
                }
            }
        }

当我将 USB 棒连接到 windows ce 6 设备时,它向我显示了一个新的硬盘识别,我需要注册这个新设备的属性,控制我的 windows ce 6 上可用的 USB 端口设备.

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.

推荐答案

您可能正在寻找的是 USB_DEVICE_DESCRIPTOR.在大窗口中,您将使用 SetupDiGetDeviceProperty 来获取此信息,但在 CE 中,此值仅对驱动程序可用.我认为在 CE 中没有从驱动程序获取此信息的通用方法.不过,您的驱动程序可能包含一个特殊的 IOCTL_ 来获取该信息.联系您的 OEM.

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.

这篇关于c#中windows Ce 6.0上usb的序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆