Mercurial > hg > ucis.core
comparison USBLib/Communication/LibUsbDotNet.cs @ 60:3424fa5a12c9
Updated Windows USB enumeration classes and VBoxUSB backend
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 12 Oct 2013 16:35:24 +0200 |
parents | a9c4fed19e99 |
children | 2b24666cd759 |
comparison
equal
deleted
inserted
replaced
59:4e1a5dec786a | 60:3424fa5a12c9 |
---|---|
18 | 18 |
19 namespace LibUsbDotNet { | 19 namespace LibUsbDotNet { |
20 public class UsbDevice : IUsbDevice { | 20 public class UsbDevice : IUsbDevice { |
21 public nIUsbInterface Device { get; private set; } | 21 public nIUsbInterface Device { get; private set; } |
22 public UsbDevice(nIUsbInterface dev) { | 22 public UsbDevice(nIUsbInterface dev) { |
23 if (dev == null) throw new ArgumentNullException("dev"); | |
23 Device = dev; | 24 Device = dev; |
24 } | 25 } |
25 public bool GetDescriptor(byte descriptorType, byte index, short langId, Byte[] buffer, int bufferLength, out int transferLength) { | 26 public bool GetDescriptor(byte descriptorType, byte index, short langId, Byte[] buffer, int bufferLength, out int transferLength) { |
26 try { | 27 try { |
27 transferLength = Device.GetDescriptor(descriptorType, index, langId, buffer, 0, bufferLength); | 28 transferLength = Device.GetDescriptor(descriptorType, index, langId, buffer, 0, bufferLength); |
85 } | 86 } |
86 public bool ClaimInterface(int interfaceID) { | 87 public bool ClaimInterface(int interfaceID) { |
87 nIUsbDevice dev = Device as nIUsbDevice; | 88 nIUsbDevice dev = Device as nIUsbDevice; |
88 if (dev == null) return false; | 89 if (dev == null) return false; |
89 try { | 90 try { |
91 if (dev.Configuration == 0) dev.Configuration = 1; | |
90 dev.ClaimInterface(interfaceID); | 92 dev.ClaimInterface(interfaceID); |
91 return true; | 93 return true; |
92 } catch { | 94 } catch { |
93 return false; | 95 return false; |
94 } | 96 } |