Ho un'applicazione che utilizza un lettore di smart card per consentire agli utenti di accedere a parti del sistema. In una posizione non ho problemi. Ma un altro, che ha un diverso tipo di produttore di schede ha un sacco di problemi. Continua a recuperare un ID zero. Poi guardando in eventlog ho visto questo: E questo è il codice:Lettore smart card, impossibile leggere alcune carte
card.Connect(reader, SHARE.Shared, PROTOCOL.T0orT1);
var apduGetID = new APDUCommand(0xFF, 0xCA, 0, 0, null, 4);
var apduRespGetID = card.Transmit(apduGetID);
long cardId = BitConverter.ToUInt32(apduRespGetID.Data.Reverse().ToArray(), 0);
il secondo problema è che poi cercando di eseguire il debug del codice, funziona perfettamente, solo allora rimuovere il punto di interruzione posso vedere il problema ma non dove. Qualcuno può aiutarmi?
P.S. ho trovato questo thread, ma non funziona: https://superuser.com/questions/715688/smart-card-errors
Aggiornamento: Qui ci sono la classe di trasmissione
public override APDUResponse Transmit(APDUCommand ApduCmd)
{
var RecvLength = (uint)(ApduCmd.Le + APDUResponse.SW_LENGTH);
byte[] ApduBuffer;
var ApduResponse = new byte[ApduCmd.Le + APDUResponse.SW_LENGTH];
var ioRequest = new SCard_IO_Request
{
m_dwProtocol = m_nProtocol,
m_cbPciLength = 8
};
// Build the command APDU
if (ApduCmd.Data == null)
{
ApduBuffer = new byte[APDUCommand.APDU_MIN_LENGTH + ((ApduCmd.Le != 0) ? 1 : 0)];
if (ApduCmd.Le != 0)
{
ApduBuffer[4] = ApduCmd.Le;
}
}
else
{
ApduBuffer = new byte[APDUCommand.APDU_MIN_LENGTH + 1 + ApduCmd.Data.Length];
for (var nI = 0; nI < ApduCmd.Data.Length; nI++)
{
ApduBuffer[APDUCommand.APDU_MIN_LENGTH + 1 + nI] = ApduCmd.Data[nI];
}
ApduBuffer[APDUCommand.APDU_MIN_LENGTH] = (byte)ApduCmd.Data.Length;
}
ApduBuffer[0] = ApduCmd.Class;
ApduBuffer[1] = ApduCmd.Ins;
ApduBuffer[2] = ApduCmd.P1;
ApduBuffer[3] = ApduCmd.P2;
m_nLastError = SCardTransmit(m_hCard, ref ioRequest, ApduBuffer, (uint)ApduBuffer.Length, IntPtr.Zero, ApduResponse, out RecvLength);
if (m_nLastError != 0)
{
var msg = "SCardTransmit error: " + m_nLastError;
throw new SmartCardException(msg, m_nLastError);
}
var apduData = new byte[RecvLength];
for (var nI = 0; nI < RecvLength; nI++)
{
apduData[nI] = ApduResponse[nI];
}
return new APDUResponse(apduData);
}
Update 2: ho anche provato con a mettere un po Thread.Sleep()
Cosa fa 'card.Transmit'? Cioè, qual è la risposta effettiva dal lettore di carte o dalla carta? Con che tipo di carta stai lavorando? –
Puoi posticipare il tuo comando e riprovare? il lettore o la carta potrebbero non essere veloci quanto il tempo di esecuzione del programma? – Abraham
Hai scritto tu stesso il programma installato sulle smart card? puoi mandare '00A404000004' a entrambi i tipi di carte e aggiungere la risposta delle carte alla domanda? (Utilizzare questo strumento per inviare comandi APDU alle schede: https://github.com/OpenSC/OpenSC/wiki) – Abraham