public void Connect(int position) { if (hContext.CheckValidity() != PCSC.SCardError.Success) { init(); } // Create a reader object using the existing context reader = new SCardReader(hContext); // Connect to the card SCardError err = reader.Connect(szReaders[position], SCardShareMode.Shared, SCardProtocol.T0 | SCardProtocol.T1); CheckErr(err); switch (reader.ActiveProtocol) { case SCardProtocol.T0: pioSendPci = SCardPCI.T0; break; case SCardProtocol.T1: pioSendPci = SCardPCI.T1; break; default: throw new PCSCException(SCardError.ProtocolMismatch, "Protocol not supported: " + reader.ActiveProtocol.ToString()); } }
public static bool EnsureOK(this SCardContext context, bool throwException = true) { if (context.IsValid()) { return(true); } return(context.CheckValidity().EnsureOK(throwException, "Unable to establish a valid PC/SC context")); }