Contains members specific to Microsofts WinUSB driver.
A WinUsbDevice should be thought of as a part of, or an interface of a USB device. The WinUsbDevice class does not have members for selecting configurations and intefaces. This is done at a lower level by the winusb driver depending on which interface the WinUsbDevice belongs to.
Inheritance: UsbDevice, IUsbInterface
コード例 #1
0
ファイル: WinUsbDevice.cs プロジェクト: Bobsson/LibUsbDotNet
        /// <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);
        }
コード例 #2
0
ファイル: WinUsbRegistry.cs プロジェクト: gyuque/CLVShare
        /// <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);
        }
コード例 #3
0
ファイル: WinUsbDevice.cs プロジェクト: Bobsson/LibUsbDotNet
        /// <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);
        }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
ファイル: WinUsbDevice.cs プロジェクト: GSharp-Project/GSharp
        /// <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;
        }
コード例 #6
0
 internal PowerPolicies(WinUsbDevice usbDevice)
 {
     mBufferPtr = Marshal.AllocCoTaskMem(MAX_SIZE);
     mUsbDevice = usbDevice;
 }
コード例 #7
0
 internal PowerPolicies(WinUsbDevice usbDevice)
 {
     mBufferPtr = Marshal.AllocCoTaskMem(MAX_SIZE);
     mUsbDevice = usbDevice;
 }
コード例 #8
-1
ファイル: WinUsbDevice.cs プロジェクト: GSharp-Project/GSharp
        /// <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;
        }