public static async Task <CTAPHID> OpenAsync(IHidDevice hidDevice) { var device = new CTAPHID(hidDevice); await device.InitAsync(); return(device); }
public async Task <bool> WinkAsync() { HidLibrary.IHidDevice hidDevice = null; try { hidDevice = CTAPHID.Find(DevicePath); if (hidDevice == null) { return(false); } using (var openedDevice = await CTAPHID.OpenAsync(hidDevice)) { var ret = await openedDevice.WinkAsync(null); } } catch (Exception) { return(false); } finally { hidDevice?.Dispose(); } return(true); }
public static async Task <SendCommandandResponseResult> SendCommandandResponse(List <HidParam> hidParams, byte[] send, int timeoutms, EventHandler keepalive) { var result = new SendCommandandResponseResult(); IHidDevice hidDevice = null; try { hidDevice = CTAPHID.find(hidParams); if (hidDevice == null) { return(null); } using (var openedDevice = await CTAPHID.OpenAsync(hidDevice)) { openedDevice.ReceiveResponseTotalTimeoutMs = timeoutms; openedDevice.KeepAlive += keepalive; result.responseData = await openedDevice.CborAsync(send); result.isTimeout = openedDevice.isReceiveResponseTotalTimeout; } } catch (Exception) { } finally { if (hidDevice != null) { hidDevice.Dispose(); } } return(result); }
public static List <string> GetAllFIDODevicePaths() { List <string> devices = new List <string>(); devices.AddRange(CTAPHID.GetAllFIDODevices().Select(d => d.DevicePath).ToList()); return(devices); }
public override string ToString() { var hid = CTAPHID.Find(DevicePath); if (hid is null) { return(string.Empty); } return($"{hid.DevicePath} - VendorId: {hid.Attributes.VendorHexId}, ProductId: {hid.Attributes.ProductHexId}, Description: '{hid.Description}'"); }
public static List <string> GetAllHIDDeviceInfo() { var ret = new List <string>(); var hids = CTAPHID.finds(); foreach (var hid in hids) { ret.Add($"VendorId = {hid.Attributes.VendorHexId} , ProductId = {hid.Attributes.ProductHexId} , DevicePath = {hid.DevicePath} , Description = {hid.Description}"); } return(ret); }
public bool IsConnected() { if (CTAPHID.find(this.hidParams) != null) { return(true); } else { return(false); } }
public string GetDevicePath() { var hid = CTAPHID.Find(DevicePath); if (hid is null) { return(string.Empty); } return($"{hid.DevicePath}"); }
public bool IsConnected() { if (CTAPHID.Find(this.DevicePath) == null) { return(false); } else { return(true); } }
public string GetDeviceProductName() { var hid = CTAPHID.Find(DevicePath); if (hid is null) { return(string.Empty); } var productBytes = new byte[(126 + 1) * 2]; hid.ReadProduct(out productBytes); string productName = System.Text.Encoding.Unicode.GetString(productBytes); return(productName); }
public async Task <(DeviceStatus devSt, byte[] ctapRes)> SendCommandandResponseAsync(string devicePath, byte[] payload, int timeoutms) { if (CTAPHID.Find(devicePath) == null) { Logger.Err("Connect Error"); return(DeviceStatus.NotConnected, null); } var res = await CTAPHID.SendCommandandResponse(devicePath, payload, timeoutms, KeepAlive); if (res == null) { Logger.Err("Response Error"); return(DeviceStatus.Unknown, null); } if (res.isTimeout) { Logger.Err("Wait Response Timeout"); return(DeviceStatus.Timeout, null); } return(DeviceStatus.Ok, res.responseData); }