Mercurial > hg > ucis.core
comparison USBLib/Communication/WinUsb/WinUsbDevice.cs @ 49:7e4dae99f919
USBLib: fix unhandled exception in WinUSB shutdown after failure to open device
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Mon, 19 Aug 2013 16:56:50 +0200 |
parents | 053cc617af54 |
children | abe0d55a2201 |
comparison
equal
deleted
inserted
replaced
48:f553f6e0a396 | 49:7e4dae99f919 |
---|---|
58 [DllImport(WIN_USB_DLL, SetLastError = true)] | 58 [DllImport(WIN_USB_DLL, SetLastError = true)] |
59 private static extern bool WinUsb_WritePipe(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, IntPtr pBuffer, int BufferLength, out int LengthTransferred, IntPtr pOVERLAPPED); | 59 private static extern bool WinUsb_WritePipe(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, IntPtr pBuffer, int BufferLength, out int LengthTransferred, IntPtr pOVERLAPPED); |
60 //[DllImport(WIN_USB_DLL, SetLastError = true)] | 60 //[DllImport(WIN_USB_DLL, SetLastError = true)] |
61 //private static extern bool WinUsb_SetPipePolicy(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value); | 61 //private static extern bool WinUsb_SetPipePolicy(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value); |
62 SafeFileHandle DeviceHandle; | 62 SafeFileHandle DeviceHandle; |
63 private SafeWinUsbInterfaceHandle[] InterfaceHandles = null; | 63 private SafeWinUsbInterfaceHandle[] InterfaceHandles = new SafeWinUsbInterfaceHandle[0]; |
64 private int[] EndpointToInterfaceIn = new int[0]; | 64 private int[] EndpointToInterfaceIn = new int[0]; |
65 private int[] EndpointToInterfaceOut = new int[0]; | 65 private int[] EndpointToInterfaceOut = new int[0]; |
66 public IUsbDeviceRegistry Registry { get; private set; } | 66 public IUsbDeviceRegistry Registry { get; private set; } |
67 | 67 |
68 public WinUsbDevice(String path, WinUsbRegistry registry) { | 68 public WinUsbDevice(String path, WinUsbRegistry registry) { |
130 return GetInterfaceHandle(EndpointToInterfaceOut[epidx]); | 130 return GetInterfaceHandle(EndpointToInterfaceOut[epidx]); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 public override void Close() { | 134 public override void Close() { |
135 foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) ih.Close(); | 135 foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) if (ih != null) ih.Close(); |
136 InterfaceHandles = new SafeWinUsbInterfaceHandle[0]; | 136 InterfaceHandles = new SafeWinUsbInterfaceHandle[0]; |
137 if (DeviceHandle != null) DeviceHandle.Close(); | 137 if (DeviceHandle != null) DeviceHandle.Close(); |
138 } | 138 } |
139 | 139 |
140 public override Byte Configuration { | 140 public override Byte Configuration { |