/// <summary> /// Opens a WinUsb directly from the user supplied device path. /// </summary> /// <param name="devicePath">Device path (symbolic link) of the WinUsb device to open.</param> /// <param name="usbDevice">Returns an opened WinUsb device on success, null on failure.</param> /// <returns>True on success.</returns> public static bool Open(string devicePath, out WinUsbDevice usbDevice) { usbDevice = null; SafeFileHandle sfhDev; bool bSuccess = WinUsbAPI.OpenDevice(out sfhDev, devicePath); if (bSuccess) { SafeWinUsbInterfaceHandle handle = new SafeWinUsbInterfaceHandle(); bSuccess = WinUsbAPI.WinUsb_Initialize(sfhDev, ref handle); if (bSuccess) { usbDevice = new WinUsbDevice(WinUsbApi, sfhDev, handle, devicePath); } else { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open:Initialize", typeof(UsbDevice)); } } else { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "Open", typeof(UsbDevice)); } return(bSuccess); }
/// <summary> /// Opens the USB device for communucation. /// </summary> /// <param name="usbDevice">Returns an opened WinUsb device on success, null on failure.</param> /// <returns>True on success.</returns> public bool Open(out WinUsbDevice usbDevice) { usbDevice = null; if (String.IsNullOrEmpty(SymbolicName)) { return(false); } if (WinUsbDevice.Open(SymbolicName, out usbDevice)) { usbDevice.mUsbRegistry = this; return(true); } return(false); }
/// <summary> /// Gets an interface associated with this <see cref="WinUsbDevice"/>. /// </summary> /// <param name="associatedInterfaceIndex">The index to retrieve. (0 = next interface, 1= interface after next, etc.).</param> /// <param name="usbDevice">A new <see cref="WinUsbDevice"/> class for the specified AssociatedInterfaceIndex.</param> /// <returns>True on success.</returns> public bool GetAssociatedInterface(byte associatedInterfaceIndex, out WinUsbDevice usbDevice) { usbDevice = null; IntPtr pHandle = IntPtr.Zero; bool bSuccess = WinUsbAPI.WinUsb_GetAssociatedInterface(mUsbHandle, associatedInterfaceIndex, ref pHandle); if (bSuccess) { SafeWinUsbInterfaceHandle tempHandle = new SafeWinUsbInterfaceHandle(pHandle); usbDevice = new WinUsbDevice(mUsbApi, null, tempHandle, mDevicePath); } if (!bSuccess) { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "GetAssociatedInterface", this); } return(bSuccess); }
internal PowerPolicies(WinUsbDevice usbDevice) { mBufferPtr = Marshal.AllocCoTaskMem(MAX_SIZE); mUsbDevice = usbDevice; }