public bool connectCard(int rdrIndex) { connActive = true; if (rdrIndex == 0) { //retCode = ACR122uCard.SCardConnect(hContext, rdrStates[rdrIndex].RdrName.ToString(), ACR122uCard.SCARD_SHARE_SHARED, // ACR122uCard.SCARD_PROTOCOL_T0 | ACR122uCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol); } else if (rdrIndex == 1) { //retCode1 = ACR122uCard.SCardConnect(hContext, rdrStates[rdrIndex].RdrName.ToString(), ACR122uCard.SCARD_SHARE_SHARED, // ACR122uCard.SCARD_PROTOCOL_T0 | ACR122uCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol); } if (retCode != ACR122uCard.SCARD_S_SUCCESS) { //MessageBox.Show(Card.GetScardErrMsg(retCode), "Card not available"); //this.Text = ACR122uCard.GetScardErrMsg(retCode).ToString() + " " + "Card not available 0 " + retCode.ToString(); connActive = false; return(false); } if (retCode1 != ACR122uCard.SCARD_S_SUCCESS) { //MessageBox.Show(Card.GetScardErrMsg(retCode), "Card not available"); this.Text = ACR122uCard.GetScardErrMsg(retCode).ToString() + " " + "Card not available 1 " + retCode.ToString(); connActive = false; return(false); } return(true); }
private void deviceStatusUpdater(int retVal) { if (retVal == 0) { //tsslblDevice.Text = "Connected to " + this.RdrState.RdrName.ToString() + " device."; //tsslblDevice.Text = "Connected to " + this.rdrStates[0].RdrName.ToString() + " device."; tsslblDevice.Image = Z.IconLibrary.FarmFresh.Icon.AcceptButton.GetImage16(); /*tmrDeviceConn.Enabled = false; * tmrReadTags.Enabled = true;*/ } else { tsslblDevice.Text = ACR122uCard.GetScardErrMsg(retCode); tsslblDevice.Image = Z.IconLibrary.FarmFresh.Icon.Error.GetImage16(); /*tmrDeviceConn.Enabled = true; * tmrReadTags.Enabled = false;*/ } }
public void SelectDevice() { //MessageBox.Show(this.ListReaders().Count.ToString()); if (this.ListReaders().Count > 0) { List <string> availableReaders = this.ListReaders(); this.RdrState = new ACR122uCard.SCARD_READERSTATE(); readername = availableReaders[0].ToString();//selecting first device this.RdrState.RdrName = readername; if (retCode == 0) { MessageBox.Show("Device successfully connected.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ACR122uCard.GetScardErrMsg(retCode).ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(ACR122uCard.GetScardErrMsg(retCode).ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void tmrReadTags_Tick(object sender, EventArgs e) // for reading the tags //MessageBox.Show(availableReaders[0].ToString() + " " + availableReaders[1].ToString()); //return; { try { if (DeviceCount > 0) { retCode = ACR122uCard.SCardConnect(hContext, rdrState1.RdrName.ToString(), ACR122uCard.SCARD_SHARE_SHARED, ACR122uCard.SCARD_PROTOCOL_T0 | ACR122uCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } if (retCode == ACR122uCard.SCARD_S_SUCCESS) { string cardUID = getcardUID(); //this.Text = cardUID; //displaying on text block this.Text = ACR122uCard.GetScardErrMsg(retCode); if (cardUID != "63000000" && cardUID != "Error") { //if (!StudentQueue.Contains(cardUID)) //{ //StudentQueue.Enqueue(cardUID); checkStudentTag(cardUID); //} } } //try{ // if (DeviceCount > 1) // { // retCode1 = ACR122uCard.SCardConnect(hContext, rdrState2.RdrName.ToString(), ACR122uCard.SCARD_SHARE_SHARED, // ACR122uCard.SCARD_PROTOCOL_T0 | ACR122uCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message.ToString()); //} //if (retCode1 == ACR122uCard.SCARD_S_SUCCESS) //{ // string cardUID = getcardUID(); // //displaying on text block // if (cardUID != "63000000" && cardUID != "Error") // { // //if (!StudentQueue.Contains(cardUID)) // //{ // //StudentQueue.Enqueue(cardUID); // checkStudentTag(cardUID); // //} // } //} //retCode = 0; //retCode1 = 0; //hCard = 0; //Protocol = 0; //hContext = 0; }