public int GetStatusChange(out string status) { status = ""; ReaderState.RdrName = readerName; ReaderState.RdrCurrState = HiDWinscard.SCARD_STATE_UNAWARE; ReaderState.RdrEventState = 0; ReaderState.UserData = "Mifare Card"; value_Timeout = 0; ReaderCount = 1; if (ReaderList == "") { status = "SmartCard Removed"; return(1); } else { retval = HID.SCardGetStatusChange(hContext, value_Timeout, ref ReaderState, ReaderCount); if ((ReaderState.ATRLength == 0) || (retval != 0)) { status = "SmartCard Removed"; return(1); } else { return(0); } } }
//public void Connect_T1(out string status) //{ // status = ""; // retval = HID.SCardConnect(hContext, readerName, HiDWinscard.SCARD_SHARE_SHARED, HiDWinscard.SCARD_PROTOCOL_T1, // ref hCard, ref protocol // ); //Command to connect the card ,protocol T=0 // ReaderState.RdrName = readerName; // ReaderState.RdrCurrState = HiDWinscard.SCARD_STATE_UNAWARE; // ReaderState.RdrEventState = 0; // //ReaderState.UserData = "Mifare Card"; // value_Timeout = 0; // ReaderCount = 1; // if (retval == 0) // { // status = "> SCardConnect" + " Successful \n"; // retval = HID.SCardGetStatusChange(hContext, value_Timeout, ref ReaderState, ReaderCount); // } // else if (retval != 0) // { // status = "> SCardConnect" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n"; // } //} public void Connect(int dwProtocol, out string status) { status = ""; retval = HID.SCardConnect(hContext, readerName, HiDWinscard.SCARD_SHARE_SHARED, (uint)dwProtocol, ref hCard, ref protocol ); //Command to connect the card ,protocol T=0 ReaderState.RdrName = readerName; ReaderState.RdrCurrState = HiDWinscard.SCARD_STATE_UNAWARE; ReaderState.RdrEventState = 0; ReaderState.UserData = "Starcos Card"; value_Timeout = 0; ReaderCount = 1; if (retval == 0) { status = "> SCardConnect" + " Successful \n"; retval = HID.SCardGetStatusChange(hContext, value_Timeout, ref ReaderState, ReaderCount); } else if (retval != 0) { status = "> SCardConnect" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n"; } }
public bool Connect(out string status) { status = ""; logManager.LogToFile("============================================", false); logManager.LogToFile("Start new session", true); logManager.LogToFile("============================================", false); retval = HID.SCardConnect(hContext, readerName, HiDWinscard.SCARD_SHARE_SHARED, HiDWinscard.SCARD_PROTOCOL_T1, ref hCard, ref protocol ); //Command to connect the card ,protocol T=1 ReaderState.RdrName = readerName; ReaderState.RdrCurrState = HiDWinscard.SCARD_STATE_UNAWARE; ReaderState.RdrEventState = 0; ReaderState.UserData = "Mifare Card"; value_Timeout = 0; ReaderCount = 1; if (retval == 0) { status = "> SCardConnect" + " Successful \n"; retval = HID.SCardGetStatusChange(hContext, value_Timeout, ref ReaderState, ReaderCount); _isConnected = true; //if (ReaderState.ATRValue[ReaderState.ATRLength - 0x6].Equals(1)) //{ // card_Type = 1; // //ATR_UID(card_Type); //} //else if (ReaderState.ATRValue[ReaderState.ATRLength - 0x6].Equals(2)) //{ // card_Type = 2; // //ATR_UID(card_Type); //} //else //{ // card_Type = 3; // //ATR_UID(card_Type); //} //timer.Enabled = false; logManager.LogToFile("Connected to card", true); return(true); } else //if (retval != 0) { logManager.LogToFile("Error in connecting to card", true); status = "> SCardConnect" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n"; //timer.Enabled = true; return(false); } }