private void OpenUSBDevice(string devicePath) { SafeFileHandle deviceHandle = CreateFile(devicePath, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, IntPtr.Zero); if (deviceHandle.IsInvalid) { WirekiteException.ThrowWin32Exception("Cannot open Wirekite device for communication"); } IntPtr interfaceHandle = IntPtr.Zero; bool success = WinUsb_Initialize(deviceHandle, ref interfaceHandle); if (!success) { WirekiteException.ThrowWin32Exception("Cannot open USB interface of Wirekite device"); } WirekiteDevice device = new WirekiteDevice(this, devicePath, deviceHandle, interfaceHandle); _devices.Add(device); if (_deviceNotification != null) { _deviceNotification.OnDeviceConnected(device); } }
internal void RemoveDevice(WirekiteDevice device) { _devices.Remove(device); }