/// <summary> /// Closes the <see cref="UsbDevice"/> and disposes any <see cref="UsbDevice.ActiveEndpoints"/>. /// </summary> /// <returns>True on success.</returns> public override bool Close() { if (IsOpen) { ReleaseAllInterfaces(); ActiveEndpoints.Clear(); mUsbHandle.Close(); } return(true); }
/// <summary> /// Closes the <see cref="UsbDevice"/> and disposes any <see cref="UsbDevice.ActiveEndpoints"/>. /// </summary> /// <returns>True on success.</returns> public override bool Close() { ActiveEndpoints.Clear(); if (IsOpen) { mUsbHandle.Close(); } return(true); }
/// <summary>Closes the device.</summary> /// <remarks><dl class="cBList"><dt>The <see cref="Close" /> function performs the following actions:</dt> /// <dd>Attempts to safely stop read threads on all <see cref="ActiveEndpoints" />.</dd> /// <dd>Aborts read threads on all <see cref="ActiveEndpoints" /> if they fail to stop gracefully.</dd> /// <dd>Closes and releases the internal device handle.</dd></dl></remarks> public bool Close() { if (mHandle.IsValid) { ActiveEndpoints.Clear(); if (!mHandle.Close()) { UsbGlobals.Error(this, UsbGlobals.LastError, "Close", (int)ErrorCodes.EFAULT); return(false); } } return(true); }
/// <summary> /// Opens an endpoint for reading /// </summary> /// <param name="readEndpointID">Endpoint number for read operations.</param> /// <param name="readBufferSize">Size of the read buffer allocated for the <see cref="UsbEndpointReader.DataReceived"/> event.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointReader"/> class ready for reading. If the specified endpoint is already been opened, the original <see cref="UsbEndpointReader"/> class is returned.</returns> public override UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID, int readBufferSize, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in mActiveEndpoints) { if (activeEndpoint.EpNum == (byte)readEndpointID) { return((UsbEndpointReader)activeEndpoint); } } UsbEndpointReader epNew = new MonoUsbEndpointReader(this, readBufferSize, readEndpointID, endpointType); return((UsbEndpointReader)ActiveEndpoints.Add(epNew)); }
/// <summary> /// Opens an endpoint for reading /// </summary> /// <param name="readEndpointID">Endpoint number for read operations.</param> /// <param name="readBufferSize">Size of the read buffer allocated for the <see cref="UsbEndpointReader.DataReceived"/> event.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointReader"/> class ready for reading. If the specified endpoint is already been opened, the original <see cref="UsbEndpointReader"/> class is returned.</returns> public override UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID, int readBufferSize, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in mActiveEndpoints) { if (activeEndpoint.EpNum == (byte)readEndpointID) { return((UsbEndpointReader)activeEndpoint); } } byte altIntefaceID = mClaimedInterfaces.Count == 0 ? UsbAltInterfaceSettings[0] : UsbAltInterfaceSettings[mClaimedInterfaces[mClaimedInterfaces.Count - 1]]; UsbEndpointReader epNew = new MonoUsbEndpointReader(this, readBufferSize, altIntefaceID, readEndpointID, endpointType); return((UsbEndpointReader)ActiveEndpoints.Add(epNew)); }
/// <summary> /// Closes the <see cref="UsbDevice"/> and disposes any <see cref="UsbDevice.ActiveEndpoints"/>. /// </summary> /// <returns>True on success.</returns> public override bool Close() { if (IsOpen) { ActiveEndpoints.Clear(); mUsbHandle.Close(); if (mSafeDevHandle != null) { if (!mSafeDevHandle.IsClosed) { mSafeDevHandle.Close(); } } } return(true); }
/// <summary> /// Sends a usb device reset command. /// </summary> /// <remarks> /// After calling <see cref="ResetDevice"/>, the <see cref="LibUsbDevice"/> instance is disposed and /// no longer usable. A new <see cref="LibUsbDevice"/> instance must be obtained from the device list. /// </remarks> /// <returns>True on success.</returns> public bool ResetDevice() { bool bSuccess; if (!IsOpen) { throw new UsbException(this, "Device is not opened."); } ActiveEndpoints.Clear(); if ((bSuccess = LibUsbApi.ResetDevice(mUsbHandle)) != true) { UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "ResetDevice Failed", this); } else { Close(); } return(bSuccess); }
/// <summary> /// Sends a usb device reset command. /// </summary> /// <remarks> /// After calling <see cref="ResetDevice"/>, the <see cref="MonoUsbDevice"/> instance is disposed and /// no longer usable. A new <see cref="MonoUsbDevice"/> instance must be obtained from the device list. /// </remarks> /// <returns>True on success.</returns> public bool ResetDevice() { int ret; if (!IsOpen) { throw new UsbException(this, "Device is not opened."); } ActiveEndpoints.Clear(); if ((ret = MonoUsbApi.ResetDevice((MonoUsbDeviceHandle)mUsbHandle)) != 0) { UsbError.Error(ErrorCode.MonoApiError, ret, "ResetDevice Failed", this); } else { Close(); } return(ret == 0); }