コード例 #1
0
        public void GetInterfaceInfo(int interfaceIndex, out USB_INTERFACE_DESCRIPTOR descriptor, out WINUSB_PIPE_INFORMATION[] pipes)
        {
            var  pipeList = new List <WINUSB_PIPE_INFORMATION>();
            bool success  = WinUsb_QueryInterfaceSettings(InterfaceHandle(interfaceIndex), 0, out descriptor);

            if (!success)
            {
                throw APIException.Win32("Failed to get WinUSB device interface descriptor.");
            }

            IntPtr interfaceHandle = InterfaceHandle(interfaceIndex);

            for (byte pipeIdx = 0; pipeIdx < descriptor.bNumEndpoints; pipeIdx++)
            {
                WINUSB_PIPE_INFORMATION pipeInfo;
                success = WinUsb_QueryPipe(interfaceHandle, 0, pipeIdx, out pipeInfo);

                pipeList.Add(pipeInfo);
                if (!success)
                {
                    throw APIException.Win32("Failed to get WinUSB device pipe information.");
                }
            }
            pipes = pipeList.ToArray();
        }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
 private static extern bool WinUsb_QueryInterfaceSettings(IntPtr InterfaceHandle, Byte AlternateInterfaceNumber, out USB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor);