Пример #1
0
        /// <summary>
        /// Opens a SmartcardReader that has a card inserted with a specified ATR.
        /// </summary>
        /// <param name="atr">The ATR to search for.</param>
        /// <returns>An instance of the SmartcardReader class -or- a null reference if no smartcard reader was found.</returns>
        /// <exception cref="ArgumentNullException"><i>atr</i> is a null reference.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public static SmartcardReader OpenReader(Atr atr)
        {
            if (atr == null)
            {
                throw new ArgumentNullException("atr", ResourceController.GetString("Error_ParamNull"));
            }
            string[]        readers = SmartcardReader.GetReaders();
            SmartcardReader sr      = null;

            foreach (string reader in readers)
            {
                sr = new SmartcardReader(reader);
                sr.Connect();
                if (atr.IsMatch(sr.Atr.GetValue()))
                {
                    break;
                }
                sr.Dispose();
                sr = null;
            }
            return(sr);
        }
Пример #2
0
 /// <summary>
 /// Opens a SmartcardReader that has a card inserted with a specified ATR.
 /// </summary>
 /// <param name="atr">The ATR to search for.</param>
 /// <returns>An instance of the SmartcardReader class -or- a null reference if no smartcard reader was found.</returns>
 /// <exception cref="ArgumentNullException"><i>atr</i> is a null reference.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public static SmartcardReader OpenReader(Atr atr) {
     if (atr == null)
         throw new ArgumentNullException("atr", ResourceController.GetString("Error_ParamNull"));
     string[] readers = SmartcardReader.GetReaders();
     SmartcardReader sr = null;
     foreach(string reader in readers) {
         sr = new SmartcardReader(reader);
         sr.Connect();
         if (atr.IsMatch(sr.Atr.GetValue()))
             break;
         sr.Dispose();
         sr = null;
     }
     return sr;
 }