Mercurial > hg > ucis.core
comparison USBLib/Communication/USBIO/USBIODevice.cs @ 68:e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 16 Oct 2013 16:58:39 +0200 |
parents | 2d16447eff12 |
children |
comparison
equal
deleted
inserted
replaced
67:2d16447eff12 | 68:e811297f5aa4 |
---|---|
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.ComponentModel; | 3 using System.ComponentModel; |
4 using System.IO; | 4 using System.IO; |
5 using System.Runtime.InteropServices; | 5 using System.Runtime.InteropServices; |
6 using Microsoft.Win32.SafeHandles; | 6 using Microsoft.Win32.SafeHandles; |
7 using UCIS.USBLib.Descriptor; | |
7 using UCIS.USBLib.Internal.Windows; | 8 using UCIS.USBLib.Internal.Windows; |
8 | 9 |
9 namespace UCIS.USBLib.Communication.USBIO { | 10 namespace UCIS.USBLib.Communication.USBIO { |
10 public class USBIODevice : UsbInterface, IUsbDevice { | 11 public class USBIODevice : UsbInterface, IUsbDevice { |
11 public string DeviceFilename { get; private set; } | 12 public string DeviceFilename { get; private set; } |
105 } | 106 } |
106 | 107 |
107 public override Byte Configuration { | 108 public override Byte Configuration { |
108 get { return base.Configuration; } | 109 get { return base.Configuration; } |
109 set { | 110 set { |
110 IList<LibUsbDotNet.Info.UsbConfigInfo> configs = (new LibUsbDotNet.UsbDevice(this)).Configs; | 111 UsbConfigurationInfo configuration = UsbDeviceInfo.FromDevice(this).FindConfiguration(value); |
111 for (int i = 0; i < configs.Count; i++) { | 112 if (configuration == null) throw new InvalidOperationException("Requested configuration ID not found"); |
112 LibUsbDotNet.Info.UsbConfigInfo config = configs[i]; | 113 unsafe { |
113 if (config.Descriptor.ConfigurationValue == value) { | 114 USBIO_SET_CONFIGURATION req = new USBIO_SET_CONFIGURATION(); |
114 unsafe { | 115 req.ConfigurationIndex = configuration.Index; |
115 USBIO_SET_CONFIGURATION req = new USBIO_SET_CONFIGURATION(); | 116 req.NbOfInterfaces = Math.Min((ushort)32, configuration.Descriptor.NumInterfaces); |
116 req.ConfigurationIndex = (ushort)i; | 117 for (int j = 0; j < req.NbOfInterfaces; j++) { |
117 req.NbOfInterfaces = Math.Min((ushort)32, config.Descriptor.NumInterfaces); | 118 UsbInterfaceInfo intf = configuration.Interfaces[j]; |
118 for (int j = 0; j < req.NbOfInterfaces; j++) { | 119 *((USBIO_INTERFACE_SETTING*)(req.InterfaceList + sizeof(USBIO_INTERFACE_SETTING) * j)) = |
119 LibUsbDotNet.Info.UsbInterfaceInfo intf = config.InterfaceInfoList[j]; | 120 new USBIO_INTERFACE_SETTING() { InterfaceIndex = intf.Descriptor.InterfaceNumber, AlternateSettingIndex = 0, MaximumTransferSize = UInt16.MaxValue }; |
120 *((USBIO_INTERFACE_SETTING*)(req.InterfaceList + sizeof(USBIO_INTERFACE_SETTING) * j)) = | 121 } |
121 new USBIO_INTERFACE_SETTING() { InterfaceIndex = intf.Descriptor.InterfaceNumber, AlternateSettingIndex = 0, MaximumTransferSize = UInt16.MaxValue }; | 122 try { |
122 } | 123 DeviceIoControl(DeviceHandle, IOCTL_USBIO_SET_CONFIGURATION, (IntPtr)(&req), sizeof(USBIO_SET_CONFIGURATION), IntPtr.Zero, 0); |
123 try { | 124 } catch (Win32Exception ex) { |
124 DeviceIoControl(DeviceHandle, IOCTL_USBIO_SET_CONFIGURATION, (IntPtr)(&req), sizeof(USBIO_SET_CONFIGURATION), IntPtr.Zero, 0); | 125 if (ex.NativeErrorCode == unchecked((int)0xE0001005L)) return; |
125 } catch (Win32Exception ex) { | 126 throw; |
126 if (ex.NativeErrorCode == unchecked((int)0xE0001005L)) return; | |
127 throw; | |
128 } | |
129 } | |
130 return; | |
131 } | 127 } |
132 } | 128 } |
133 throw new InvalidOperationException("Requested configuration ID not found"); | |
134 } | 129 } |
135 } | 130 } |
136 | 131 |
137 public void ClaimInterface(int interfaceID) { | 132 public void ClaimInterface(int interfaceID) { |
138 } | 133 } |