Exemple #1
0
        private void WireUpCardReader(UsbDevice device)
        {
            _reader?.Dispose();
            _reader = new CardReader(device);
            _reader.OnSlotStateChange += (_, change) =>
            {
                if (change.IccPresent)
                {
                    _reader.ActivateSlot(change.SlotNumber);

                    var status = _reader.GetSlotStatus(change.SlotNumber);
                    if (status == SlotStatus.IccPresentAndActive)
                    {
                        var response = _reader.SendApdu(change.SlotNumber, new GetData());
                        var info     = Parser.GetPacInfo(Format.Corporate1000, response.Data);

                        RunOnUiThread(() =>
                        {
                            _statusText.Text = "Card Present";
                            _cardIdText.Text = info.CardId.ToString();
                        });
                    }
                }
                else
                {
                    _reader.DeactivateSlot(change.SlotNumber);

                    RunOnUiThread(() =>
                    {
                        _statusText.Text = "Card Not Present";
                        _cardIdText.Text = "";
                    });
                }
            };
            _reader.Start();
        }