private static StringBuilder getDescriptorReport(UsbRegistry usbRegistry) { UsbDevice usbDevice; StringBuilder sbReport = new StringBuilder(); if (!usbRegistry.Open(out usbDevice)) return sbReport; sbReport.AppendLine(string.Format("{0} OSVersion:{1} LibUsbDotNet Version:{2} DriverMode:{3}", usbRegistry.FullName, UsbDevice.OSVersion, LibUsbDotNetVersion, usbDevice.DriverMode)); sbReport.AppendLine(usbDevice.Info.ToString("",UsbDescriptor.ToStringParamValueSeperator,UsbDescriptor.ToStringFieldSeperator)); foreach (UsbConfigInfo cfgInfo in usbDevice.Configs) { sbReport.AppendLine(string.Format("CONFIG #{1}\r\n{0}", cfgInfo.ToString("", UsbDescriptor.ToStringParamValueSeperator, UsbDescriptor.ToStringFieldSeperator), cfgInfo.Descriptor.ConfigID)); foreach (UsbInterfaceInfo interfaceInfo in cfgInfo.InterfaceInfoList) { sbReport.AppendLine(string.Format("INTERFACE ({1},{2})\r\n{0}", interfaceInfo.ToString("", UsbDescriptor.ToStringParamValueSeperator, UsbDescriptor.ToStringFieldSeperator), interfaceInfo.Descriptor.InterfaceID, interfaceInfo.Descriptor.AlternateID)); foreach (UsbEndpointInfo endpointInfo in interfaceInfo.EndpointInfoList) { sbReport.AppendLine(string.Format("ENDPOINT 0x{1:X2}\r\n{0}", endpointInfo.ToString("", UsbDescriptor.ToStringParamValueSeperator, UsbDescriptor.ToStringFieldSeperator), endpointInfo.Descriptor.EndpointID)); } } } usbDevice.Close(); return sbReport; }
private static bool FillWindowsMonoUsbDeviceRegistry(UsbRegistry usbRegistry, MonoUsbDevice usbDevice) { MonoLibUsb.MonoUsbApi.internal_windows_device_priv priv = MonoLibUsb.MonoUsbApi.GetWindowsPriv(usbDevice.Profile.ProfileHandle); string path; for (int i = 0; i < 32; i++) { if (priv.usb_interfaces[i].path == IntPtr.Zero) { break; } path = Marshal.PtrToStringAnsi(priv.usb_interfaces[i].path); //Debug.Print("Intf:{0} Path:{1}",i,path); } path = Marshal.PtrToStringAnsi(priv.path); bool bFound = false; //System.Diagnostics.Debug.WriteLine(sb.ToString()); path = path.ToString().ToLower().Replace("#", "\\"); foreach (MasterItem masterItem in mMasterSetupApiDeviceList) { if (path.Contains(masterItem[DEVICE_ID_KEY].ToString().ToLower())) { usbRegistry.mDeviceProperties = masterItem; bFound = true; break; } } return(bFound); }
public UsbConnection(UsbRegistry regDevice) { this.DevicePath = regDevice.SymbolicName; device = regDevice.Device; SerialNumber = device.Info.SerialString; Name = device.Info.ProductString; Version = device.Info.Descriptor.BcdDevice; }
internal void OpenDevice (UsbRegistry registry) { this._device = registry.Device; IUsbDevice wholeUsbDevice = _device as IUsbDevice; if (!ReferenceEquals (wholeUsbDevice, null)) { // Select config #1 wholeUsbDevice.SetConfiguration (1); // Claim interface #0. wholeUsbDevice.ClaimInterface (0); } }
/// <summary> /// Dynamic predicate find function. Pass this function into any method that has a <see cref="Predicate{UsbRegistry}"/> parameter. /// </summary> /// <remarks> /// Override this member when inheriting the <see cref="UsbDeviceFinder"/> class to change/alter the matching behavior. /// </remarks> /// <param name="usbRegistry">The UsbRegistry device to check.</param> /// <returns>True if the <see cref="UsbRegistry"/> instance matches the <see cref="UsbDeviceFinder"/> properties.</returns> public virtual bool Check(UsbRegistry usbRegistry) { if (mVid != int.MaxValue) { if (usbRegistry.Vid != mVid) { return(false); } } if (mPid != int.MaxValue) { if (usbRegistry.Pid != mPid) { return(false); } } if (mRevision != int.MaxValue) { if (usbRegistry.Rev != mRevision) { return(false); } } if (!String.IsNullOrEmpty(mSerialNumber)) { if (String.IsNullOrEmpty(usbRegistry.SymbolicName)) { return(false); } UsbSymbolicName usbSymbolicName = UsbSymbolicName.Parse(usbRegistry.SymbolicName); if (mSerialNumber != usbSymbolicName.SerialNumber) { return(false); } } if (mDeviceInterfaceGuid != Guid.Empty) { List <Guid> deviceGuids = new List <Guid>(usbRegistry.DeviceInterfaceGuids); if (!deviceGuids.Contains(mDeviceInterfaceGuid)) { return(false); } } return(true); }
public static bool FillDeviceProperties(UsbRegistry usbRegistry, UsbDevice usbDevice) { lock (mLockSetupApiRegistry) { if (NeedsRefresh) { BuildMasterList(); } if (usbDevice is MonoUsbDevice && !Helper.IsLinux) { return(FillWindowsMonoUsbDeviceRegistry(usbRegistry, (MonoUsbDevice)usbDevice)); } string fakeHwId = LegacyUsbRegistry.GetRegistryHardwareID((ushort)usbDevice.Info.Descriptor.VendorID, (ushort)usbDevice.Info.Descriptor.ProductID, (ushort)usbDevice.Info.Descriptor.BcdDevice); bool bFound = false; string hwIdToFind = fakeHwId.ToLower(); foreach (MasterItem masterItem in mMasterSetupApiDeviceList) { string[] hwIds = masterItem[SPDRP.HardwareId.ToString()] as string[]; if (ReferenceEquals(hwIds, null)) { continue; } foreach (string hwID in hwIds) { if (hwID.ToLower().Contains(hwIdToFind)) { usbRegistry.mDeviceProperties = masterItem; bFound = true; break; } } if (bFound) { break; } } return(bFound); } }
void formDAQSelector_FormClosing(object sender, FormClosingEventArgs e) { if (!formDAQSelector.isDeviceSelected) { sequenceTextbox.BackColor = Color.Red; } else { sequenceTextbox.BackColor = System.Drawing.SystemColors.Control; usbDeviceReg = formDAQSelector.usbDevice; StartAcquisition(); } dataBuffer = Convert.ToInt32(formDAQSelector.textEditDataBuffer.Text); SignalData = new double[dataBuffer]; //to be specified the size }
/// <summary> /// Dynamic predicate find function. Pass this function into any method that has a <see cref="Predicate{UsbRegistry}"/> parameter. /// </summary> /// <remarks> /// Override this member when inheriting the <see cref="UsbDeviceFinder"/> class to change/alter the matching behavior. /// </remarks> /// <param name="usbRegistry">The UsbRegistry device to check.</param> /// <returns>True if the <see cref="UsbRegistry"/> instance matches the <see cref="UsbDeviceFinder"/> properties.</returns> public virtual bool Check(UsbRegistry usbRegistry) { if (mVid != int.MaxValue) if (usbRegistry.Vid != mVid) return false; if (mPid != int.MaxValue) if (usbRegistry.Pid != mPid) return false; if (mRevision != int.MaxValue) if (usbRegistry.Rev != mRevision) return false; if (!String.IsNullOrEmpty(mSerialNumber)) { if (String.IsNullOrEmpty(usbRegistry.SymbolicName)) return false; UsbSymbolicName usbSymbolicName = UsbSymbolicName.Parse(usbRegistry.SymbolicName); if (mSerialNumber != usbSymbolicName.SerialNumber) return false; } if (mDeviceInterfaceGuid != Guid.Empty) { List<Guid> deviceGuids = new List<Guid>(usbRegistry.DeviceInterfaceGuids); if (!deviceGuids.Contains(mDeviceInterfaceGuid)) return false; } return true; }
private static bool BuildMasterCallback(IntPtr deviceInfoSet, int deviceindex, ref SetupApi.SP_DEVINFO_DATA deviceInfoData, object userData) { MasterList deviceList = userData as MasterList; MasterItem deviceItem = new MasterItem(); StringBuilder sb = new StringBuilder(256); if (SetupApi.CM_Get_Device_ID(deviceInfoData.DevInst, sb, sb.Capacity, 0) != SetupApi.CR.SUCCESS) { return(false); } deviceItem.Add(DEVICE_ID_KEY, sb.ToString()); deviceList.Add(deviceItem); RegistryValueKind propertyType; byte[] propBuffer = new byte[256]; int requiredSize; bool bSuccess = SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet, ref deviceInfoData, UsbRegistry.DEVICE_INTERFACE_GUIDS, SetupApi.DICUSTOMDEVPROP.NONE, out propertyType, propBuffer, propBuffer.Length, out requiredSize); if (bSuccess) { string[] devInterfaceGuids = UsbRegistry.GetAsStringArray(propBuffer, requiredSize); deviceItem.Add(UsbRegistry.DEVICE_INTERFACE_GUIDS, devInterfaceGuids); foreach (string s in devInterfaceGuids) { Guid g = new Guid(s); List <string> devicePathList; if (WinUsb.WinUsbRegistry.GetDevicePathList(g, out devicePathList)) { deviceItem.DevicePaths.Add(g, devicePathList); } } } else { bSuccess = SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet, ref deviceInfoData, UsbRegistry.LIBUSB_INTERFACE_GUIDS, SetupApi.DICUSTOMDEVPROP.NONE, out propertyType, propBuffer, propBuffer.Length, out requiredSize); if (bSuccess) { string[] devInterfaceGuids = UsbRegistry.GetAsStringArray(propBuffer, requiredSize); deviceItem.Add(UsbRegistry.LIBUSB_INTERFACE_GUIDS, devInterfaceGuids); } } bSuccess = SetupApi.SetupDiGetCustomDeviceProperty(deviceInfoSet, ref deviceInfoData, UsbRegistry.SYMBOLIC_NAME_KEY, SetupApi.DICUSTOMDEVPROP.NONE, out propertyType, propBuffer, propBuffer.Length, out requiredSize); if (bSuccess) { string symbolicName = UsbRegistry.GetAsString(propBuffer, requiredSize); deviceItem.Add(UsbRegistry.SYMBOLIC_NAME_KEY, symbolicName); } SetupApi.getSPDRPProperties(deviceInfoSet, ref deviceInfoData, deviceItem); return(false); }
private void addDevice(UsbRegistry deviceReg, string display) { if (!deviceReg.Open(out mUsbDevice)) return; mUsbRegistry = deviceReg; TreeNode tvDevice = tvInfo.Nodes.Add(display); string[] sDeviceAdd = mUsbDevice.Info.ToString().Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (string s in sDeviceAdd) tvDevice.Nodes.Add(s); foreach (UsbConfigInfo cfgInfo in mUsbDevice.Configs) { TreeNode tvConfig = tvDevice.Nodes.Add("Config " + cfgInfo.Descriptor.ConfigID); string[] sCfgAdd = cfgInfo.ToString().Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (string s in sCfgAdd) tvConfig.Nodes.Add(s); TreeNode tvInterfaces = tvConfig; //.Nodes.Add("Interfaces"); foreach (UsbInterfaceInfo interfaceInfo in cfgInfo.InterfaceInfoList) { TreeNode tvInterface = tvInterfaces.Nodes.Add("Interface [" + interfaceInfo.Descriptor.InterfaceID + "," + interfaceInfo.Descriptor.AlternateID + "]"); string[] sInterfaceAdd = interfaceInfo.ToString().Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (string s in sInterfaceAdd) tvInterface.Nodes.Add(s); TreeNode tvEndpoints = tvInterface; //.Nodes.Add("Endpoints"); foreach (UsbEndpointInfo endpointInfo in interfaceInfo.EndpointInfoList) { TreeNode tvEndpoint = tvEndpoints.Nodes.Add("Endpoint 0x" + (endpointInfo.Descriptor.EndpointID).ToString("X2")); string[] sEndpointAdd = endpointInfo.ToString().Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (string s in sEndpointAdd) tvEndpoint.Nodes.Add(s); } } } mUsbDevice.Close(); }
internal void Init(HidDevice hidDevice, UsbRegistry registry) { _hidDevice = hidDevice; OpenDevice (registry); }
private void simpleButtonOK_Click(object sender, EventArgs e) { if (comboBoxEditDeviceList.SelectedIndex >= 0) { usbDevice = (UsbRegistry)tbDeviceList.Rows[comboBoxEditDeviceList.SelectedIndex]["device"]; isDeviceSelected = true; } this.Close(); }
public CrazyFlieDongle(UsbRegistry deviceReg) { _deviceReg = deviceReg; }
/// <summary> /// Matches the VID and PID according to: http://wiki.bitcraze.se/projects:crazyradio:protocol?s[]=pid#usb_protocol /// </summary> private static bool DonglePredicate(UsbRegistry reg) { return reg.Pid == 0x7777 && reg.Vid == 0x1915; }
public LibusbHidDevice (UsbRegistry key) { this.deviceRegistry = key; }
private bool openAsTestDevice(UsbRegistry usbRegistry) { if (!ReferenceEquals(mUsbDevice, null)) closeTestDevice(mUsbDevice); mUsbDevice = null; try { if (usbRegistry.Open(out mUsbDevice)) { UsbInterfaceInfo readInterfaceInfo; UsbInterfaceInfo writeInterfaceInfo; UsbDevice.UsbErrorEvent += OnUsbError; if (!UsbEndpointBase.LookupEndpointInfo(mUsbDevice.Configs[0], 0x80, out readInterfaceInfo, out mReadEndpointInfo)) { throw new Exception("failed locating read endpoint."); } mBenchMarkParameters.BufferSize -= (mBenchMarkParameters.BufferSize%(mReadEndpointInfo.Descriptor.MaxPacketSize)); if (!UsbEndpointBase.LookupEndpointInfo(mUsbDevice.Configs[0], 0x00, out writeInterfaceInfo, out mWriteEndpointInfo)) { throw new Exception("failed locating write endpoint."); } if (((mWriteEndpointInfo.Descriptor.Attributes & 3)==(int) EndpointType.Isochronous) || ((mReadEndpointInfo.Descriptor.Attributes & 3)==(int) EndpointType.Isochronous)) { throw new Exception("buenchmark GUI application does not support ISO endpoints. Use BenchmarkCon instead."); } mBenchMarkParameters.BufferSize -= (mBenchMarkParameters.BufferSize%(mWriteEndpointInfo.Descriptor.MaxPacketSize)); if (writeInterfaceInfo.Descriptor.InterfaceID != readInterfaceInfo.Descriptor.InterfaceID) throw new Exception("read/write endpoints must be on the same interface."); mEP1Reader = mUsbDevice.OpenEndpointReader( (ReadEndpointID)mReadEndpointInfo.Descriptor.EndpointID, mBenchMarkParameters.BufferSize, (EndpointType)(mReadEndpointInfo.Descriptor.Attributes & 3)); mEP1Writer = mUsbDevice.OpenEndpointWriter( (WriteEndpointID) mWriteEndpointInfo.Descriptor.EndpointID, (EndpointType) (mWriteEndpointInfo.Descriptor.Attributes & 3)); mInterfaceInfo = writeInterfaceInfo; mEP1Reader.ReadThreadPriority = mBenchMarkParameters.Priority; mEP1Reader.DataReceived += OnDataReceived; makeTestBytes(out loopTestBytes, mBenchMarkParameters.BufferSize); // 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 = mUsbDevice 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(mInterfaceInfo.Descriptor.InterfaceID); } return true; } } catch(Exception ex) { SetStatus(ex.Message, true); } if (!ReferenceEquals(mUsbDevice,null)) { try { closeTestDevice(mUsbDevice); } finally { mUsbDevice = null; mEP1Reader = null; mEP1Writer = null; } } return false; }