Mercurial > hg > ucis.core
comparison USBLib/Descriptor/UsbDescriptor.cs @ 58:fd63c453ff65
Improved Windows USB enumeration classes
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 09 Oct 2013 20:54:15 +0200 |
parents | 15ddb1e0e2a5 |
children | 99ed461509fe |
comparison
equal
deleted
inserted
replaced
57:b1efeada517e | 58:fd63c453ff65 |
---|---|
31 return Encoding.Unicode.GetString(buffer, offset + 2, slen - 2); | 31 return Encoding.Unicode.GetString(buffer, offset + 2, slen - 2); |
32 } | 32 } |
33 public static String GetStringFromDevice(IUsbInterface device, byte index, short langId) { | 33 public static String GetStringFromDevice(IUsbInterface device, byte index, short langId) { |
34 Byte[] buff = new Byte[256]; | 34 Byte[] buff = new Byte[256]; |
35 int len = device.GetDescriptor((Byte)UsbDescriptorType.String, index, langId, buff, 0, buff.Length); | 35 int len = device.GetDescriptor((Byte)UsbDescriptorType.String, index, langId, buff, 0, buff.Length); |
36 if (len == 0) return null; | |
36 return GetString(buff, 0, len); | 37 return GetString(buff, 0, len); |
37 } | 38 } |
38 } | 39 } |
39 [StructLayout(LayoutKind.Sequential, Pack = 1)] | 40 [StructLayout(LayoutKind.Sequential, Pack = 1)] |
40 public struct UsbDeviceDescriptor { | 41 public struct UsbDeviceDescriptor { |
197 public unsafe static UsbHubDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | 198 public unsafe static UsbHubDescriptor FromByteArray(Byte[] buffer, int offset, int length) { |
198 if (length < Marshal.SizeOf(typeof(UsbHubDescriptor))) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | 199 if (length < Marshal.SizeOf(typeof(UsbHubDescriptor))) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); |
199 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | 200 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); |
200 fixed (Byte* ptr = buffer) return *(UsbHubDescriptor*)(ptr + offset); | 201 fixed (Byte* ptr = buffer) return *(UsbHubDescriptor*)(ptr + offset); |
201 } | 202 } |
203 public static unsafe int Size { get { return sizeof(UsbHubDescriptor); } } | |
202 } | 204 } |
203 } | 205 } |