UsbInterface Classe

Definizione

Fornisce informazioni sull'interfaccia USB, inclusi i relativi endpoint, il numero di impostazioni alternative supportate dall'interfaccia e ottiene l'intero descrittore impostato per tali impostazioni. Ottiene anche pipe associate agli endpoint supportati dall'interfaccia.

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
Ereditarietà
Object Platform::Object IInspectable UsbInterface
Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 10 (è stato introdotto in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v1.0)

Esempio

Questo esempio di codice illustra come analizzare i descrittori e ottenere oggetti pipe. L'esempio presuppone che l'app abbia ottenuto in precedenza l'oggetto UsbDevice .

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];

}

Proprietà

BulkInPipes

Ottiene una matrice di oggetti che rappresentano pipe che l'host ha aperto per comunicare con endpoint IN bulk definiti nell'impostazione corrente dell'impostazione dell'interfaccia USB.

BulkOutPipes

Ottiene una matrice di oggetti che rappresentano pipe aperte dall'host per comunicare con endpoint OUT bulk definiti nell'impostazione corrente dell'interfaccia USB.

Descriptors

Ottiene una matrice di oggetti che rappresentano descrittori per tutte le impostazioni alternative che fanno parte di questa interfaccia USB.

InterfaceNumber

Ottiene il numero di interfaccia che identifica l'interfaccia USB. Questo valore è il campo bInterfaceNumber di un descrittore di interfaccia USB standard.

InterfaceSettings

Ottiene una matrice di oggetti che rappresentano impostazioni alternative definite per l'interfaccia USB.

InterruptInPipes

Ottiene una matrice di oggetti che rappresentano pipe aperte dall'host per comunicare con endpoint IN di interruzione definiti nell'impostazione corrente dell'interfaccia USB.

InterruptOutPipes

Ottiene una matrice di oggetti che rappresentano pipe aperte dall'host per comunicare con endpoint OUT di interruzione definiti nell'impostazione corrente dell'interfaccia USB.

Si applica a