예제 #1
0
        private static void Connect(bool lowPower)
        {
            Console.WriteLine($"Connecting to reader at '{appSettings.ReaderIpAddress}'.");
            reader.Connect(appSettings.ReaderIpAddress);
            Settings settings = reader.QueryDefaultSettings();

            // Start the reader as soon as it's configured.
            // This will allow it to run without a client connected.
            settings.AutoStart.Mode = AutoStartMode.Immediate;
            settings.AutoStop.Mode  = AutoStopMode.None;

            // Use Advanced GPO to set GPO #1
            // when an client (LLRP) connection is present.
            //settings.Gpos.GetGpo(1).Mode = GpoMode.LLRPConnectionStatus;

            // Tell the reader to include the timestamp in all tag reports.
            settings.Report.IncludeFirstSeenTime = true;
            settings.Report.IncludeLastSeenTime  = true;
            settings.Report.IncludeSeenCount     = true;

            // If this application disconnects from the
            // reader, hold all tag reports and events.
            settings.HoldReportsOnDisconnect = true;

            // Enable keepalives.
            settings.Keepalives.Enabled    = true;
            settings.Keepalives.PeriodInMs = 5000;

            // Enable link monitor mode.
            // If our application fails to reply to
            // five consecutive keepalive messages,
            // the reader will close the network connection.
            settings.Keepalives.EnableLinkMonitorMode = true;
            settings.Keepalives.LinkDownThreshold     = 5;

            if (lowPower)
            {
                settings.ReaderMode                  = ReaderMode.AutoSetDenseReader;
                settings.SearchMode                  = SearchMode.SingleTarget;
                settings.Session                     = 1;
                settings.Antennas.TxPowerMax         = false;
                settings.Antennas.TxPowerInDbm       = 20;
                settings.Antennas.RxSensitivityMax   = false;
                settings.Antennas.RxSensitivityInDbm = -70;
            }
            else
            {
                settings.ReaderMode = ReaderMode.AutoSetDenseReaderDeepScan;
            }

            // Assign an event handler that will be called
            // when keepalive messages are received.
            reader.KeepaliveReceived += OnKeepaliveReceived;

            // Assign an event handler that will be called
            // if the reader stops sending keepalives.
            reader.ConnectionLost += OnConnectionLost;

            // Apply the newly modified settings.
            reader.ApplySettings(settings);

            // Save the settings to the reader's
            // non-volatile memory. This will
            // allow the settings to persist
            // through a power cycle.
            reader.SaveSettings();

            // Assign the TagsReported event handler.
            // This specifies which method to call
            // when tags reports are available.
            reader.TagsReported += OnTagsReported;
        }