private void tabDevice_Selected(object sender, TabControlEventArgs e) { if (e.Action == TabControlAction.Selected) { if (e.TabPage == tabRegistry) { if (mUsbRegistry != null) { tRegProps.Clear(); UsbSymbolicName symName = UsbSymbolicName.Parse(mUsbRegistry.SymbolicName); if (symName.SerialNumber != string.Empty) { tRegProps.AppendText(string.Format("SerialNumber:{0}\r\n", symName.SerialNumber)); } if (symName.ClassGuid != Guid.Empty) { tRegProps.AppendText(string.Format("Class Guid:{0}\r\n", symName.ClassGuid)); } foreach (KeyValuePair <string, object> current in mUsbRegistry.DeviceProperties) { string key = current.Key; object oValue = current.Value; if (oValue is string[]) { tRegProps.AppendText(key + ":\r\n"); key = new string(' ', key.Length); string[] saValue = oValue as string[]; foreach (string s in saValue) { tRegProps.AppendText(String.Format("{0} {1}\r\n", key, s)); } continue; } tRegProps.AppendText(String.Format("{0}:{1}\r\n", key, oValue)); } } } else if (e.TabPage == tabVersionInfo) { rtfVersionInfo.Clear(); rtfVersionInfo.AppendText("Operating System:" + UsbDevice.OSVersion + "\n"); rtfVersionInfo.AppendText("LibUsbDotNet Version:" + LibUsbDotNetVersion + "\n"); rtfVersionInfo.AppendText("LibUsb Kernel Type:" + UsbDevice.KernelType + "\n"); rtfVersionInfo.AppendText("LibUsb Kernel Version:" + UsbDevice.KernelVersion + "\n"); } } }
private void cboDevice_DropDown(object sender, EventArgs e) { cboDevice.Items.Clear(); mRegInfo = UsbDevice.AllDevices; foreach (UsbRegistry usbRegistry in mRegInfo) { string sCboText = ""; object oHardwareID = usbRegistry[SPDRP.HardwareId.ToString()]; if (oHardwareID != null && oHardwareID is string[]) { UsbSymbolicName symVidPid = UsbSymbolicName.Parse(((string[])oHardwareID)[0]); sCboText = string.Format("Vid:{0} Pid:{1} {2}", symVidPid.Vid.ToString("X4"), symVidPid.Pid.ToString("X4"), usbRegistry.FullName); cboDevice.Items.Add(sCboText); } } }
void logDevice(UsbRegistry usbRegistry) { UsbDevice device; if (!usbRegistry.Open(out device)) { return; } // split device.Info's string representation on linefeeds // iterateDevice: Vid:0x2457 Pid:0x101E (rev:2) - Ocean Optics USB2000+ (WinUSB) // iterateDevice: Vid:0x24AA Pid:0x1000 (rev:100) - Wasatch Photonics Spectrometer // Not all device info summaries will appear in device.Configs...not sure why string[] deviceInfoSummaries = device.Info.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in deviceInfoSummaries) { logger.debug("Summary: {0}", line); } foreach (UsbConfigInfo cfgInfo in device.Configs) { logger.debug("Config {0}", cfgInfo.Descriptor.ConfigID); // log UsbConfigInfo logNameValuePairs(cfgInfo.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)); // log UsbInterfaceInfo foreach (UsbInterfaceInfo interfaceInfo in cfgInfo.InterfaceInfoList) { logger.debug("Interface [InterfaceID {0}, AlternateID {1}]", interfaceInfo.Descriptor.InterfaceID, interfaceInfo.Descriptor.AlternateID); logNameValuePairs(interfaceInfo.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)); // log UsbEndpointInfo foreach (UsbEndpointInfo endpointInfo in interfaceInfo.EndpointInfoList) { logger.debug(" Endpoint 0x" + (endpointInfo.Descriptor.EndpointID).ToString("x2")); logNameValuePairs(endpointInfo.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries), " "); } } // log SymbolicName UsbSymbolicName symName = UsbSymbolicName.Parse(usbRegistry.SymbolicName); logger.debug("Symbolic Name:"); logger.debug(" VID: 0x{0:x4}", symName.Vid); logger.debug(" PID: 0x{0:x4}", symName.Pid); logger.debug(" SerialNumber: {0}", symName.SerialNumber); logger.debug(" Class Guid: {0}", symName.ClassGuid); logger.debug("Device Properties:"); foreach (KeyValuePair <string, object> pair in usbRegistry.DeviceProperties) { string key = pair.Key; object value = pair.Value; // handle array values if (value is string[]) { string[] values = value as string[]; logger.debug(" {0}: [ {1} ]", key, string.Join(", ", values)); } else { logger.debug(" {0}: {1}", key, value); } } logger.debug(" "); } device.Close(); }
private void FillDeviceInfo() { try { UsbRegDeviceList mDevList = UsbDevice.AllDevices; treeDevices.Nodes.Clear(); treeDevices.Nodes.Add("Refreshed at " + DateTime.Now.ToString("HH:mm:ss.fff")); foreach (UsbRegistry device in mDevList) { TreeNode tvDevice = treeDevices.Nodes.Add(string.Format( "VID: 0x{0:X4}, PID: 0x{1:X4}, (rev: {2}) - {3}", device.Vid, device.Pid, (ushort)device.Rev, device[SPDRP.DeviceDesc] )); UsbDevice mUsbDevice; if (!device.Open(out mUsbDevice)) { continue; } UsbRegistry mUsbRegistry = device; tvDevice.Nodes.Add(string.Format("{0}: 0x{1:X4}", "CurrentCultureLangID", mUsbDevice.Info.CurrentCultureLangID)); tvDevice.Nodes.Add(string.Format("{0}: {1}", "ManufacturerString", mUsbDevice.Info.ManufacturerString)); tvDevice.Nodes.Add(string.Format("{0}: {1}", "ProductString", mUsbDevice.Info.ProductString)); tvDevice.Nodes.Add(string.Format("{0}: {1}", "SerialString", mUsbDevice.Info.SerialString)); tvDevice.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "DriverMode", mUsbDevice.DriverMode, (int)mUsbDevice.DriverMode)); if (mUsbDevice.Info.Descriptor != null) { TreeNode tvDescriptor = tvDevice.Nodes.Add(string.Format("Descriptor [Length: {0}]", mUsbDevice.Info.Descriptor.Length)); tvDescriptor.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "DescriptorType", mUsbDevice.Info.Descriptor.DescriptorType, (int)mUsbDevice.Info.Descriptor.DescriptorType)); tvDescriptor.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "Class", mUsbDevice.Info.Descriptor.Class, (int)mUsbDevice.Info.Descriptor.Class)); tvDescriptor.Nodes.Add(string.Format("{0}: 0x{1:X2}", "SubClass", mUsbDevice.Info.Descriptor.SubClass)); tvDescriptor.Nodes.Add(string.Format("{0}: {1}", "ConfigurationCount", mUsbDevice.Info.Descriptor.ConfigurationCount)); tvDescriptor.Nodes.Add(string.Format("{0}: {1}", "MaxPacketSize0", mUsbDevice.Info.Descriptor.MaxPacketSize0)); tvDescriptor.Nodes.Add(string.Format("{0}: {1}", "ManufacturerStringIndex", mUsbDevice.Info.Descriptor.ManufacturerStringIndex)); tvDescriptor.Nodes.Add(string.Format("{0}: {1}", "ProductStringIndex", mUsbDevice.Info.Descriptor.ProductStringIndex)); tvDescriptor.Nodes.Add(string.Format("{0}: {1}", "SerialStringIndex", mUsbDevice.Info.Descriptor.SerialStringIndex)); tvDescriptor.Nodes.Add(string.Format("{0}: 0x{1:X4}, {2}: 0x{3:X4}", "BcdUsb", mUsbDevice.Info.Descriptor.BcdUsb, "BcdDevice", mUsbDevice.Info.Descriptor.BcdDevice)); } if (mUsbDevice.ActiveEndpoints != null) { TreeNode tvActiveEndpoints = tvDevice.Nodes.Add(string.Format("{0} [Count: {1}]", "ActiveEndpoints", mUsbDevice.ActiveEndpoints.Count)); foreach (var i in mUsbDevice.ActiveEndpoints) { FillEndpointInfo(tvActiveEndpoints, i); } } //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 0x" + cfgInfo.Descriptor.ConfigID.ToString("X2")); tvConfig.Nodes.Add(string.Format("{0}: {1}", "ConfigString", cfgInfo.ConfigString)); //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 [0x" + interfaceInfo.Descriptor.InterfaceID.ToString("X2") + ", 0x" + interfaceInfo.Descriptor.AlternateID.ToString("X2") + "]"); tvInterface.Nodes.Add(string.Format("{0}: {1}", "InterfaceString", interfaceInfo.InterfaceString)); if (interfaceInfo.EndpointInfoList != null) { TreeNode tvEndpoints = tvInterface.Nodes.Add(string.Format("Endpoints [Count: {0}]", interfaceInfo.EndpointInfoList.Count)); foreach (var i in interfaceInfo.EndpointInfoList) { FillEndpointInfo(tvEndpoints, i); } } if (interfaceInfo.Descriptor != null) { TreeNode tvDesc = tvInterface.Nodes.Add(string.Format("Descriptor [Length: {0}]", interfaceInfo.Descriptor.Length)); tvDesc.Nodes.Add(string.Format("{0}: 0x{1:X2}, {2}: 0x{3:X2}", "InterfaceID", interfaceInfo.Descriptor.InterfaceID, "AlternateID", interfaceInfo.Descriptor.AlternateID)); tvDesc.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "Class", interfaceInfo.Descriptor.Class, (int)interfaceInfo.Descriptor.Class)); tvDesc.Nodes.Add(string.Format("{0}: 0x{1:X2}", "Subclass", interfaceInfo.Descriptor.SubClass)); tvDesc.Nodes.Add(string.Format("{0}: 0x{1:X2}", "Protocol", interfaceInfo.Descriptor.Protocol)); tvDesc.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "Class", interfaceInfo.Descriptor.DescriptorType, (int)interfaceInfo.Descriptor.DescriptorType)); tvDesc.Nodes.Add(string.Format("{0}: {1}", "EndpointCount", interfaceInfo.Descriptor.EndpointCount)); tvDesc.Nodes.Add(string.Format("{0}: 0x{1:X2}", "StringIndex", interfaceInfo.Descriptor.StringIndex)); } //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(); TreeNode tvRegistry = tvDevice.Nodes.Add("Registry Properties"); mUsbRegistry = device; UsbSymbolicName symName = UsbSymbolicName.Parse(mUsbRegistry.SymbolicName); if (string.IsNullOrEmpty(symName.SerialNumber) == false) { tvRegistry.Nodes.Add(string.Format("{0}: {1}", "SerialNumber", symName.SerialNumber)); } else { tvRegistry.Nodes.Add(string.Format("{0}: {1}", "SerialNumber", "None")); } if (symName.ClassGuid == null) { tvRegistry.Nodes.Add(string.Format("{0}: (NULL)", "ClassGuid")); } else if (symName.ClassGuid != Guid.Empty) { tvRegistry.Nodes.Add(string.Format("{0}: {1}", "ClassGuid", symName.ClassGuid.ToString().ToUpperInvariant())); } else { tvRegistry.Nodes.Add(string.Format("{0}: {1} (None)", "ClassGuid", symName.ClassGuid)); } foreach (KeyValuePair <string, object> current in mUsbRegistry.DeviceProperties) { string key = current.Key; object oValue = current.Value; if (oValue is string[]) { if (string.IsNullOrEmpty(key) == false && string.IsNullOrEmpty(key.Trim()) == false) { string[] saValue = oValue as string[]; TreeNode tvKey = tvRegistry.Nodes.Add(key + " [" + saValue.Length.ToString() + " Items]"); foreach (string s in saValue) { if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false) { tvKey.Nodes.Add(s); } } } } else if (oValue is string) { string s = oValue as string; if (string.IsNullOrEmpty(key) == false && string.IsNullOrEmpty(key.Trim()) == false) { key = key.Trim(); if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false) { tvRegistry.Nodes.Add(key + ": " + s); } } } } } if (treeDevices.Nodes.Count <= 1) { treeDevices.Nodes.Add("No Devices Found"); treeDevices.Nodes.Add("A device must be installed which uses the LibUsb-Win32 driver."); treeDevices.Nodes.Add("Or"); treeDevices.Nodes.Add("The LibUsb-Win32 kernel service must be enabled."); treeDevices.Nodes.Add("See the AVR Project IDE wiki for details"); treeDevices.Nodes.Add(Properties.Resources.UsbInfoPanelWikiURL); } } catch (Exception ex) { //ErrorReportWindow.Show(ex, "Error While Getting USB Device Data"); string eventText = DateTime.Now.ToString("HH:mm:ss.fff - ") + "Exception During Device Refresh"; TreeNode tvEvent = treeErrors.Nodes.Insert(0, eventText); treeErrors.Nodes.Add(ex.Message); } }