Пример #1
0
 public CardQProcessor(ICardInterfaceManger cardInterfaceManger, string deviceId)
 {
     this.deviceId = deviceId;
     cancellationTokenForCardInterfaceManager = new CancellationTokenSource();
     CardQ = new CardQ(1000);
     CardInterfaceManger = cardInterfaceManger;
 }
Пример #2
0
        public ApduResponse SendCommand(ApduCommand apduCommand)
        {
            CardQ.EnqueueToInput(new CardRequest(apduCommand, CardinterfaceServiceRequestEnum.ADPU));

            CardResponse response = CardQ.DequeueFromOutput(false); //this will poll indefinetely

            return(response.ApduResponse);
        }
Пример #3
0
        private async Task StartServicingeQ()
        {
            //run for as long as card reader is active
            while (1 == 1)
            {
                try
                {
                    CardRequest cardRequest = CardQ.DequeueFromInput(false, true);
                    if (cardRequest == null) //timeout
                    {
                        if (cancellationTokenForCardInterfaceManager.Token.IsCancellationRequested)
                        {
                            cancellationTokenForCardInterfaceManager.Dispose();
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    CardResponse response;
                    try
                    {
                        response = new CardResponse(await Transceive(cardRequest.ApduCommand), CardInterfaceServiceResponseEnum.RA);
                    }
                    catch
                    {
                        ApduResponse apduRes = new ApduResponse();
                        byte[]       dataOut = new byte[] { 0x00, 0x00 };
                        apduRes.Deserialize(dataOut);
                        response = new CardResponse(apduRes, CardInterfaceServiceResponseEnum.L1RSP);
                    }
                    CardQ.EnqueueToOutput(response);
                }
                catch (Exception ex)
                {
                    StopServiceQProcess();
                    OnExceptionOccured(ex);
                }
            }
        }