public void Close() { epReader?.Dispose(); epReader = null; epWriter?.Dispose(); epWriter = null; device?.Close(); device = null; }
public void Dispose() { if (OscillDevice != null) { OscillDevice.Close(); } if (writer != null) { writer.Dispose(); } if (reader != null) { reader.Dispose(); } OscillDevice = null; }
public void Dispose() { lock (locker) { if (_pinDmd2Device != null && _pinDmd2Device.IsOpen) { var wholeUsbDevice = _pinDmd2Device as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.ReleaseInterface(0); } _pinDmd2Device.Close(); } _pinDmd2Device = null; UsbDevice.Exit(); } }
public override void Close() { if (_device != null && _device.IsOpen) { IUsbDevice wholeUsbDevice = _device as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface #0. wholeUsbDevice.ReleaseInterface(0); } _device.Close(); } base.Close(); }
//--------------------------------------------------------------------------------- private void timer1_Tick(object sender, EventArgs e) { label1.Text = "Current Time:" + DateTime.Now.ToString("HH:mm:ss"); dev = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x1234, 0x6789)); if (dev == null) { for (int i = 0; i < 8; i++) { R(i).BackStyle = BackStyle.Transparent; G(i).BackStyle = BackStyle.Transparent; } if (btn == 3) { this.Close(); } } else { ShowG(0); ShowR(0); Usbout(dev, 0, 0); Usbout(dev, 0, 0x10); if (btn == 1 && cnt < green.Length) { ShowG(green[cnt]); Usbout(dev, green[cnt], 0); cnt++; } else if (btn == 2 && cnt < 8) { int n = (int)Math.Pow(2, cnt); ShowR(n); Usbout(dev, (byte)n, 0x20); Usbout(dev, (byte)n, 0x30); cnt++; } else if (btn == 3) { dev.Close(); this.Close(); } } }
public void Close() { this.Dispose(); if (myUsbDevice != null) { if (myUsbDevice.DriverMode == UsbDevice.DriverModeType.MonoLibUsb) { try { myUsbDevice.Close(); } catch { } } myUsbDevice = null; } }
public void Close() { if (device != null) { device.Close(); } device = null; if (epReader != null) { epReader.Dispose(); } epReader = null; if (epWriter != null) { epWriter.Dispose(); } epWriter = null; }
public void Close() { if (_device != null) { if (_device.IsOpen) { IUsbDevice whole = _device as IUsbDevice; if (!ReferenceEquals(whole, null)) { whole.ReleaseInterface(1); } _device.Close(); UsbDevice.Exit(); } } }
public static void PrintUsbInfo() { UsbDevice usbDevice = null; UsbRegDeviceList allDevices = UsbDevice.AllDevices; Console.WriteLine("Found {0} devices", allDevices.Count); foreach (UsbRegistry usbRegistry in allDevices) { Console.WriteLine("Got device: {0}\r\n", usbRegistry.FullName); if (usbRegistry.Open(out usbDevice)) { Console.WriteLine("Device Information\r\n------------------"); Console.WriteLine("{0}", usbDevice.Info.ToString()); Console.WriteLine("VID & PID: {0} {1}", usbDevice.Info.Descriptor.VendorID, usbDevice.Info.Descriptor.ProductID); Console.WriteLine("\r\nDevice configuration\r\n--------------------"); foreach (UsbConfigInfo usbConfigInfo in usbDevice.Configs) { Console.WriteLine("{0}", usbConfigInfo.ToString()); Console.WriteLine("\r\nDevice interface list\r\n---------------------"); ReadOnlyCollection <UsbInterfaceInfo> interfaceList = usbConfigInfo.InterfaceInfoList; foreach (UsbInterfaceInfo usbInterfaceInfo in interfaceList) { Console.WriteLine("{0}", usbInterfaceInfo.ToString()); Console.WriteLine("\r\nDevice endpoint list\r\n--------------------"); ReadOnlyCollection <UsbEndpointInfo> endpointList = usbInterfaceInfo.EndpointInfoList; foreach (UsbEndpointInfo usbEndpointInfo in endpointList) { Console.WriteLine("{0}", usbEndpointInfo.ToString()); } } } usbDevice.Close(); } Console.WriteLine("\r\n----- Device information finished -----\r\n"); } }
public void Run(Stream output) { StreamWriter sw = new StreamWriter(output); sw.WriteLine("--- Test_usb_strerror Test ---"); UsbDevice testDevice = PicTestDevice.TestDevice; if (testDevice != null) { int ret; ret = testDevice.SetConfiguration(1); Debug.Assert(ret == 0); sw.WriteLine("SetConfiguration(1):" + ret); ret = testDevice.ClaimInterface(0); Debug.Assert(ret == 0); sw.WriteLine("ClaimInterface(0):" + ret); ret = testDevice.SetConfiguration(0); Debug.Assert(ret == (int)ErrorCodes.EINVAL); sw.WriteLine("SetConfiguration(0):" + ret); sw.WriteLine("LastError:" + UsbGlobals.LastError); ret = testDevice.ReleaseInterface(0); Debug.Assert(ret == 0); sw.WriteLine("ReleaseInterface(0):" + ret); ret = testDevice.SetConfiguration(0); Debug.Assert(ret == 0); sw.WriteLine("SetConfiguration(0):" + ret); testDevice.Close(); sw.WriteLine("SUCCESS!"); } else { sw.WriteLine("Failed opening device."); } sw.WriteLine("------------------------------"); sw.Flush(); }
/// <summary> /// Close the hardware interface. /// </summary> public void Close() { this.Dispose(); if (myUsbDevice != null) { if (myUsbDevice.DriverMode == UsbDevice.DriverModeType.MonoLibUsb) { try { myUsbDevice.Close(); } catch (Exception e) { XTenManager.logger.Error(e); } } myUsbDevice = null; } }
public void GutenTAGClose() { if (reader != null) { reader.Dispose(); } if (writer != null) { writer.Dispose(); } if (MyUsbDevice != null) { if (MyUsbDevice.IsOpen) { MyUsbDevice.Close(); } } isOpen = false; }
protected override void Dispose(bool disposing) { if (device != null && device.IsOpen) { reader.DataReceivedEnabled = false; reader.DataReceived -= HandleDataReceived; var usbDevice = device as IUsbDevice; if (usbDevice != null) { usbDevice.ReleaseInterface(deviceInterfaceId); } device.Close(); device = null; } base.Dispose(disposing); }
// Build up device name from manufacturer, product name, and // serial number strings. The index of each of these strings // is in a fixed location in the device descriptor. Then add // the device to the list box. void GetDeviceName(UsbDevice dev) { byte[] arbBuf; string strTag; try { dev.Open(); // Get device descriptor // bmRequestType = 0 - standard device request // bRequest = 6 - Get_Descriptor // wValue: high byte = 1 - device; low byte = 0 - descriptor index // wIndex = 0 - not used // wLength = 18 - length of descriptor arbBuf = dev.ControlRead(0, 6, 0x100, 0, 18); // Entries 14, 15, and 16 have the index of the manufacturer, // product name, and serial number string descriptors, respectively. strTag = GetStringDescriptor(dev, arbBuf[14]); strTag += '/'; strTag += GetStringDescriptor(dev, arbBuf[15]); strTag += '/'; strTag += GetStringDescriptor(dev, arbBuf[16]); // Assign the combined ID string to the Tag. dev.Tag = strTag; } catch (Exception exc) { dev.Tag = "Can't open: " + exc.Message; } dev.Close(); // done for now // Use the Tag as the value to be returned by ToString(). // This makes it easy to add the UsbDevice to a list box. dev.GetMyString = delegate(UsbDevice device) { return((string)device.Tag); }; // The list box will display ToString(), which is now the Tag. lstDevices.Items.Add(dev); }
//-------------------------------------------------------------------------------------------------------- public static void Close() { if (USBDev != null) { if (USBDev.IsOpen) { IUsbDevice wholeUsbDevice = USBDev as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.ReleaseInterface(0); } USBDev.Close(); } USBDev = null; UsbDevice.Exit(); } }
private void closeTestDevice() { if (!ReferenceEquals(usb, null)) { if (usb.IsOpen) { mEP1Reader.DataReceived -= mBulkInOut_DataReceived; stopReadWrite(); mEP1Reader.Dispose(); mEP1Writer.Dispose(); usb.ReleaseInterface(0); usb.SetConfiguration(0); usb.ActiveEndpoints.Clear(); usb.Close(); } usb = null; mEP1Reader = null; mEP1Writer = null; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (device != null && device.IsOpen) { IUsbDevice wholeUsbDevice = device as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.ReleaseInterface(interfaceId); } device.Close(); } } disposedValue = true; } }
/// <summary> /// Frees all USB resources /// </summary> public void Dispose() { if (coordinatorUsb != null) { if (coordinatorUsb.IsOpen) { IUsbDevice wholeUsbDevice = coordinatorUsb as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface #0. wholeUsbDevice.ReleaseInterface(0); } coordinatorUsb.Close(); } coordinatorUsb = null; // Free USB resources UsbDevice.Exit(); } }
private void OnDevNotify(object sender, DeviceNotifyEventArgs e) { if (e.Device.IdProduct == ClearShotDevice.ProductId && e.Device.IdVendor == ClearShotDevice.VendorId) { if (e.EventType == EventType.DeviceArrival) { //Set and raise event. _targetDevice = UsbDevice.OpenUsbDevice(x => x.Pid == ClearShotDevice.ProductId && x.Vid == ClearShotDevice.VendorId); OnConnected(this, EventArgs.Empty); } else if (e.EventType == EventType.DeviceRemoveComplete) { if (_targetDevice != null) { _targetDevice.Close(); _targetDevice = null; } OnDisconnected(this, EventArgs.Empty); } } }
/// <summary> /// Close the hardware interface. /// </summary> public void Close() { if (myUsbDevice == null) { return; } if (myUsbDevice.DriverMode == UsbDevice.DriverModeType.MonoLibUsb) { try { myUsbDevice.Close(); } catch (Exception e) { XTenManager.logger.Error(e); } } myUsbDevice = null; UsbDevice.Exit(); Dispose(); }
private static void ReleaseResourcesIfRequired() { if (MyUsbDevice != null) { if (MyUsbDevice.IsOpen) { _orb.TurnLightningOff(); IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface wholeUsbDevice.ReleaseInterface(1); } MyUsbDevice.Close(); } MyUsbDevice = null; // Free usb resources UsbDevice.Exit(); } }
public static void CloseUSBDevice() { if (_usbDevice != null) { if (_usbDevice.IsOpen) { IUsbDevice wholeUsbDevice = _usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Close the USB interface if we still have it open. wholeUsbDevice.ReleaseInterface(0); Console.WriteLine(Strings.INFO_INTERFACERELEASE); } // Close the USB device _usbDevice.Close(); } _usbDevice = null; UsbDevice.Exit(); } }
private void Usb_exit() { reader.DataReceivedEnabled = false; reader.DataReceived -= (OnRxEndPointData); this.EndInvoke(ketthuc); reader.Dispose(); writer.Dispose(); if (myUsbDevice != null) { if (myUsbDevice.IsOpen) { IUsbDevice wholeUsbDevice = myUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.ReleaseInterface(0); } myUsbDevice.Close(); } myUsbDevice = null; UsbDevice.Exit(); } }
public static void Close() { if (usbDevice == null) { return; } RefreshThreadWanted = false; while (RefreshThreadRunning) { Thread.Sleep(40); } Thread.Sleep(40); WriteText("Goodbye"); RefreshDisplayAsync().Wait(); Thread.Sleep(200); usbDevice.Close(); usbDevice.Dispose(); usbDevice = null; }
private void DeviceDisconnect() { if (inUsingDevice != null && inUsingDevice.IsOpen) { EndpointReader.DataReceivedEnabled = false; EndpointReader.DataReceived -= (OnRxEndPointData); IUsbDevice wholeUsbDevice = inUsingDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface #0. wholeUsbDevice.ReleaseInterface(0); } inUsingDevice.Close(); } EndpointWriter = null; EndpointReader = null; inUsingDevice = null; // Update controls lb_status.Text = "未连接"; lb_status.ForeColor = Color.Red; }
private void disconnect() { if (MyUsbDevice != null) { if (MyUsbDevice.IsOpen) { // If this is a "whole" usb device (libusb-win32, linux libusb-1.0) // it exposes an IUsbDevice interface. If not (WinUSB) the // 'wholeUsbDevice' variable will be null indicating this is // an interface of a device; it does not require or support // configuration and interface selection. IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // Release interface #0. wholeUsbDevice.ReleaseInterface(0); } MyUsbDevice.Close(); } MyUsbDevice = null; } }
public override void Close() { if (thread != null) { thread.Abort(); thread = null; } if (usbDevice != null) { if (usbDevice.IsOpen) { IUsbDevice wholeUsbDevice = usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.ReleaseInterface(0); } usbDevice.Close(); } usbDevice = null; UsbDevice.Exit(); } }
/// <summary> /// 断开连接调用 /// </summary> private void disconnected() { pl_conn.Enabled = true; pl_main.Enabled = false; if (captureForm != null) { captureForm.Close(); captureForm = null; } if (thread != null && thread.IsAlive) { thread.Abort(); } writer = null; usbcmd = null; btn_connect.Text = "连接设备"; btn_capture.Text = "开始窗口捕捉"; if (inUsingDevce != null) { inUsingDevce.Close(); inUsingDevce = null; } }
private void closeDevice() { if (mDev != null) { if (mEpReader != null) { mEpReader.DataReceivedEnabled = false; mEpReader.DataReceived -= mEp_DataReceived; mEpReader.Dispose(); mEpReader = null; } if (mEpWriter != null) { mEpWriter.Dispose(); mEpWriter = null; } mDev.ReleaseInterface(0); mDev.SetConfiguration(0); mDev.Close(); mDev = null; } panTransfer.Enabled = false; }
public void Dispose() { try { if (aliveTimer != null) { aliveTimer.Change(Timeout.Infinite, Timeout.Infinite); } } catch { } try { reader.Dispose(); writer.Dispose(); } catch { } try { controlDevice.Close(); } catch { } try { sensorDevice.Close(); } catch { } controlDevice = null; SensorDataUpdate = null; Removed = null; INReport = null; }