internal USBInterface(USBDevice device, int interfaceIndex, API.USB_INTERFACE_DESCRIPTOR rawDesc, USBPipeCollection pipes) { // Set raw class identifiers ClassValue = rawDesc.bInterfaceClass; SubClass = rawDesc.bInterfaceSubClass; Protocol = rawDesc.bInterfaceProtocol; Number = rawDesc.bInterfaceNumber; InterfaceIndex = interfaceIndex; // If interface class is of a known type (USBBaseClass enum), use this // for the InterfaceClass property. BaseClass = USBBaseClass.Unknown; if (Enum.IsDefined(typeof(USBBaseClass), (int)rawDesc.bInterfaceClass)) { BaseClass = (USBBaseClass)(int)rawDesc.bInterfaceClass; } Device = device; Pipes = pipes; // Handle pipes foreach (USBPipe pipe in pipes) { // Attach pipe to this interface pipe.AttachInterface(this); // If first in or out pipe, set InPipe and OutPipe if (pipe.IsIn && InPipe == null) InPipe = pipe; if (pipe.IsOut && OutPipe == null) OutPipe = pipe; } }
private void InitializeInterfaces() { int numInterfaces = _wuDevice.InterfaceCount; List<USBPipe> allPipes = new List<USBPipe>(); USBInterface[] interfaces = new USBInterface[numInterfaces]; // UsbEndpoint for (int i = 0; i < numInterfaces; i++) { API.USB_INTERFACE_DESCRIPTOR descriptor; API.WINUSB_PIPE_INFORMATION[] pipesInfo; _wuDevice.GetInterfaceInfo(i, out descriptor, out pipesInfo); USBPipe[] interfacePipes = new USBPipe[pipesInfo.Length]; for(int k=0;k<pipesInfo.Length;k++) { USBPipe pipe = new USBPipe(this, pipesInfo[k]); interfacePipes[k] = pipe; allPipes.Add(pipe); } // TODO: //if (descriptor.iInterface != 0) // _wuDevice.GetStringDescriptor(descriptor.iInterface); USBPipeCollection pipeCollection = new USBPipeCollection(interfacePipes); interfaces[i] = new USBInterface(this, i, descriptor, pipeCollection); } Pipes = new USBPipeCollection(allPipes.ToArray()); Interfaces = new USBInterfaceCollection(interfaces); }