Пример #1
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);
        }
Пример #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);
        }