Пример #1
0
        public static string cardProtocol()
        {
            WinSCard scard = new WinSCard();
            try
            {

                scard.EstablishContext();
                scard.ListReaders();
                string readerName = scard.ReaderNames[1];
                scard.WaitForCardPresent(readerName);

                scard.Connect(readerName);
                byte[] cmdApdu = { 0xFF, 0xCA, 0x00, 0x00, 00 }; // Get Card UID ...
                byte[] respApdu = new byte[10];
                int respLength = respApdu.Length;

                scard.Transmit(cmdApdu, cmdApdu.Length, respApdu, ref respLength);

                //find a better place for this
                App.UID = HexFormatting.ToHexString(respApdu, true);

                //he wanted some kinda beeping sound when someone swipes their card
                System.Media.SystemSounds.Beep.Play();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return App.UID;
        }
Пример #2
0
        //generic form
        public void AddReaders(ComboBox comboBox)
        {
            comboBox.Items.Clear();
            comboBox.Enabled = false;

            WinSCard pcscReader = new WinSCard();
            pcscReader.EstablishContext();
            pcscReader.ListReaders();

            if (pcscReader.ReaderNames != null)
            {
                comboBox.Items.AddRange( pcscReader.ReaderNames );
                comboBox.SelectedIndex = 0;

                if (pcscReader.ReaderNames.Length > 1)
                {
                    comboBox.Enabled = true;
                }
            }
            else
            {
                comboBox.Items.Add( "No PC/SC Reader found!" );
            }
            pcscReader.ReleaseContext();
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PCSCReader"/> class.
 /// </summary>
 public PCSCReader()
 {
     this.SCard = new GS.SCard.WinSCard();
     readerName = null;
 }