// 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 override void PollDevice() { if (interfaces.Count > 0 && onConnect != null) { onConnect(interfaces.First().Value, true); return; } foreach (int PID in PIDs) { UsbDeviceFinder scopeUsbFinder = new UsbDeviceFinder(VID, PID); UsbDevice scopeUsbDevice = UsbDevice.OpenUsbDevice(scopeUsbFinder); if (scopeUsbDevice != null) { try { DeviceFound(scopeUsbDevice); } catch (Exception e) { C.Logger.Error("Device was found but failed to register: " + e.Message); } break; } } }
private void Start() { var USBFinder = new UsbDeviceFinder(0x057E, 0x0337); GCNAdapter = UsbDevice.OpenUsbDevice(USBFinder); if (GCNAdapter != null) { reader = GCNAdapter.OpenEndpointReader(ReadEndpointID.Ep01); writer = GCNAdapter.OpenEndpointWriter(WriteEndpointID.Ep02); //prompt controller to start sending writer.Write(Convert.ToByte((char)19), 10, out transferLength); // PORT 1: bytes 02-09 // PORT 2: bytes 11-17 // PORT 3: bytes 20-27 // PORT 4: bytes 29-36l ReadBuffer = new byte[37]; // 32 (4 players x 8) bytes for input, 5 bytes for formatting //WriteBuffer = new byte[5]; // 1 for command, 4 for rumble state //WriteBuffer[0] = 0x11; //WriteBuffer[1] = 0; reader.ReadThreadPriority = System.Threading.ThreadPriority.Highest; reader.Flush(); gcThread = new Thread(() => inputUpdate(ref ReadBuffer)); gcThread.Start(); } else { UnityEngine.Debug.Log("ERROR: Could not detect device WUP-028 Gamecube Controller Adapter."); } }
/// <summary> /// Performs initialisation tasks required before enabling printing. /// </summary> /// <exception cref="DC.PrintingServices.PrinterNotFoundException">No printer can be found with the specified vendor id and product id.</exception> public void Initialise() { // Create a USB device finder for finding the printer. _deviceFinder = new UsbDeviceFinder(this.VendorID, this.ProductID); // Find and open a connection to the printer. _printer = UsbDevice.OpenUsbDevice(_deviceFinder); _printerUSBDevice = _printer as IUsbDevice; if (_printerUSBDevice != null) { // ANDREW LING [28 Feburary 2014]: Make the configuration and interface settings configurable. _printerUSBDevice.SetConfiguration(1); _printerUSBDevice.ClaimInterface(0); } else { // The printer cannot be located. // ANDREW LING [28 February 2014]: TODO: Log when the printer cannot be located. // ANDREW LING [28 February 2014]: TODO: Display an error message on screen when the printer cannot be located. throw new PrinterNotFoundException(this.VendorID, this.ProductID); } // ANDREW LING [28 February 2014]: TODO: Make the write end point ID configurable. _writer = _printerUSBDevice.OpenEndpointWriter(WriteEndpointID.Ep02); // Mark that the initialisation tasks have been completed. _initialised = true; }
/// <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); // create the otp reader object this.myOTPreader = new OTPreader(this); // create a saved track reader to get a list of saved tracks this.trackReader = new SavedTrackReader(this); this.trackList = trackReader.trackList; // get the record table data tableReader = new RecordTableReader(this); tableReader.readRecordTable(); this.recordTableList = tableReader.recordTable; }
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); } }
//called at init, and each time a system event occurs private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e) { switch (e.EventType) { case EventType.DeviceArrival: C.Logger.Debug("LibUSB device arrival"); if (e.Device == null || e.Device.IdVendor != VID || !PIDs.Contains(e.Device.IdProduct)) { C.Logger.Debug("Not taking this device, PID/VID not a smartscope"); return; } UsbDeviceFinder usbFinder = new UsbDeviceFinder(e.Device.IdVendor, e.Device.IdProduct, e.Device.SerialNumber); UsbDevice usbDevice = UsbDevice.OpenUsbDevice(usbFinder); if (usbDevice != null) { DeviceFound(usbDevice); } break; case EventType.DeviceRemoveComplete: C.Logger.Debug(String.Format("LibUSB device removal [VID:{0},PID:{1}]", e.Device.IdVendor, e.Device.IdProduct)); if (e.Device != null && e.Device.IdVendor == VID && PIDs.Contains(e.Device.IdProduct)) { RemoveDevice(e.Device.SerialNumber); } break; default: C.Logger.Debug("LibUSB unhandled device event [" + Enum.GetName(typeof(EventType), e.EventType) + "]"); break; } }
public IDevice GetDevice(ConnectedDeviceDefinition deviceDefinition) { var usbDeviceFinder = new UsbDeviceFinder((int)deviceDefinition.VendorId.Value, (int)deviceDefinition.ProductId.Value); var usbDevice = UsbDevice.OpenUsbDevice(usbDeviceFinder); return(usbDevice != null ? new LibUsbDevice(usbDevice, 3000) : null); }
/// <summary> /// Connect to first Fastboot device /// </summary> public void Connect() { UsbDeviceFinder finder; if (string.IsNullOrWhiteSpace(targetSerialNumber)) { finder = new UsbDeviceFinder(USB_VID, USB_PID); } else { finder = new UsbDeviceFinder(USB_VID, USB_PID, targetSerialNumber); } device = UsbDevice.OpenUsbDevice(finder); if (device == null) { throw new Exception("No devices available."); } var wDev = device as IUsbDevice; if (wDev is IUsbDevice) { wDev.SetConfiguration(1); wDev.ClaimInterface(0); } }
public bool Connect() { bool rv = false; rv = false; Disconnect(); MyUSBDeviceFinder = new UsbDeviceFinder(DevVID, DevPID, DevRevision, DevSerialNumber, DevGUID); MyUSBDevice = UsbDevice.OpenUsbDevice(MyUSBDeviceFinder); if (MyUSBDevice != null) { WholeUSBDevice = MyUSBDevice as IUsbDevice; if (!ReferenceEquals(WholeUSBDevice, null)) { WholeUSBDevice.SetConfiguration(1); WholeUSBDevice.ClaimInterface(0); } MyUSBWriter = MyUSBDevice.OpenEndpointWriter(WriteEndpointID.Ep01); MyUSBReader = MyUSBDevice.OpenEndpointReader(ReadEndpointID.Ep01, 4096); MyUSBReader.DataReceived += MyUSBReader_DataReceived; MyUSBReader.DataReceivedEnabled = true; MyUSBSetupPacket.RequestType = (byte)(UsbCtrlFlags.RequestType_Vendor | UsbCtrlFlags.Recipient_Interface | UsbCtrlFlags.Direction_In); MyUSBSetupPacket.Request = 1; MyUSBSetupPacket.Value = 0; MyUSBSetupPacket.Length = 4; bkThread = new System.Threading.Thread(this.Th_DoWork); bkThExit = false; bkThread.Start(); rv = true; } return(rv); }
public void Disconnect() { if (bkThread != null) { bkThExit = true; bkThInterrupt.Set(); if (bkThread.ThreadState == System.Threading.ThreadState.Running) { bkThread.Join(); } } bkThread = null; if (MyUSBDevice != null) { if (MyUSBDevice.IsOpen) { WholeUSBDevice = MyUSBDevice as IUsbDevice; if (!ReferenceEquals(WholeUSBDevice, null)) { WholeUSBDevice.ReleaseInterface(0); } MyUSBReader.DataReceivedEnabled = false; MyUSBReader.DataReceived -= MyUSBReader_DataReceived; MyUSBDevice.Close(); } MyUSBDevice = null; WholeUSBDevice = null; MyUSBDeviceFinder = null; MyUSBReader = null; MyUSBWriter = null; } }
/// <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 override bool Open() { try { UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(((UsbConfigModel)Configuration).PID, ((UsbConfigModel)Configuration).VID); UsbRegistry myUsbRegistry = UsbDevice.AllWinUsbDevices.Find(MyUsbFinder); if (myUsbRegistry is null) { return(false); } // Open this usb device. _dev = UsbDevice.OpenUsbDevice(MyUsbFinder) as IUsbDevice; _dev.SetConfiguration(1); _dev.ClaimInterface(0); _writer = _dev.OpenEndpointWriter(WriteEndpointID.Ep01); _reader = _dev.OpenEndpointReader(ReadEndpointID.Ep01); } catch (Exception exp) { throw new Exception(exp.ToString()); } return(true); }
internal IDaplugDongle OpenFirstDongle() { UsbDeviceFinder usbDeviceFinder = new UsbDeviceFinder(VENDOR_ID, PRODUCT_ID); var usbDevice = UsbDevice.OpenUsbDevice(usbDeviceFinder); return(new WinUSBDaplugDongle(usbDevice)); }
public static bool ScanForDMX() { UsbDeviceFinder finder = new UsbDeviceFinder(DMX.vID, DMX.pID); var reg = UsbDevice.AllDevices.Find(finder); return(reg != null); }
/// <summary> /// Initializes a new instance of the LIB USB class. /// </summary> /// <param name="vendorId">Vendor identifier.</param> /// <param name="productId">Product identifier.</param> /// <param name="readId">Read identifier.</param> /// <param name="writeId">Write identifier.</param> public LibUsb(short vendorId, short productId, ReadEndpointID readId, WriteEndpointID writeId) { this.vendorId = vendorId; this.productId = productId; this.readId = readId; this.writeId = writeId; myUsbFinder = new UsbDeviceFinder(this.vendorId, this.productId); }
public MyUsb(int nVId, int nPId) { UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent; nVid = nVId; nPid = nPId; MyUsbFinder = new UsbDeviceFinder(nVId, nPId); }
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(); }
/// <inheritdoc/> public UsbDeviceCollection FindAll(UsbDeviceFinder finder) { if (finder == null) { throw new ArgumentNullException(nameof(finder)); } return(this.FindAll(finder.Check)); }
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; }
private LCTFController() { this.usbFinder = new UsbDeviceFinder(new Guid("{d67436ae-96c7-4da3-83c9-322c4ceb41f3}")); this.usbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier(); this.usbDeviceNotifier.OnDeviceNotify += this.OnDeviceNotify; this.usbDeviceNotifier.Enabled = true; this.UpdateAttachedDevices(); }
public BarcodeScanner(string vendorId, string productId, int interfaceId) { this.vendorId = vendorId; this.productId = productId; usbFinder = new UsbDeviceFinder( Int32.Parse(vendorId, System.Globalization.NumberStyles.HexNumber), Int32.Parse(productId, System.Globalization.NumberStyles.HexNumber)); this.interfaceId = interfaceId; configureDevice(); }
public static UsbPrintConnector Open(int vendorId, int productId, string profile = null) { UsbDeviceFinder finder = new UsbDeviceFinder(vendorId, productId); UsbDevice device = UsbDevice.OpenUsbDevice(finder); if (device == null) { return(null); } return(new UsbPrintConnector(device)); }
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)); } } }
/// <inheritdoc /> public Task OpenAsync() { return(Task.Factory.StartNew(() => { var finder = new UsbDeviceFinder((int)OwiUsbConstants.Vid, (int)OwiUsbConstants.Pid); this.device = UsbDevice.OpenUsbDevice(finder); if (device == null) { var message = string.Format("Unable to locate owi robotic arm with pid = {0}, vid = {1}. Please ensure you have the device connected with a valid usb driver installed.", finder.Pid, finder.Vid); throw new InvalidOperationException(message); } })); }
// 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(); } }
internal static void Init() { // Note that the VID and PID for the test device is 10C4,84C4 UsbDeviceFinder finder = new UsbDeviceFinder(0x10C4, 0x84C4); USBComm.RadioBase = (IUsbDevice)UsbDevice.OpenUsbDevice(finder); USBComm.Reader = USBComm.RadioBase.OpenEndpointReader(ReadEndpointID.Ep01); USBComm.Writer = USBComm.RadioBase.OpenEndpointWriter(WriteEndpointID.Ep01); Reader.Flush(); USBComm.RadioBase.SetConfiguration(1); USBComm.RadioBase.ClaimInterface(0); }
public int init(int device, int devid = 0) { UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(0x1915, 0x7777); var crazyRadiosRegDeviceList = UsbDevice.AllDevices.FindAll(MyUsbFinder); foreach (UsbRegistry reg in crazyRadiosRegDeviceList) { if (reg.Device != null) { MyUsbDevice = reg.Device; break; } } if (MyUsbDevice == null) { return(1); } IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { wholeUsbDevice.SetConfiguration(1); wholeUsbDevice.ClaimInterface(0); } writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01); reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01); version = (ushort)(MyUsbDevice.Info.Descriptor.BcdDevice & 0xFF); if (version < 30) { return(2); } this.set_data_rate(DATA_RATE.DR_2MPS); this.set_channel(2); this.arc = -1; if (this.version >= 40) { this.set_cont_carrier(false); this.set_address(0xE7E7E7E7E7); this.set_power(POWER.P_0DBM); this.set_arc(3); this.set_ard_bytes(32); this.set_ack_enable(true); } return(0); }
/// <summary> /// Function to check the presence of the device on the USB bus /// </summary> /// <param name="USB_VID"> Device Vendor ID</param> /// <param name="USB_PID"> Device Product ID</param> public void DetectDeviceOnBus(Int32 USB_VID, Int32 USB_PID) { UsbDevice usbDevice = null; UsbDeviceFinder usbDeviceFinder = new UsbDeviceFinder(USB_VID, USB_PID); usbDevice = UsbDevice.OpenUsbDevice(usbDeviceFinder); if (usbDevice != null) { DeviceOnBusDetected = true; } else { DeviceOnBusDetected = false; } UsbDevice.Exit(); }