Exemplo n.º 1
0
        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);
        }