예제 #1
0
        public static string cardProtocol()
        {
            WinSCard scard = new WinSCard();

            try
            {
                scard.EstablishContext();
                scard.ListReaders();
                string readerName = scard.ReaderNames[1];
                scard.WaitForCardPresent(readerName);


                scard.Connect(readerName);
                byte[] cmdApdu    = { 0xFF, 0xCA, 0x00, 0x00, 00 }; // Get Card UID ...
                byte[] respApdu   = new byte[10];
                int    respLength = respApdu.Length;

                scard.Transmit(cmdApdu, cmdApdu.Length, respApdu, ref respLength);

                //find a better place for this
                App.UID = HexFormatting.ToHexString(respApdu, true);

                //he wanted some kinda beeping sound when someone swipes their card
                System.Media.SystemSounds.Beep.Play();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return(App.UID);
        }
예제 #2
0
 internal ACR122U_SmartCardException(ACR122U_ResposeErrorCodes ACRErrorOnExceptionIn, ErrorCodes ErrorOnExceptionIn) : base(ErrorOnExceptionIn, ACR122U_SmartCard.GetACRErrMsg(ACRErrorOnExceptionIn) + "\n\t" + WinSCard.GetScardErrMsg(ErrorOnExceptionIn))
 {
     ACRErrorOnException = ACRErrorOnExceptionIn;
 }
예제 #3
0
        // Submit Button
        //     Starts the example code based on Form selections ---------------------------------------------

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            #region Variables

            bool   eject = false;
            string msg   = "";

            SampleCodeMag      mag = null;
            SampleCodeGraphics prn = null;

            #endregion

            #region Check Selections

            // Verifies that a printer has been selected
            try
            {
                if (cboPrn.SelectedIndex < 0)
                {
                    msg = "Error: A Printer has not been selected";
                    return;
                }

                // Verifies that at least one selection is made
                if (!this.cbBack.Checked && !this.cbFront.Checked && !this.cbMag.Checked && !this.cbContact.Checked)
                {
                    msg = "Error: No Selections";
                    return;
                }

                #endregion



                #region Smart Cards
                {
                    // the eject variable is set to true if magnetic encoding is not selected
                    //  and neither Front or Back is selected

                    eject = (!this.cbMag.Checked && !this.cbBack.Checked && !this.cbFront.Checked);

                    // Determines which smart card sample code to run

                    if (this.cbContact.Checked)
                    {
                        contact = new SampleCodeCONTACT();
                        string _contactlessReader = "";
                        string _contactReader     = "";
                        string errorMsg           = "";

                        WinSCard.GetPCSCReaders(out _contactlessReader, out _contactReader, out errorMsg);
                        if (_contactReader != null && _contactReader.Length > 0)
                        {
                            contact.ContactEncode(this.cboPrn.Text, _contactReader, Convert.ToInt16(eject), out msg);
                            if (msg == "")
                            {
                                this.lblStatus.Text = "CONTACT : No Errors";
                            }
                            else
                            {
                                this.lblStatus.Text = msg;
                            }
                        }
                        else
                        {
                            this.lblStatus.Text = "Error: No Contact Reader found";
                        }
                    }
                }

                #endregion

                #region Magnetic Encoding

                if (cbMag.Checked)
                {
                    // the eject variable is set to true if neither Front or Back is selected

                    eject = (!this.cbBack.Checked && !this.cbFront.Checked);

                    // Encodes and Verifies all three Tracks

                    mag = new SampleCodeMag();
                    mag.PerformMagneticEncodeJob(this.cboPrn.Text, out msg);
                    if (msg != "")
                    {
                        return;
                    }
                    this.lblStatus.Text = "Magnetic Encoding : No Errors";
                }

                #endregion

                #region Printing

                // Initialize the Print Side Class

                prn = new SampleCodeGraphics();

                // Determines the printing type

                if (this.cbFront.Checked && !this.cbBack.Checked)
                {
                    prn.PrintFrontSideOnly(this.cboPrn.Text, "Front Side Text", Application.StartupPath, out msg);
                    if (msg == "")
                    {
                        this.lblStatus.Text = "No Errors : Front Side Only Printing";
                    }
                }
                else if (this.cbFront.Checked && this.cbBack.Checked)
                {
                    prn.PrintBothSides(this.cboPrn.Text, "Front Side Text", "Back Side Text", Application.StartupPath, out msg);
                    if (msg == "")
                    {
                        this.lblStatus.Text = "No Errors : Both Side Printing";
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                MessageBox.Show(ex.ToString(), "btnSubmit_Click threw exception");
            }
            finally
            {
                if (msg != "")
                {
                    this.lblStatus.Text = msg;
                }

                mag = null;
                prn = null;
            }

            #endregion
        }