Пример #1
0
        public static async Task <CTAPHID> OpenAsync(IHidDevice hidDevice)
        {
            var device = new CTAPHID(hidDevice);
            await device.InitAsync();

            return(device);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static List <string> GetAllFIDODevicePaths()
        {
            List <string> devices = new List <string>();

            devices.AddRange(CTAPHID.GetAllFIDODevices().Select(d => d.DevicePath).ToList());
            return(devices);
        }
Пример #5
0
        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}'");
        }
Пример #6
0
        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);
        }
Пример #7
0
 public bool IsConnected()
 {
     if (CTAPHID.find(this.hidParams) != null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #8
0
        public string GetDevicePath()
        {
            var hid = CTAPHID.Find(DevicePath);

            if (hid is null)
            {
                return(string.Empty);
            }

            return($"{hid.DevicePath}");
        }
Пример #9
0
 public bool IsConnected()
 {
     if (CTAPHID.Find(this.DevicePath) == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }