Exemple #1
0
        internal UsbDevice(WDU_DEVICE_HANDLE hDev, ref WDU_DEVICE pDeviceInfo)
        {
            WDU_CONFIGURATION pConfig = (WDU_CONFIGURATION)Marshal.PtrToStructure(pDeviceInfo.pActiveConfig,
                                                                                  typeof(WDU_CONFIGURATION));

            dwNumOfInterfaces = pConfig.dwNumInterfaces;
            interfacesInfo    = new INTERFACE_INFO[dwNumOfInterfaces];
            hDevice           = hDev;

            for (uint i = 0; i < dwNumOfInterfaces; ++i)
            {
                interfacesInfo[i].wduInterface = (WDU_INTERFACE)Marshal.PtrToStructure(
                    pDeviceInfo.pActiveInterface(i), typeof(WDU_INTERFACE));
                WDU_ALTERNATE_SETTING pAltSetting = (WDU_ALTERNATE_SETTING)Marshal.PtrToStructure(
                    interfacesInfo[i].wduInterface.pActiveAltSetting, typeof(WDU_ALTERNATE_SETTING));

                if (i == 0)
                {
                    dwInterfaceNum  = pAltSetting.Descriptor.bInterfaceNumber;
                    dwAltSettingNum = pAltSetting.Descriptor.bAlternateSetting;
                    pPipesList      = new PipeList(pDeviceInfo.Pipe0, pAltSetting, hDevice);
                }

                interfacesInfo[i].bInterfaceNumber = pAltSetting.Descriptor.bInterfaceNumber;

                dwNumOfAltSettingsTotal += interfacesInfo[i].wduInterface.dwNumAltSettings;
            }

            DWORD dwStatus = wdu_lib_decl.WDU_GetDeviceAddr(hDevice,
                                                            ref dwAddr);

            wVid = (WORD)pDeviceInfo.Descriptor.idVendor;
            wPid = (WORD)pDeviceInfo.Descriptor.idProduct;
        }
Exemple #2
0
        public DWORD ChangeAlternateSetting(DWORD newInterface, DWORD newSetting)
        {
            DWORD dwStatus = (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS;

            // if the chosen setting is the same as it was - do nothing
            if (newInterface == this.dwInterfaceNum && newSetting == this.dwAltSettingNum)
            {
                return(dwStatus);
            }

            dwStatus = wdu_lib_decl.WDU_SetInterface(hDevice, newInterface,
                                                     newSetting);
            if (dwStatus != (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS)
            {
                return(dwStatus);
            }

            IntPtr ppDeviceInfo = (System.IntPtr) 0;

            dwStatus = (DWORD)wdu_lib_decl.WDU_GetDeviceInfo(hDevice,
                                                             ref ppDeviceInfo);
            if (dwStatus != (DWORD)WD_ERROR_CODES.WD_STATUS_SUCCESS)
            {
                return(dwStatus);
            }

            WDU_DEVICE pDeviceInfo = (WDU_DEVICE)Marshal.PtrToStructure(ppDeviceInfo,
                                                                        typeof(WDU_DEVICE));

            int index = GetInterfaceIndexByNumber(newInterface);

            interfacesInfo[index].wduInterface = (WDU_INTERFACE)Marshal.PtrToStructure(
                pDeviceInfo.pActiveInterface((uint)index), typeof(WDU_INTERFACE));

            WDU_ALTERNATE_SETTING pActiveAltSetting =
                (WDU_ALTERNATE_SETTING)Marshal.PtrToStructure(interfacesInfo[index].
                                                              wduInterface.pActiveAltSetting, typeof(WDU_ALTERNATE_SETTING));

            dwInterfaceNum  = newInterface;
            dwAltSettingNum = newSetting;
            pPipesList      = new PipeList(((UsbPipe)(pPipesList[0])).GetPipeInfo(),
                                           pActiveAltSetting, hDevice);
            wdu_lib_decl.WDU_PutDeviceInfo(ppDeviceInfo);

            return(dwStatus);
        }