Mercurial > hg > ucis.core
comparison USBLib/Descriptor/UsbDescriptor.cs @ 96:94df2951d118
USBLib: fix USB string descriptor retrieval
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Thu, 26 Jun 2014 21:04:20 +0200 |
parents | e811297f5aa4 |
children |
comparison
equal
deleted
inserted
replaced
95:ebdff34b9e4f | 96:94df2951d118 |
---|---|
46 int slen = buffer[offset]; | 46 int slen = buffer[offset]; |
47 if (slen > length) throw new InvalidOperationException("The string has been truncated"); | 47 if (slen > length) throw new InvalidOperationException("The string has been truncated"); |
48 return Encoding.Unicode.GetString(buffer, offset + 2, slen - 2); | 48 return Encoding.Unicode.GetString(buffer, offset + 2, slen - 2); |
49 } | 49 } |
50 public static String GetStringFromDevice(IUsbInterface device, byte index, short langId) { | 50 public static String GetStringFromDevice(IUsbInterface device, byte index, short langId) { |
51 Byte[] buff = new Byte[256]; | 51 Byte[] buff = new Byte[255]; |
52 int len = device.GetDescriptor((Byte)UsbDescriptorType.String, index, langId, buff, 0, buff.Length); | 52 int len = device.GetDescriptor((Byte)UsbDescriptorType.String, index, langId, buff, 0, buff.Length); |
53 if (len == 0) return null; | 53 if (len == 0) return null; |
54 return GetString(buff, 0, len); | 54 return GetString(buff, 0, len); |
55 } | 55 } |
56 } | 56 } |