Ejemplo n.º 1
0
        /// <summary>
        /// gets a list of devices
        /// </summary>
        /// <returns></returns>
        protected static List <DeviceListItem> getDeviceList(Guid deviceInterfaceGuid)
        {
            IntPtr deviceListHandle = Winusb.listCreate(deviceInterfaceGuid);

            try
            {
                UInt32 deviceListSize = Winusb.listSize(deviceListHandle);

                var deviceList = new List <DeviceListItem>();

                for (Byte i = 0; i < deviceListSize; i++)
                {
                    // Get all the needed info in an effecient way.  This is more efficient than
                    // using listGetSerialNumber and listGetProductId because we only need to
                    // get the device instance once instead of 3 times.
                    Int32  deviceInstance = Winusb.listGetDeviceInstance(deviceListHandle, i);
                    String serialNumber   = Winusb.getSerialNumber(deviceInstance);
                    UInt16 productId      = Winusb.getProductID(deviceInstance);

                    DeviceListItem item = new DeviceListItem(deviceInstance,
                                                             deviceInterfaceGuid,
                                                             "#" + serialNumber,
                                                             serialNumber,
                                                             productId);
                    deviceList.Add(item);
                }
                return(deviceList);
            }
            finally
            {
                Winusb.listDestroy(deviceListHandle);
            }
        }