Example #1
0
        /// <summary>
        /// Establishes a connection (using a specific resource manager context) between the calling application and a smart card contained by a specific reader. If no card exists in the specified reader, an error is returned.
        /// </summary>
        /// <param name="readerName">The name of the reader that contains the target card.</param>
        /// <param name="shareMode">A flag that indicates whether other applications may form connections to the card.</param>
        /// <param name="preferredProtocols">A bitmask of acceptable protocols for the connection. Possible values may be combined with the OR operation.</param>
        public void Connect(string readerName, ShareModeOptions shareMode, ProtocolOptions preferredProtocols)
        {
            if (_hContext == IntPtr.Zero)
            {
                throw new SCardException("No card reader context established.  Must call SCard.EstablishContext() first.");
            }
            if (_hCard != IntPtr.Zero)
            {
                throw new SCardException("Already connected to card.  Must call SCard.Disconnect() first.");
            }
            IntPtr hCard = IntPtr.Zero;
            int    rtn   = SCardDll.SCardConnectA(_hContext, readerName, (UInt32)shareMode, (UInt32)preferredProtocols, ref hCard, ref _protocol);

            EvalReturnCode(rtn);
            _hCard = hCard;
        }
Example #2
0
 /// <summary>
 /// Establishes a connection (using a specific resource manager context) between the calling application and a smart card contained by a specific reader. If no card exists in the specified reader, an error is returned.
 /// </summary>
 /// <param name="readerName">The name of the reader that contains the target card.</param>
 /// <param name="shareMode">A flag that indicates whether other applications may form connections to the card.</param>
 /// <param name="preferredProtocols">A bitmask of acceptable protocols for the connection. Possible values may be combined with the OR operation.</param>
 public void Connect(string readerName, ShareModeOptions shareMode, ProtocolOptions preferredProtocols)
 {
     if (_hContext == IntPtr.Zero)
         throw new SCardException("No card reader context established.  Must call SCard.EstablishContext() first.");
     if (_hCard != IntPtr.Zero)
         throw new SCardException("Already connected to card.  Must call SCard.Disconnect() first.");
     IntPtr hCard = IntPtr.Zero;
     int rtn = SCardDll.SCardConnectA(_hContext, readerName, (UInt32)shareMode, (UInt32)preferredProtocols, ref hCard, ref _protocol);
     EvalReturnCode(rtn);
     _hCard = hCard;
 }