LibUsbDotNet/LibUsbDotNet/LibUsb/UsbDevice.DeviceHandle.cs
/// <summary>
/// Retrieve a descriptor from a device.
/// </summary>
/// <param name="descriptorIndex">
/// The index of the descriptor to retieve.
/// </param>
/// <param name="failSilently">
/// <see langword="true"/> to return <see langword="null"/> when the descriptor could not be
/// received; <see langword="false"/> to throw an <see cref="UsbException"/> instead.
/// </param>
/// <returns>
/// The value of the requested descriptor.
/// </returns>
Retrieve a descriptor from a device.
Retrieve a descriptor from a device .
public unsafe string GetStringDescriptor(byte descriptorIndex, bool failSilently = false)
        {
            if (failSilently && !this.IsOpen)
            {
                return null;
            }
            this.EnsureNotDisposed();
            this.EnsureOpen();
            if (descriptorIndex == 0)
            {
                return null;
            }
            byte[] buffer = new byte[1024];
            fixed (byte* ptr = &buffer[0])
            {
                var length = (int)NativeMethods.GetStringDescriptorAscii(this.deviceHandle, descriptorIndex, ptr, buffer.Length);
                if (length < 0)
                {
                    if (failSilently)
                    {
                        return null;
                    }
                    else
                    {
                        ((Error)length).ThrowOnError();
                    }
                }
                return Encoding.ASCII.GetString(buffer, 0, length);
            }
        }
public unsafe string GetStringDescriptor ( byte descriptorIndex , bool failSilently = false ) { if ( failSilently && ! this . IsOpen ) { return null ; } this . EnsureNotDisposed ( ) ; this . EnsureOpen ( ) ; if ( descriptorIndex == 0 ) { return null ; } byte [ ] buffer = new byte [ 1024 ] ; fixed ( byte * ptr = & buffer [ 0 ] ) { var length = ( int ) NativeMethods . GetStringDescriptorAscii ( this . deviceHandle , descriptorIndex , ptr , buffer . Length ) ; if ( length < 0 ) { if ( failSilently ) { return null ; } else { ( ( Error ) length ) . ThrowOnError ( ) ; } } return Encoding . ASCII . GetString ( buffer , 0 , length ) ; } }
Retrieve a descriptor from a device.
Retrieve a descriptor from a device .
The value of the requested descriptor.
The value of the requested descriptor .
descriptorIndex
byte
The index of the descriptor to retieve.
The index of the descriptor to retieve .
failSilently
bool
to return  when the descriptor could not be
received;  to throw an  instead.
to return when the descriptor could not be received ; to throw an instead .