コード例 #1
0
ファイル: ImpinjControlService.cs プロジェクト: cyysu/rfid
        public ConnectResponse connect(string address)
        {
            try
            {
                if (this.connected)
                {
                    Console.WriteLine("已存在连接 status: connected");
                    return(new ConnectResponse(_readerSettings.antennaConfiguration, _readerSettings.readerCapabilities, _readerSettings.rOReportSpec));
                }
                _reader = new LLRPClient();
                if (impinjInstalled == false)
                {
                    Impinj_Installer.Install();
                    impinjInstalled = true;
                }

                ENUM_ConnectionAttemptStatusType status;
                bool ret = _reader.Open(address, 2000, out status);
                AntennaConfiguration antennaConfiguration;
                ReaderCapabilities   readerCapabilities;
                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader!");
                    if (status.ToString().Equals("-1"))
                    {
                        Console.WriteLine("Wrong Address");
                    }
                    else
                    {
                        Console.WriteLine(status.ToString());
                    }
                    connected = false;
                    _reader.Close();
                    return(null);
                }
                else
                {
                    Console.WriteLine("Succeeded to Connect to Reader!");
                    _readerSettings = new ReaderSettings(_reader);
                    _readerSettings.AddEventHandler();
                    _readerSettings.Enable_Impinj_Extensions();
                    readerCapabilities = _readerSettings.GetReaderCapabilities();
                    if (readerCapabilities == null)
                    {
                        _reader.Close();
                        connected = false;
                        return(null);
                    }
                    antennaConfiguration = new AntennaConfiguration();
                    antennaConfiguration.init(readerCapabilities);
                    antennaConfiguration = _readerSettings.getRFIDReaderPara(antennaConfiguration, readerCapabilities.MaxNumberOfAntennaSupported);
                    _readerSettings.antennaConfiguration = antennaConfiguration;
                    _readerSettings.rOReportSpec         = new ROReportSpec();
                    ConnectResponse connectResponse = new ConnectResponse(antennaConfiguration, readerCapabilities, _readerSettings.rOReportSpec);
                    connected = true;
                    Console.WriteLine("status: connected");
                    return(connectResponse);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(null);
        }
コード例 #2
0
        private void tsbtnConnect_Click(object sender, EventArgs e)
        {
            string address = "";

            if (rbtnIP.Checked)
            {
                if (tbxIP.Text == String.Empty)
                {
                    MessageBox.Show("Please Input IP Address!");
                    return;
                }
                RFIDReaderParameter.IP = tbxIP.Text.Trim();
                address = RFIDReaderParameter.IP;
            }
            else if (rbtnHostname.Checked)
            {
                if (tbxMAC1.Text == String.Empty || tbxMAC2.Text == String.Empty || tbxMAC3.Text == String.Empty)
                {
                    MessageBox.Show("Please complete Hostname!");
                    return;
                }
                RFIDReaderParameter.Hostname = String.Format(@"speedwayr-{0}-{1}-{2}.local", tbxMAC1.Text.Trim(), tbxMAC2.Text.Trim(), tbxMAC3.Text.Trim());
                address = RFIDReaderParameter.Hostname;
            }

            Console.WriteLine("Connectting to Reader...");

            //Update Status
            tsslblStatus.Text  = ReaderStatus.Connecting.ToString();
            tsslblStatus.Image = Properties.Resources.status_connecting;
            // Create a LLRPClient instance.
            _reader = new LLRPClient();
            //Impinj Best Practice! Always Install the Impinj extensions
            Impinj_Installer.Install();

            ENUM_ConnectionAttemptStatusType status;
            bool ret = _reader.Open(address, 2000, out status);

            // Check for a connection error
            if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
            {
                // Could not connect to the reader; Print out the error
                Console.WriteLine("Failed to Connect to Reader!");
                if (status.ToString() == "-1")
                {
                    tsslblStatus.Text = "Wrong Address";
                }
                else
                {
                    tsslblStatus.Text = status.ToString();
                }


                tsslblStatus.Image = Properties.Resources.status_stop;
                MessageBox.Show(tsslblStatus.Text, "Connection Error");
                RFIDReaderParameter.IsConnected = false;
                _reader.Close();
                return;
            }
            else
            {
                //Connect to the reader successfully
                Console.WriteLine("Succeeded to Connect to Reader!");

                tsslblStatus.Text  = ReaderStatus.Connected.ToString();
                tsslblStatus.Image = Properties.Resources.status_ready;

                tsbtnConnect.Enabled      = false;
                tsbtnStart.Enabled        = true;
                tsbtnMoreSettings.Enabled = true;

                cbResetToFactoryDefault.Enabled = true;
                gbReadMode.Enabled              = true;
                gbFrequencyInfo.Enabled         = true;
                gbTagFilter.Enabled             = true;
                RFIDReaderParameter.IsConnected = true;

                _readerSettings = new ReaderSettings(this, _reader);
                _readerSettings.AddEventHandler();
                _readerSettings.Enable_Impinj_Extensions();
                _readerSettings.GetReaderCapabilities();
                new RFIDReaderParameter();
                _readerSettings.UpdateUISettings();
            }
        }