changeset 51:e3f37686b15a

Merge HWLib and USBLib extensions
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 30 Sep 2013 21:24:35 +0200
parents 7e4dae99f919 (diff) 556b4fb511bd (current diff)
children d4778c3232ad
files
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/USBLib/Communication/WinUsb/WinUsbDevice.cs	Mon Sep 30 19:23:09 2013 +0200
+++ b/USBLib/Communication/WinUsb/WinUsbDevice.cs	Mon Sep 30 21:24:35 2013 +0200
@@ -60,7 +60,7 @@
 		//[DllImport(WIN_USB_DLL, SetLastError = true)]
 		//private static extern bool WinUsb_SetPipePolicy(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value);
 		SafeFileHandle DeviceHandle;
-		private SafeWinUsbInterfaceHandle[] InterfaceHandles = null;
+		private SafeWinUsbInterfaceHandle[] InterfaceHandles = new SafeWinUsbInterfaceHandle[0];
 		private int[] EndpointToInterfaceIn = new int[0];
 		private int[] EndpointToInterfaceOut = new int[0];
 		public IUsbDeviceRegistry Registry { get; private set; }
@@ -132,7 +132,7 @@
 		}
 
 		public override void Close() {
-			foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) ih.Close();
+			foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) if (ih != null) ih.Close();
 			InterfaceHandles = new SafeWinUsbInterfaceHandle[0];
 			if (DeviceHandle != null) DeviceHandle.Close();
 		}
--- a/Util/ArrayUtil.cs	Mon Sep 30 19:23:09 2013 +0200
+++ b/Util/ArrayUtil.cs	Mon Sep 30 21:24:35 2013 +0200
@@ -65,6 +65,17 @@
 			}
 			return ret;
 		}
+		public static T[] Merge<T>(params IList<T>[] parts) {
+			int count = 0;
+			foreach (IList<T> segment in parts) count += segment.Count;
+			T[] ret = new T[count];
+			int offset = 0;
+			foreach (IList<T> segment in parts) {
+				segment.CopyTo(ret, offset);
+				offset += segment.Count;
+			}
+			return ret;
+		}
 		public static Boolean Equal<T>(T[] a, T[] b, IEqualityComparer<T> comparer) {
 			if (ReferenceEquals(a, b)) return true;
 			if (a == null || b == null) return false;