Exemplo n.º 1
0
        /// <summary>
        /// Gets a unicode string descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <param name="stringIndex">The index of the string descriptor to get.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static UnicodeString GetUnicodeStringDescriptor(USBDeviceInfo device, byte stringIndex)
        {
#if USB_TRACE
            DBGMSG(((FOS_System.String)"USB: GET_DESCRIPTOR string, endpoint: 0 stringIndex: ") + stringIndex);
#endif

            if (stringIndex == 0)
            {
                return new UnicodeString()
                {
                    StringType = 0,
                    Value = "[NONE]"
                };
            }

            UnicodeString result = new UnicodeString()
            {
                StringType = 0,
                Value = "[Failed to load]"
            };

            //64 byte buffer
            ushort bufferSize = 64;
            StringDescriptorUnicode* buffer = (StringDescriptorUnicode*)FOS_System.Heap.AllocZeroed(bufferSize, "USBManager : GetUnicodeStringDescriptor");

            try
            {
                USBTransfer transfer = new USBTransfer();
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, bufferSize);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 3, stringIndex, 0x0409, bufferSize);
                device.hc.INTransaction(transfer, false, buffer, bufferSize);
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);

                if (transfer.success)
                {
                    result = new UnicodeString()
                    {
                        StringType = buffer->descriptorType,
                        Value = buffer->length > 0 ? FOS_System.ByteConverter.GetASCIIStringFromUTF16((byte*)buffer->widechar, 0, buffer->length) : ""
                    };

#if USB_TRACE
                    ShowUnicodeString(result);
#endif
                }
            }
            finally
            {
                FOS_System.Heap.Free(buffer);
            }

            return result;
        }
Exemplo n.º 2
0
 private static void ShowUnicodeString(UnicodeString str)
 {
     DBGMSG(str.Value);
 }