Share via


UsbInterface Class

Definition

Provides information about the USB interface including its endpoints, the number of alternate settings the interface supports, and gets the entire descriptor set for those settings. It also obtains pipes associated with the endpoints that the interface supports.

public ref class UsbInterface sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class UsbInterface final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class UsbInterface
Public NotInheritable Class UsbInterface
Inheritance
Object Platform::Object IInspectable UsbInterface
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This code example shows how to parse descriptors and get pipe objects. The example assumes that the app has previously obtained the UsbDevice object.

using Windows.Devices.Usb;
using Windows.Storage.Streams;

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{

    UsbDevice device;
    UInt32 readLen = 8;

    // Get the UsbDevice object. Not shown.

    ...

    UsbInterface myInterface = null;

    //
    // Need to find this descriptor after an interface descriptor:
    //
    //   ===>Class-Specific Video Control Interface Header Descriptor<===
    // bLength:   0x0D
    // bDescriptorType:   0x24
    // bDescriptorSubtype:0x01
    // bcdVDC:  0x0100
    // wTotalLength:    0x00D9  -> Validated
    // dwClockFreq: 0x02DC6C00 = (48000000) Hz
    // bInCollection:     0x01
    // baInterfaceNr[1]:  0x01
    // USB Video Class device: spec version 1.0
    //
    foreach (var interf in device.Configuration.UsbInterfaces)
    {
        foreach (var setting in interf.InterfaceSettings)
        {
            var descriptors = setting.Descriptors;

            // First descriptor in the setting must be the interface descriptor
            if (descriptors.Count >= 2 &&
                UsbInterfaceDescriptor.TryParse(descriptors[0], null) == 
                                            true && 
                                            descriptors[1].Length == 0x0D &&
                                            descriptors[1].DescriptorType == 0x24)
            {
                Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(readLen);
                descriptors[1].readDescriptorBuffer(buffer);
                Windows.Storage.Streams.DataReader reader = Windows.Storage.Streams.DataReader.FromBuffer(buffer);

                reader.ReadByte(); // bLength
                reader.ReadByte(); // bDescriptorType
                byte bDescriptorSubType = reader.ReadByte();

                if (bDescriptorSubType == 0x01) 
                {
                    // This is our interface.
                    myInterface = interf;
                    ushort bcdVDC = reader.ReadUInt16();
                    ushort wTotalLength = reader.ReadUInt16();
                    byte lsb = reader.ReadByte();
                    uint dwClockFreq = (reader.ReadUInt16() << 8) + lsb;
                    byte bInCollection = reader.ReadByte();
                    byte baInterfaceNr1 = reader.ReadByte();

                    await setting.SelectSettingAsync();
                }
                break;
            }
        }

        if (myInterface != null)
        {
            break;
        }
    }

    if (myInterface == null)
    {
        ShowError("Video Control Interface descriptor not found");
        return;
    }

    // Pipes are now available to communicate with endpoints

    UsbInterruptInPipe interruptIn = myInterface.InterruptInPipes[0];
    UsbBulkOutPipe bulkOut = myInterface.BulkOutPipes[0];

}

Properties

BulkInPipes

Gets an array of objects that represent pipes that the host opened to communicate with bulk IN endpoints defined in the current setting of the USB interface setting.

BulkOutPipes

Gets an array of objects that represent pipes that the host opened to communicate with bulk OUT endpoints defined in the current setting of the USB interface.

Descriptors

Gets an array of objects that represent descriptors for all alternate settings that are part of this USB interface.

InterfaceNumber

Gets the interface number that identifies the USB interface. This value is the bInterfaceNumber field of a standard USB interface descriptor.

InterfaceSettings

Gets an array of objects that represent alternate settings defined for the USB interface.

InterruptInPipes

Gets an array of objects that represent pipes that the host opened to communicate with interrupt IN endpoints defined in the current setting of the USB interface.

InterruptOutPipes

Gets an array of objects that represent pipes that the host opened to communicate with interrupt OUT endpoints defined in the current setting of the USB interface.

Applies to