/// <summary> /// Disconnects the an established connection to a smart card and closes /// an established resource manager context, freeing any resources allocated /// under that context. /// </summary> /// <param name="disposition">Action to take on the card in the connected reader on close.</param> public void Disconnect(SCARD_DISCONNECT disposition) { try { this.SCard.Disconnect(disposition); this.SCard.ReleaseContext(); this.readerName = null; } catch (WinSCardException ex) { throw ex; } catch (Exception ex) { throw ex; } }
/// <summary> /// The SCardDisconnect function terminates a connection previously opened between the calling /// application and a smart card in the target reader. /// </summary> /// <param name="disposition"> /// Action to take on the card in the connected reader on close. /// </param> /// <returns> /// If the function succeeds, the function returns SCARD_S_SUCCESS. /// If the function fails, it returns an error code. /// </returns> public void Disconnect(SCARD_DISCONNECT disposition) { connectedReaderName = null; if (this.phCARD != (IntPtr)0) { int ret = WinSCardAPIWrapper.SCardDisconnect(phCARD, (uint)disposition); this.phCARD = (IntPtr)0; this.readerStrings = null; if (ret == 0) { Trace.WriteLineIf(scardTrace, String.Format(" SCard.Disconnect(SCARD_DISCONNECT.{0})...", disposition)); } else { throw new WinSCardException(scardTrace, "SCard.Disconnect", ret); } } }
public static extern HRESULT SCardDisconnect(IntPtr hCard, SCARD_DISCONNECT options);
/// <summary> /// The SCardReconnect function reestablishes an existing connection between the calling application and /// a smart card. This function moves a card handle from direct access to general access, or acknowledges /// and clears an error condition that is preventing further access to the card. /// </summary> /// <param name="dwShareMode"> /// A flag that indicates whether other applications may form connections to the card. /// </param> /// <param name="dwPrefProtocol"> /// A bitmask of acceptable protocols for the connection. Possible values may be combined with the OR operation. /// </param> /// <param name="disconnectAction"> /// Action to take on the card in the connected reader on close. /// </param> /// <returns> /// If the function succeeds, the function returns SCARD_S_SUCCESS. /// If the function fails, it returns an error code. /// </returns> public void Reconnect(SCARD_SHARE_MODE dwShareMode, SCARD_PROTOCOL dwPrefProtocol, SCARD_DISCONNECT disconnectAction) { int ret = WinSCardAPIWrapper.SCardReconnect(phCARD, (uint)dwShareMode, (uint)dwPrefProtocol, (uint)disconnectAction, out activeSCardProtocol); if (ret == 0) { Trace.WriteLineIf(scardTrace, String.Format(" SCard.Reconnect(SHARE_MODE.{0}, SCARD_PROTOCOL.{1}, SCARD_DISCONNECT.{2} )", dwShareMode, (SCARD_PROTOCOL)dwPrefProtocol, (SCARD_DISCONNECT)disconnectAction)); Trace.WriteLineIf(scardTrace, String.Format(" Active Protocol: SCARD_PROTOCOL.{0} ", (SCARD_PROTOCOL)activeSCardProtocol)); Trace.WriteLineIf(this.TraceSCard, HexFormatting.Dump(" ATR: 0x", this.Atr, this.Atr.Length, 24)); } else { throw new WinSCardException(scardTrace, "SCard.Reconnect", ret); } }
/// <summary> /// The SCardReconnect function reestablishes an existing connection between the calling application and /// a smart card. This function moves a card handle from direct access to general access, or acknowledges /// and clears an error condition that is preventing further access to the card. /// </summary> /// <param name="disconnectAction"> /// Action to take on the card in the connected reader on close. /// </param> /// <returns> /// If the function succeeds, the function returns SCARD_S_SUCCESS. /// If the function fails, it returns an error code. /// </returns> public void Reconnect(SCARD_DISCONNECT disconnectAction) { Reconnect(SCARD_SHARE_MODE.Exclusive, SCARD_PROTOCOL.Tx, disconnectAction); }
public void Reconnect(SCARD_SHARE_MODE dwShareMode, SCARD_PROTOCOL dwPrefProtocol, SCARD_DISCONNECT disconnectAction) { int ret = WinSCardAPIWrapper.SCardReconnect( phCARD, (uint)dwShareMode, (uint)dwPrefProtocol, (uint)disconnectAction, out activeSCardProtocol); if (ret == 0) { Trace.WriteLineIf(scardTrace, String.Format(" SCard.Reconnect(SHARE_MODE.{0}, SCARD_PROTOCOL.{1}, SCARD_DISCONNECT.{2} )", dwShareMode, (SCARD_PROTOCOL)dwPrefProtocol, (SCARD_DISCONNECT)disconnectAction)); Trace.WriteLineIf(scardTrace, String.Format(" Active Protocol: SCARD_PROTOCOL.{0} ", (SCARD_PROTOCOL)activeSCardProtocol)); Trace.WriteLineIf(this.TraceSCard, HexFormatting.Dump(" ATR: 0x",this.Atr,this.Atr.Length,24)); } else { throw new WinSCardException(scardTrace, "SCard.Reconnect", ret); } }
public void Reconnect(SCARD_DISCONNECT disconnectAction) { Reconnect(SCARD_SHARE_MODE.Exclusive, SCARD_PROTOCOL.Tx, disconnectAction); }
public void Disconnect(SCARD_DISCONNECT disposition) { connectedReaderName = null; if (this.phCARD != (IntPtr)0) { int ret = WinSCardAPIWrapper.SCardDisconnect(phCARD, (uint)disposition); this.phCARD = (IntPtr)0; this.readerStrings = null; if (ret == 0) { Trace.WriteLineIf(scardTrace, String.Format(" SCard.Disconnect(SCARD_DISCONNECT.{0})...", disposition)); } else { throw new WinSCardException( scardTrace, "SCard.Disconnect", ret ); } } }