Example #1
0
 private static void SAMFinder(object args)
 {
     bool stopThread = false;
     string readerName = ((InfoHolder)args).readerName;
     ABnoteSAMFinder sam = ((InfoHolder)args).sam;
     SCARD_READERSTATE stat = Smart.GetStatusChangeEx(readerName, 10, SCardState.SCARD_STATE_UNAWARE);
     while (!stopThread)
     {
         if ((stat.dwEventState & SCardState.SCARD_STATE_UNKNOWN) == SCardState.SCARD_STATE_UNKNOWN)
         {
             // reader removed?
             return;
         }
         if (((stat.dwEventState & SCardState.SCARD_STATE_PRESENT) == SCardState.SCARD_STATE_PRESENT) &&
             !((stat.dwEventState & SCardState.SCARD_STATE_INUSE) == SCardState.SCARD_STATE_INUSE))
         {
             // Card inserted - check for SAM applet
             ABnoteSAM card = new ABnoteSAM(Smart.Connect(readerName), new RelaxedStatusWordFilter());
             string resp = "";
             try
             {
                 resp = card.SelectApplet();
             }
             catch (Exception) { }
             if (resp.EndsWith("9000"))
             {
                 sam.ReaderName = readerName;
                 sam.OnSAMFound(card);
             }
             else if (sam.FindAnyCard)
             {
                 sam.ReaderName = readerName;
                 sam.OnSAMFound(card);
             }
         }
         lock (stateLock)
         {
             stopThread = sam.StopFinder;
         }
         try
         {
             stat = Smart.GetStatusChangeEx((string)readerName, -1, stat.dwEventState);
         }
         catch (Exception) {
             break;
         }
     }
 }
Example #2
0
 private void OnSAMFound(ABnoteSAM card)
 {
     if (SAMFound != null)
     {
         SAMFound(this, card);
     }
 }
Example #3
0
 void finder_SAMFound(object sender, ABnoteSAM card)
 {
     DialogResult dr = MessageBox.Show("Card found in " + ((ABnoteSAMFinder)sender).ReaderName + ". Connect to this card?", "SAM Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (dr == DialogResult.Yes)
     {
         this.card = card;
         if (InvokeRequired)
         {
             Invoke((MethodInvoker)delegate()
             {
                 btn_Connect.Text = "Connected";
             });
         }
         else
         {
             btn_Connect.Text = "Connected";
         }
     }
 }