/// <summary> /// Class constructor for the traq|paq /// </summary> public TraqpaqDevice() { // find the device traqpaqDeviceFinder = new UsbDeviceFinder(Constants.VID, Constants.PID); // open the device this.MyUSBDevice = UsbDevice.OpenUsbDevice(traqpaqDeviceFinder); // If the device is open and ready if (MyUSBDevice == null) throw new TraqPaqNotConnectedException("Device not found"); this.reader = MyUSBDevice.OpenEndpointReader(ReadEndpointID.Ep01); this.writer = MyUSBDevice.OpenEndpointWriter(WriteEndpointID.Ep02); // create the battery object this.battery = new Battery(this); // get a list of saved tracks getAllTracks(); // get the record table data tableReader = new RecordTableReader(this); tableReader.readRecordTable(); this.recordTableList = tableReader.recordTable; }
// Connect to the arm public bool Connect() { // Vendor ID/Product ID here UsbDeviceFinder USBFinder = new UsbDeviceFinder(0x1267, 0x0); // Try to open the device RobotArm = UsbDevice.OpenUsbDevice(USBFinder); // Did we connect OK? if ((RobotArm == null)) return false; // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = RobotArm as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config #1 wholeUsbDevice.SetConfiguration(1); // Claim interface #0. wholeUsbDevice.ClaimInterface(0); } // Connected and have interface to the arm return true; }
public LibUsb_AsyncUsbStream (string port) { var splited = port.Split ('-'); var finder = new UsbDeviceFinder (int.Parse (splited [0]), int.Parse (splited [1])); device = UsbDevice.OpenUsbDevice (finder); if (device == null) { throw new Exception ("Failed to find device:" + port); } if (!device.IsOpen) { throw new Exception ("Device is not open:" + port); } var usbDevice = device as IUsbDevice; var interfaceInfo = device.Configs [0].InterfaceInfoList [0]; if (usbDevice != null) { usbDevice.SetConfiguration (device.Configs [0].Descriptor.ConfigID); usbDevice.ClaimInterface (interfaceInfo.Descriptor.InterfaceID); deviceInterfaceId = interfaceInfo.Descriptor.InterfaceID; } foreach (var ep in interfaceInfo.EndpointInfoList) { if ((ep.Descriptor.EndpointID & 0x80) > 0) { reader = device.OpenEndpointReader ((ReadEndpointID)ep.Descriptor.EndpointID); reader.DataReceived += HandleDataReceived; reader.DataReceivedEnabled = true; } else { writer = device.OpenEndpointWriter ((WriteEndpointID)ep.Descriptor.EndpointID); } } }
private static void InitDevice() { MyUsbFinder = new UsbDeviceFinder(0x045E, 0x02B0); MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); // If the device is open and ready if (MyUsbDevice == null) throw new Exception("Device Not Found."); // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config #1 wholeUsbDevice.SetConfiguration(1); // Claim interface #0. wholeUsbDevice.ClaimInterface(0); } }
public static void OpenDevice(Int32 vid, Int32 pid) { if (usbDevice != null) Program.ShowError("A device is already openned, please close it first."); Logger.Log("Connecting to device vid." + vid + " pid." + pid); UsbDeviceFinder usbFinder = new UsbDeviceFinder(vid, pid); // Find and open the usb device. usbDevice = UsbDevice.OpenUsbDevice(usbFinder); // If the device is open and ready if (usbDevice == null) throw new Exception("Device Not Found."); // 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 = usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config #1 wholeUsbDevice.SetConfiguration(1); // Claim interface #0. wholeUsbDevice.ClaimInterface(0); } }
public LagomLitenLed() { MyUsbFinder = new UsbDeviceFinder(0x1781, 0x1111); red = new byte[numberOfDiodes]; green = new byte[numberOfDiodes]; blue = new byte[numberOfDiodes]; }
/// <summary> /// Creates an instance of a USB device using a VID PID pair /// </summary> /// <param name="vid">VID</param> /// <param name="pid">PID</param> public VUsbDevice(int vid, int pid) { MyUsbFinder = new UsbDeviceFinder(vid, pid); UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier(); UsbDeviceNotifier.OnDeviceNotify += new EventHandler<DeviceNotifyEventArgs>(UsbDeviceNotifier_OnDeviceNotify); UsbDeviceNotifier.Enabled = true; }
public PortUtil(string usbVid, string usbPid, string endpointId) { Int32 vid = Int32.Parse(usbVid, NumberStyles.HexNumber); Int32 pid = Int32.Parse(usbPid, NumberStyles.HexNumber); _usbFinder = new UsbDeviceFinder(vid, pid); _endpointId = GetEndpointId(endpointId); _portType = PortType.USB; }
public Teensy(int pid, int vid) { _vid = vid; _pid = pid; _usbFinder = new UsbDeviceFinder(_vid, _pid); _buffer = null; _devNotifier = DeviceNotifier.OpenDeviceNotifier(); _devNotifier.OnDeviceNotify += OnDeviceNotify; }
public ArduinoUsbDevice(int vendorId, int productId) { _vendorId = vendorId; _productId = productId; _myUsbFinder = new UsbDeviceFinder(_vendorId, _productId); _usbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier(); _usbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent; ConnectUsbDevice(); }
/// <summary> /// Initializes a new instance of the <see cref="uDMX"/> class. /// </summary> public uDMX() { // Find device by vID and pID UsbDeviceFinder finder = new UsbDeviceFinder (vID, pID); _device = UsbDevice.OpenUsbDevice (finder); if (_device != null) { // Verify if it's really uDMX if (!(_device.Info.ManufacturerString == MANUFACTURER && _device.Info.ProductString == PRODUCT)) { _device = null; } } }
/// <summary> /// Simple constructor /// </summary> public littleWire() { MyUsbFinder = new UsbDeviceFinder(0x1781, 0x0C9F); }
/// <summary> /// Opens the usb device that matches the <see cref="UsbDeviceFinder"/>. /// </summary> /// <param name="usbDeviceFinder">The <see cref="UsbDeviceFinder"/> class used to find the usb device.</param> /// <returns>An valid/open usb device class if the device was found or Null if the device was not found.</returns> public static UsbDevice OpenUsbDevice(UsbDeviceFinder usbDeviceFinder) { return OpenUsbDevice((Predicate<UsbRegistry>) usbDeviceFinder.Check); }
/// <summary> /// Find all UsbRegistry devices using a <see cref="UsbDeviceFinder"/> instance. /// </summary> /// <param name="usbDeviceFinder">The <see cref="UsbDeviceFinder"/> instance used to locate the usb registry devices.</param> /// <returns>All usb registry classes that match.</returns> public UsbRegDeviceList FindAll(UsbDeviceFinder usbDeviceFinder) { return(FindAll((Predicate <UsbRegistry>)usbDeviceFinder.Check)); }
// USB connection and adapter management public override void Open() { this.Close(); try { caLibUsbAdapter.write_lock.WaitOne(); usb_finder = new UsbDeviceFinder(this.vid, this.pid); Debug.Assert(this.usb_finder != null); // open device usb_device = UsbDevice.OpenUsbDevice(usb_finder); if (usb_device == null) { throw new Exception("No compatible adapters found"); } wholeUsbDevice = usb_device as IUsbDevice; if (!ReferenceEquals (wholeUsbDevice, null)) { wholeUsbDevice.SetConfiguration(1); wholeUsbDevice.ClaimInterface(1); } else { throw new Exception("Failed to claim interface"); } // open endpoints ep_reader = usb_device.OpenEndpointReader(this.read_ep_id); ep_writer = usb_device.OpenEndpointWriter(this.write_ep_id); if(ep_reader == null || ep_writer == null) { throw new Exception("Failed to open endpoints"); } // clear garbage from input this.ep_reader.ReadFlush(); // attach read event ep_reader.DataReceived += (read_usb); ep_reader.DataReceivedEnabled = true; } catch (Exception e) { this.Close(); throw e; } finally { caLibUsbAdapter.write_lock.ReleaseMutex(); } }
private static bool Get_connect_PlanetCNC() { //vid 2121 pid 2130 в десятичной системе будет как 8481 и 8496 соответственно UsbDeviceFinder myUsbFinder = new UsbDeviceFinder(8481, 8496); // Попытаемся установить связь _myUsbDevice = UsbDevice.OpenUsbDevice(myUsbFinder); if (_myUsbDevice == null) { string StringError = "Не найден подключенный контроллер."; _connected = false; AddMessage(StringError); //запустим событие о разрыве связи if (WasDisconnected != null) WasDisconnected(null, new DeviceEventArgsMessage(StringError)); return false; } IUsbDevice wholeUsbDevice = _myUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config #1 wholeUsbDevice.SetConfiguration(1); // Claim interface #0. wholeUsbDevice.ClaimInterface(0); } // open read endpoint 1. _usbReader = _myUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01); // open write endpoint 1. _usbWriter = _myUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01); return true; }
//private static List<UsbEndpointWriter> writers; //TODO: Implement multiple controller writers //private static List<UsbEndpointReader> readers; //TODO: Implement multiple controller writers public MainWindow() { System.Windows.Application.Current.MainWindow = this; InitializeComponent(); ValidateRegistrySettings(); jController = new JoystickController(); cController = new ChatpadController(); try { MyUsbFinder = new UsbDeviceFinder(1118, 1817); MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); if (MyUsbDevice == null) //support other product id (knock-off?) { ErrorLogging.WriteLogEntry("USB Device (1118,1817) not found: ", ErrorLogging.LogLevel.Fatal); MyUsbFinder = new UsbDeviceFinder(1118, 657); MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); if (MyUsbDevice == null) { ErrorLogging.WriteLogEntry("USB Device (1118,657) not found: ", ErrorLogging.LogLevel.Fatal); } } } catch (Exception e) { ErrorLogging.WriteLogEntry(String.Format("No USB Device found: {0}", e.InnerException), ErrorLogging.LogLevel.Fatal); } try { IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { try { wholeUsbDevice.SetConfiguration(1); wholeUsbDevice.ClaimInterface(0); reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01); writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01); reader.DataReceived += new EventHandler<EndpointDataEventArgs>(reader_DataReceived); reader.DataReceivedEnabled = true; } catch (Exception e) { ErrorLogging.WriteLogEntry(String.Format("Error opening endpoints: {0}", e.InnerException), ErrorLogging.LogLevel.Fatal); } } else { ErrorLogging.WriteLogEntry("Whole USB device is not implemented", ErrorLogging.LogLevel.Error); } } catch (Exception e) { ErrorLogging.WriteLogEntry(String.Format("Failure converting usb device to whole usb device: {0}", e.InnerException), ErrorLogging.LogLevel.Fatal); } try { timer.Start(); InitializeChatpad(); InitializeController(); } catch (Exception e) { ErrorLogging.WriteLogEntry(String.Format("Error in init of chatpad or controller: {0}", e.InnerException), ErrorLogging.LogLevel.Fatal); } timer.Tick += new EventHandler(dispatcherTimer_Tick); timer.Interval = new TimeSpan(0, 0, 0, 1, 0); ni.Icon = new Icon(@"Images\controller.ico"); ni.Visible = true; ni.Click += delegate(object sender, EventArgs args) { this.Show(); this.WindowState = WindowState.Normal; }; }
static UsbCommunicator() { finder = new UsbDeviceFinder(Constants.getVID(), Constants.getPID()); }
/// <summary> /// Find the last UsbRegistry devices using a <see cref="UsbDeviceFinder"/> instance. /// </summary> /// <param name="usbDeviceFinder">The <see cref="UsbDeviceFinder"/> instance used to locate the usb registry devices.</param> /// <returns>A valid usb registry class if the device was found or Null if the device was not found.</returns> public UsbRegistry FindLast(UsbDeviceFinder usbDeviceFinder) { return(mUsbRegistryList.FindLast((Predicate <UsbRegistry>)usbDeviceFinder.Check)); }
void HandleUsbDeviceNotifierOnDeviceNotify(object sender, DeviceNotifyEventArgs e) { if ( e.Device.IdVendor == GARMIN_VID ) { var device_finder = new UsbDeviceFinder(e.Device.IdVendor, e.Device.IdProduct); var device_registry = UsbDevice.AllDevices.Find(device_finder); UsbDevice device; if ( device_registry.Open(out device) ) { DeviceAdded(new GarminUnit(device)); } } }
/// <summary> /// Saves a <see cref="UsbDeviceFinder"/> instance to a stream. /// </summary> /// <param name="usbDeviceFinder"></param> /// <param name="outStream"></param> public static void Save(UsbDeviceFinder usbDeviceFinder, Stream outStream) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(outStream, usbDeviceFinder); }
// //переделать всё // private void connect() { if (comboBox1.SelectedIndex != -1) MyUsbFinder = new UsbDeviceFinder(Convert.ToInt32(devices_libusb[comboBox1.SelectedIndex].VID, 16), Convert.ToInt32(devices_libusb[comboBox1.SelectedIndex].PID, 16)); DataPoint temp = new DataPoint(); ErrorCode ec = ErrorCode.None; try { //открываем поток MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); if (MyUsbDevice == null) throw new Exception("Device Not Found."); IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.SetConfiguration(1); wholeUsbDevice.ClaimInterface(0); } //читает 1ый эндпоинт UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader((ReadEndpointID)comboBox2.SelectedItem); byte[] readBuffer = new byte[1024]; int bytesRead; //Возвращает данные или ошибку, если через 5 секунд ничего не было возвращено ec = reader.Read(readBuffer, 5000, out bytesRead); if (bytesRead == 0) throw new Exception(string.Format("{0}:No more bytes!", ec)); try { if (trying) { temp.SetValueXY(i, Convert.ToDouble(Encoding.Default.GetString(readBuffer, 0, bytesRead).Replace('.', ','))); i++; chart1.Series[0].Points.Add(temp); data.Add(Encoding.Default.GetString(readBuffer, 0, bytesRead)); } } catch { trying = false; } textBox2.AppendText(Encoding.Default.GetString(readBuffer, 0, bytesRead)); } catch (Exception ex) { //кидает ошибку и останавливает таймер при ошибке timer1.Stop(); MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message); } finally { //закрывает поток 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 void Start() { var USBFinder = new UsbDeviceFinder(0x057E, 0x0337); GCNAdapter = UsbDevice.OpenUsbDevice(USBFinder); gcn1DZ = new ControllerDeadZones(); if (GCNAdapter != null) { int transferLength; writer = GCNAdapter.OpenEndpointWriter(WriteEndpointID.Ep02); //prompt controller to start sending writer.Write(Convert.ToByte((char)19), 10, out transferLength); try { if (!JoystickHelper.checkJoystick(ref gcn1, 1)) { SystemHelper.CreateJoystick(1); } if (gcn1Enabled && gcn1.AcquireVJD(1)) { gcn1ok = true; gcn1.ResetAll(); } } catch (Exception ex) { DriverLog(null, new Logging.LogEventArgs("Error: " + ex.ToString())); if (ex.Message.Contains("HRESULT: 0x8007000B")) { DriverLog(null, new Logging.LogEventArgs("Error: vJoy driver mismatch. Did you install the wrong version (x86/x64)?")); Driver.run = false; return; } } if (noEventMode) { DriverLog(null, new Logging.LogEventArgs("Driver successfully started, entering input loop.")); run = true; while (run) { if (gcn1ok) { JoystickHelper.setJoystick(ref gcn1, Bot.Instance.State, 1, gcn1DZ); } } if (GCNAdapter != null) { if (GCNAdapter.IsOpen) { if (!ReferenceEquals(wholeGCNAdapter, null)) { wholeGCNAdapter.ReleaseInterface(0); } GCNAdapter.Close(); } GCNAdapter = null; UsbDevice.Exit(); DriverLog(null, new Logging.LogEventArgs("Closing driver thread...")); } DriverLog(null, new Logging.LogEventArgs("Driver thread has been stopped.")); } else { DriverLog(null, new Logging.LogEventArgs("Driver successfully started, entering input loop.")); //using Interrupt request instead of looping behavior. reader.DataReceivedEnabled = true; reader.DataReceived += reader_DataReceived; reader.ReadBufferSize = 37; reader.ReadThreadPriority = System.Threading.ThreadPriority.Highest; run = true; } } else { DriverLog(null, new Logging.LogEventArgs("GCN Adapter not detected.")); Driver.run = false; } }
/// <summary> /// Saves a <see cref="UsbDeviceFinder"/> instance to a stream. /// </summary> /// <param name="usbDeviceFinder"></param> /// <param name="outStream"></param> public static void Save(UsbDeviceFinder usbDeviceFinder, Stream outStream) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(outStream, usbDeviceFinder); }
protected void OnOpen() { UsbDeviceFinder f = new UsbDeviceFinder(2334, 3); _device = UsbDevice.OpenUsbDevice(f); if (_device == null) throw new Exception("Device not found"); IUsbDevice id = _device as IUsbDevice; if (id == null) throw new Exception("This is not a full usb device"); id.SetConfiguration(1); id.ClaimInterface(0); _irIN = _device.OpenEndpointReader(ReadEndpointID.Ep01); _bulkOUT = _device.OpenEndpointWriter(WriteEndpointID.Ep02); _bulkIN = _device.OpenEndpointReader(ReadEndpointID.Ep03); }