private bool CheckCard() { bool functionReturnValue = false; //Variable declaration int ReaderLen = 0; long tmpWord; tmpWord = 32; ATRLen = Convert.ToInt32(tmpWord); retCode = ModWinsCard.SCardStatus(hCard, cbReader.Text, ref ReaderLen, ref dwState, ref dwActProtocol, ref ATRVal[0], ref ATRLen); if (retCode != ModWinsCard.SCARD_S_SUCCESS) { //Call DisplayOut(1, retCode, "") functionReturnValue = false; return(functionReturnValue); } else { InterpretATR(); functionReturnValue = true; } return(functionReturnValue); }
private void bGetAtr_Click(object sender, EventArgs e) { string tmpStr; int indx; displayOut(0, 0, "Invoke Card Status"); ATRLen = 33; retCode = ModWinsCard.SCardStatus(hCard, cbReader.Text, ref ReaderLen, ref dwState, ref dwActProtocol, ref ATRVal[0], ref ATRLen); if (retCode != ModWinsCard.SCARD_S_SUCCESS) { displayOut(1, retCode, ""); System.Environment.Exit(0); } else { tmpStr = "ATR Length : " + ATRLen.ToString(); displayOut(3, 0, tmpStr); tmpStr = "ATR Value : "; for (indx = 0; indx <= ATRLen - 1; indx++) { tmpStr = tmpStr + " " + string.Format("{0:X2}", ATRVal[indx]); } displayOut(3, 0, tmpStr); } tmpStr = "Active Protocol: "; switch (dwActProtocol) { case 1: tmpStr = tmpStr + "T=0"; break; case 2: tmpStr = tmpStr + "T=1"; break; default: tmpStr = "No protocol is defined."; break; } displayOut(3, 1, tmpStr); InterpretATR(); }
private void _pollingTimer_Tick(object sender, EventArgs e) { int readerLen = 0, dwState = 0, dwProtocol = 0; _receivedBuffer = new byte[32]; var atrLen = _receivedBuffer.Length; Connect(); _returnCode = ModWinsCard.SCardStatus(_hCard, _name, ref readerLen, ref dwState, ref dwProtocol, ref _receivedBuffer[0], ref atrLen); if (_returnCode != ModWinsCard.SCARD_S_SUCCESS && ShouldChangeState(ReaderCardState.NO_CARD_DETECTED)) { _smartCard = null; OnReaderCardStateChanged(new ReaderCardStateChangedEventArgs(ReaderCardState.NO_CARD_DETECTED)); } else { try { var card = new SmartCard(atrLen, _receivedBuffer); if (ShouldChangeState(ReaderCardState.CARD_PRESENT) || card.Type != _smartCard.Type) { if (_smartCard == null) { _smartCard = card; } else { _smartCard = _smartCard.Type == card.Type ? _smartCard : card; } OnReaderCardStateChanged(new ReaderCardStateChangedEventArgs(ReaderCardState.CARD_PRESENT)); } } catch (Exception) { _smartCard = null; OnReaderCardStateChanged(new ReaderCardStateChangedEventArgs(ReaderCardState.NO_CARD_DETECTED)); } } }