コード例 #1
0
        private static UsbStdSetupPacket GetPartialDescriptorRequest()
        {
            // request 8 bytes initially, to find out the length of the descriptor
            var package = new UsbStdSetupPacket {
                bmRequestType = (byte)(UsbConstants.UsbSetupDataStageIn |
                                       UsbConstants.UsbReqRecipientDevice |
                                       UsbConstants.UsbReqTypeStandard),
                bRequest = 6, // GET_DESCRIPTOR
                wLength  = 8,
                wIndex   = 0,
                wValue   = 1 << 8 // Device
            };

            return(package);
        }
コード例 #2
0
        private string GetStringDescriptor(ushort stringDescriptorIndex)
        {
            var packet = new UsbStdSetupPacket
            {
                bmRequestType = 0x80,
                bRequest      = 6,                                          // GET_DESCRIPTOR
                wValue        = (ushort)((3 << 8) + stringDescriptorIndex), // 3 => STRING
                wIndex        = 0x0409,
                wLength       = 256
            };

            var buffer = _usbControlPipe.ControlTransferIn(packet.bmRequestType, packet.bRequest, packet.wValue, packet.wIndex, packet.wLength);

            // this is required due to an issue in WinUSB.NET 1.0.3;
            // should be fixed in WinUSB.NET 2.0.0
            var realLength = Math.Max(Math.Min(buffer[0], buffer.Length) - 2, 0);

            return(Encoding.Unicode.GetString(buffer, 2, realLength));
        }