Esempio n. 1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            string errMsg = string.Empty;

            try {
                prnOps = new PrinterOps();

                if (!CheckForPrinter(ref errMsg))
                {
                    throw new ArgumentException(errMsg);
                }

                if (!ReaderSearch(out errMsg))
                {
                    throw new ArgumentException(errMsg);
                }

                this.lblVersion.Text += GetZCSmartCardLibVersion();
                SetLblReaderVersion();

                CboCardTypeInit();
            } catch (Exception ex) {
                MessageBox.Show("Form Load Error: " + ex.Message);
                Application.Exit();
            } finally {
                scReader = null;
                prnOps   = null;
            }
        }
Esempio n. 2
0
        private bool SetOffsets(string cardType)
        {
            bool       offsetsSet = false;
            PrinterOps prnOps     = new PrinterOps();

            try {
                prnOps = new PrinterOps();
                if (!prnOps.DiscoverUSBPrinters())
                {
                    throw new Exception(prnOps.printerError);
                }

                if (!prnOps.OpenConnection())
                {
                    prnOps = null;
                    throw new Exception(prnOps.printerError);
                }

                int max = 0;
                int min = 0;
                prnOps.GetSmartOffsetRange(cardType, out min, out max);

                if (this.nbOffset.Value < min)
                {
                    this.nbOffset.Value   = 0;
                    this.nbOffset.Minimum = min;
                    this.nbOffset.Value   = min;
                }
                else
                {
                    this.nbOffset.Minimum = min;
                }
                if (this.nbOffset.Value > max)
                {
                    this.nbOffset.Value   = 0;
                    this.nbOffset.Maximum = max;
                    this.nbOffset.Value   = max;
                }
                else
                {
                    this.nbOffset.Maximum = max;
                }

                string offsetRange = "Offset range is " + min.ToString() + " to " + max.ToString();
                System.Windows.Forms.ToolTip toolTip = new System.Windows.Forms.ToolTip();
                toolTip.SetToolTip(this.nbOffset, offsetRange);
                offsetsSet = true;
            } catch {
            } finally {
                if (prnOps != null)
                {
                    prnOps.CloseConnection();
                    prnOps = null;
                }
            }
            return(offsetsSet);
        }
Esempio n. 3
0
        private void BtnTest_Click(object sender, EventArgs e)
        {
            string errMsg = string.Empty;

            try {
                prnOps = new PrinterOps();

                if (!CheckForPrinter(ref errMsg))
                {
                    throw new ArgumentException(errMsg);
                }

                if (!prnOps.OpenConnection())
                {
                    throw new ArgumentException(prnOps.printerError);
                }

                string alarmDescr = string.Empty;
                if (prnOps.IsAlarmHandling(out alarmDescr))
                {
                    errMsg = "Alarm: " + alarmDescr + " : cannot run test";
                    throw new Exception(errMsg);
                }

                if (string.IsNullOrEmpty(cardSlot))
                {
                    throw new Exception("No reader selected");
                }

                scReader = new ReaderLib();

                switch (cboCardType.Text)
                {
                case "MIFARE CLASSIC":
                case "MIFARE ULTRALIGHT":
                case "MIFARE DESFIRE":
                    if (cardSlot.Contains("Elatec"))
                    {
                        if (!scReader.SetRFHF(virtualSlot, true))
                        {
                            throw new Exception(scReader.ReaderError);
                        }
                    }
                    RunTest(out errMsg);
                    if (!scReader.SetRFHF(virtualSlot, false))
                    {
                        throw new Exception(scReader.ReaderError);
                    }
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        throw new Exception(errMsg);
                    }
                    break;

                case "PROX":
                case "HITAG":
                    if (cardSlot.Contains("Elatec"))
                    {
                        if (!scReader.SetRFLF(virtualSlot, true))
                        {
                            throw new Exception(scReader.ReaderError);
                        }
                    }
                    RunTest(out errMsg);
                    if (!scReader.SetRFLF(virtualSlot, false))
                    {
                        throw new Exception(scReader.ReaderError);
                    }
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        throw new Exception(errMsg);
                    }
                    break;

                case "AT88SC0104C":
                    RunTest(out errMsg);
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        throw new Exception(errMsg);
                    }
                    break;

                case "SLEXX42":
                case "SLEXX28":
                    RunTest(out errMsg);
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        throw new Exception(errMsg);
                    }
                    break;

                default:
                    throw new Exception("Unknown Test");
                }
            } catch (Exception ex) {
                MessageBox.Show("Test Click Error : " + ex.Message);
            } finally {
                scReader = null;
                if (prnOps != null)
                {
                    prnOps.CloseConnection();
                    prnOps = null;
                }
            }
        }