Example #1
0
        private void buttonConnect_CheckedChanged(object sender, System.EventArgs e)
        {
            if (buttonConnect.Checked)
            {
                try
                {
                    this.UseWaitCursor = true;
                    buttonConnect.Text = "Dis&connect";
                    reader.ConnectCOMM(Int32.Parse((string)comboSerialPort.SelectedItem), true);

                    // Set the parameters
                    reader.SetBusAddress((byte)Int32.Parse(textBoxBusAddress.Text));
                    reader.SetPortPara("Timeout", textBoxTimeout.Text);

                    reader.ReadReaderInfo();                // read important reader info
                    reader.ReadCompleteConfiguration(true); // read reader's configuration from EEPROM (this need some time!)

                    // add the listener
                    reader.AddEventListener(this, FeIscListenerConst.SCANNER_PRT_EVENT);
                    this.UseWaitCursor = false;
                }
                catch (Exception)
                {
                    if (reader.Connected)
                    {
                        try
                        {
                            reader.RemoveEventListener(this, FeIscListenerConst.SCANNER_PRT_EVENT);
                            reader.DisConnect();
                        }
                        catch (Exception) {}
                    }
                    buttonConnect.Checked = false;
                    buttonConnect.Text    = "&Connect";
                    return;
                }
            }
            else
            {
                try
                {
                    buttonConnect.Text = "&Connect";
                    // remove the listener
                    reader.RemoveEventListener(this, FeIscListenerConst.SCANNER_PRT_EVENT);
                    reader.DisConnect();
                }
                catch (Exception) {}
            }
        }
        public ISOHostSample()
        {
            try
            {
                fedm = new FedmIscReader();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error");
            }

            //declaration from Thread
            Thread MyThread = new Thread(new ThreadStart(ReadThread));

            fedm.SetTableSize(FedmIscReaderConst.ISO_TABLE, 128);

            config = new PortConnection();
            config.PortConfig(ref fedm);
            DialogResult reponse = config.ShowDialog();


            if (fedm.Connected == true)
            {
                try
                {
                    fedm.ReadCompleteConfiguration(false);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.ToString(), "Error");
                }
                // set Persistence Reset Time in Reader Configuration to zero
                // this speeds up inventory cycles
                int back = OBID.Fedm.ERROR_UNSUPPORTED_NAMESPACE;
                try
                {
                    back = fedm.TestConfigPara(OBID.ReaderConfig.Transponder.PersistenceReset.Antenna.No1.PersistenceResetTime);
                }
                catch (Exception ex)
                { // ignore Exception
                }
                // if reader supports this parameter, set it !
                if (0 == back)
                {
                    try
                    {
                        back = fedm.GetConfigPara(OBID.ReaderConfig.Transponder.PersistenceReset.Antenna.No1.PersistenceResetTime, out persistenceResetTime, false);
                        back = fedm.SetConfigPara(OBID.ReaderConfig.Transponder.PersistenceReset.Antenna.No1.PersistenceResetTime, (uint)0, false);
                        if (back == 1) // return value 1 indicates modified parameter
                        {
                            back = fedm.ApplyConfiguration(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.ToString(), "Error");
                    }
                }
            }

            // Init Dialogs Authent
            authmifare_config = new AuthentMifare(this.fedm);
            authmyd_config    = new AuthentMYD(this.fedm);

            if (fedm.Connected == true && reponse == DialogResult.Cancel)
            {
                InitializeComponent();

                //set read Mode
                this.comboBoxMod.SelectedIndex = 1;

                //set bank for UHF
                this.comboBoxBank.SelectedIndex = 3;
                this.comboBoxBank.Enabled       = false;

                // set blockSize
                this.numericUpDownDBS.Minimum   = 1;
                this.numericUpDownDBS.Maximum   = 256;
                this.numericUpDownDBS.Increment = 1;
                this.numericUpDownDBS.Value     = 4;

                // set the number of blocks
                this.numericUpDownDBN.Minimum   = 1;
                this.numericUpDownDBN.Maximum   = 256;
                this.numericUpDownDBN.Increment = 1;
                this.numericUpDownDBN.Value     = 1;

                // set status of Authent Buttons
                this.button_Authent_myd.Enabled   = false;
                this.button_AuthentMifare.Enabled = false;

                this.checkBoxEnable.Checked = true;

                //Registry from Events send and receive
                fedm.AddEventListener(this, FeIscListenerConst.SEND_STRING_EVENT);
                fedm.AddEventListener(this, FeIscListenerConst.RECEIVE_STRING_EVENT);

                //Init from  TextEditor
                HexEdit.SetSize(128, 4, BnkIdx);

                //Thread starten in Background
                running = false;
                MyThread.IsBackground = true;
                MyThread.Start();
            }
            else
            {
                config.ShowDialog();
            }
        }