public UWPHidDevicePoller(int productId, int vendorId, UWPHidDevice uwpHidDevice) { _PollTimer.Elapsed += _PollTimer_Elapsed; _PollTimer.Start(); ProductId = productId; VendorId = vendorId; UWPHidDevice = uwpHidDevice; }
public override async Task <ConnectionInfo> TestConnection(string deviceId) { try { await _TestConnectionSemaphore.WaitAsync(); if (_ConnectionTestedDeviceIds.TryGetValue(deviceId, out var connectionInfo)) { return(connectionInfo); } using (var hidDevice = await UWPHidDevice.GetHidDevice(deviceId).AsTask()) { var canConnect = hidDevice != null; if (!canConnect) { return new ConnectionInfo { CanConnect = false } } ; Logger.Log($"Testing device connection. Id: {deviceId}. Can connect: {canConnect}", null, nameof(UWPHidDeviceFactory)); connectionInfo = new ConnectionInfo { CanConnect = canConnect, UsagePage = hidDevice.UsagePage }; _ConnectionTestedDeviceIds.Add(deviceId, connectionInfo); return(connectionInfo); } } catch (Exception ex) { Logger.Log("", ex, nameof(UWPHidDeviceFactory)); return(new ConnectionInfo { CanConnect = false }); } finally { _TestConnectionSemaphore.Release(); } }