public bool Transmit(CAPDU capdu, ref RAPDU rapdu) { _capdu = capdu; if (!Transmit()) return false; rapdu = _rapdu; return true; }
/**m* SCardChannel/Transmit * * NAME * SCardChannel.Transmit() * * SYNOPSIS * bool Transmit() * RAPDU Transmit(CAPDU capdu) * bool Transmit(CAPDU capdu, ref RAPDU rapdu) * void Transmit(CAPDU capdu, TransmitDoneCallback callback) * * DESCRIPTION * Sends a command APDU (CAPDU) to the connected card, and retrieves its response APDU (RAPDU) * * SOURCE * * SCardChannel card = new SCardChannel( ... reader ... ); * if (!card.Connect( SCARD.PROTOCOL_T0|SCARD.PROTOCOL_T1 )) * { * // handle error * } * * * // Example 1 * // --------- * * card.Command = new CAPDU("00 A4 00 00 02 3F 00"); * if (!card.Transmit()) * { * // handle error * } * MessageBox.Show("Card answered: " + card.Response.AsString(" ")); * * * // Example 2 * // --------- * * RAPDU response = card.Transmit(new CAPDU("00 A4 00 00 02 3F 00"))) * if (response == null) * { * // handle error * } * MessageBox.Show("Card answered: " + response.AsString(" ")); * * * // Example 3 * // --------- * * CAPDU command = new CAPDU("00 A4 00 00 02 3F 00"); * RAPDU response = new RAPDU(); * if (!card.Transmit(command, ref response)) * { * // handle error * } * MessageBox.Show("Card answered: " + response.AsString(" ")); * * * // Example 4 * // --------- * * // In this example the Transmit is performed by a background thread * // We supply a delegate so the main class (window/form) will be notified * // when Transmit will return * * delegate void OnTransmitDoneInvoker(RAPDU response); * * void OnTransmitDone(RAPDU response) * { * // Ensure we're back in the context of the main thread (application's message pump) * if (this.InvokeRequired) * { * this.BeginInvoke(new OnTransmitDoneInvoker(OnTransmitDone), response); * return; * } * * if (response == null) * { * // handle error * } * * MessageBox.Show("Card answered: " + response.AsString(" ")); * } * * card.Transmit(new CAPDU("00 A4 00 00 02 3F 00"), new SCardChannel.TransmitDoneCallback(OnTransmitDone)); * * * SEE ALSO * SCardChannel.Connect * SCardChannel.Transmit * SCardChannel.Command * SCardChannel.Response * **/ public bool Transmit() { byte[] rsp_buffer = new byte[258]; uint rsp_length = 258; uint rc; _rapdu = null; rc = SCARD.Transmit(_hCard, IntPtr.Zero, _capdu.Bytes, _capdu.Size, IntPtr.Zero, rsp_buffer, ref rsp_length); if (rc != SCARD.S_SUCCESS) { _last_error = rc; return false; } _rapdu = new RAPDU(rsp_buffer, (int)rsp_length); return true; }