comparison USBLib/Windows/USB/UsbDevice.cs @ 87:9b898d8b2541

Small improvements in Windows USB device handling
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 05 Jun 2014 00:46:15 +0200
parents e811297f5aa4
children
comparison
equal deleted inserted replaced
86:5d1b72ba44dc 87:9b898d8b2541
47 47
48 public int NumConfigurations { get { return DeviceDescriptor.NumConfigurations; } } 48 public int NumConfigurations { get { return DeviceDescriptor.NumConfigurations; } }
49 public int VendorID { get { return DeviceDescriptor.VendorID; } } 49 public int VendorID { get { return DeviceDescriptor.VendorID; } }
50 public int ProductID { get { return DeviceDescriptor.ProductID; } } 50 public int ProductID { get { return DeviceDescriptor.ProductID; } }
51 51
52 private short[] languages = null;
53
52 private String GetStringSafe(Byte id) { 54 private String GetStringSafe(Byte id) {
53 if (id == 0) return null; 55 if (id == 0) return null;
54 String s = UsbStringDescriptor.GetStringFromDevice(this, id, 0); 56 if (languages == null) {
57 Byte[] buff = new Byte[256];
58 int len = GetDescriptor((Byte)UsbDescriptorType.String, 0, 0, buff, 0, buff.Length);
59 if (len > 1) {
60 languages = new short[len / 2 - 1];
61 for (int i = 0; i < languages.Length; i++) languages[i] = BitConverter.ToInt16(buff, i * 2 + 2);
62 }
63 }
64 short language = (languages == null || languages.Length == 0) ? (short)0 : languages[0];
65 String s = UsbStringDescriptor.GetStringFromDevice(this, id, language);
55 if (s == null) return s; 66 if (s == null) return s;
56 return s.Trim(' ', '\0'); 67 return s.Trim(' ', '\0');
57 } 68 }
58 69
59 public string Manufacturer { get { return GetStringSafe(DeviceDescriptor.ManufacturerStringID); } } 70 public string Manufacturer { get { return GetStringSafe(DeviceDescriptor.ManufacturerStringID); } }