Exemple #1
0
        /*
         */

        private bool Set_Reader_Config()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            msg.ReaderEventNotificationSpec.EventNotificationState                      = new PARAM_EventNotificationState[5];
            msg.ReaderEventNotificationSpec.EventNotificationState[0]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType         = ENUM_NotificationEventType.AISpec_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = false;

            msg.ReaderEventNotificationSpec.EventNotificationState[1]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType         = ENUM_NotificationEventType.Antenna_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[2]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType         = ENUM_NotificationEventType.GPI_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = false;

            msg.ReaderEventNotificationSpec.EventNotificationState[3]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType         = ENUM_NotificationEventType.Reader_Exception_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[4]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType         = ENUM_NotificationEventType.RFSurvey_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = false;

            /**
             * 2014.2.19
             * */
            msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
            msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Periodic;
            msg.KeepaliveSpec.PeriodicTriggerValue = HeartPericodic;

            /*
             * */

            msg.ResetToFactoryDefault = false;

            MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);

            if (rsp != null)
            {
                //return rsp.ToString();
                return(true);
            }
            else if (msg_err != null)
            {
                //return msg_err.ToString();
                return(false);
            }
            else
            {
                //return "Command time out!";
                return(false);
            }
        }
        /// <summary></summary>
        private void ResetToFactoryDefault()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.ResetToFactoryDefault = true;

            MSG_ERROR_MESSAGE?msgErr = null;
            MSG_SET_READER_CONFIG_RESPONSE?msgResp = this.llrpClient?.SET_READER_CONFIG(
                msg: msg,
                msg_err: out msgErr,
                time_out: this.timeout);

            LLRPHelper.CheckError(msgResp, msgErr);
        }
Exemple #3
0
        /// <summary></summary>
        protected void ResetToFactoryDefault()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.ResetToFactoryDefault = true;

            MSG_ERROR_MESSAGE?msgErr = null;
            MSG_SET_READER_CONFIG_RESPONSE?msgResp = this.BaseClient?.SET_READER_CONFIG(
                msg:      msg,
                msg_err:  out msgErr,
                time_out: 3000);

            this.CheckLLRPError(msgResp, msgErr);
        }
Exemple #4
0
        /// <summary></summary>
        protected override void SetReaderConfig()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            // Keepalive
            PARAM_KeepaliveSpec pKeepalive = new PARAM_KeepaliveSpec();

            msg.KeepaliveSpec = pKeepalive;

            pKeepalive.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Periodic;
            pKeepalive.PeriodicTriggerValue = 30000;

            // Link monitor
            PARAM_ImpinjLinkMonitorConfiguration pLinkMonitor = new PARAM_ImpinjLinkMonitorConfiguration();

            pLinkMonitor.LinkMonitorMode   = ENUM_ImpinjLinkMonitorMode.Enabled;
            pLinkMonitor.LinkDownThreshold = 4;

            msg.Custom.Add(pLinkMonitor);

            // Event notification
            PARAM_ReaderEventNotificationSpec pNotificationSpec = new PARAM_ReaderEventNotificationSpec();

            msg.ReaderEventNotificationSpec = pNotificationSpec;

            pNotificationSpec.EventNotificationState = new PARAM_EventNotificationState[1];

            PARAM_EventNotificationState pROSpecState = new PARAM_EventNotificationState();

            pNotificationSpec.EventNotificationState[0] = pROSpecState;

            pROSpecState.NotificationState = true;
            pROSpecState.EventType         = ENUM_NotificationEventType.ROSpec_Event;

            //Console.Error.WriteLine($"{msg.ToString()}");

            MSG_ERROR_MESSAGE?msgErr = null;
            MSG_SET_READER_CONFIG_RESPONSE?msgResp = this.BaseClient?.SET_READER_CONFIG(
                msg: msg,
                msg_err: out msgErr,
                time_out: this.Timeout);

            LLRPHelper.CheckLLRPResponse(msgResp, msgErr);
        }
Exemple #5
0
        /// <summary></summary>
        private void SetReaderConfig()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            PARAM_KeepaliveSpec pKeepalive = new PARAM_KeepaliveSpec();

            msg.KeepaliveSpec = pKeepalive;
            pKeepalive.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Periodic;
            pKeepalive.PeriodicTriggerValue = 15000;

            PARAM_ImpinjLinkMonitorConfiguration pLinkMonitor = new PARAM_ImpinjLinkMonitorConfiguration();

            pLinkMonitor.LinkDownThreshold = 4;
            pLinkMonitor.LinkMonitorMode   = ENUM_ImpinjLinkMonitorMode.Enabled;
            msg.Custom.Add(pLinkMonitor);

            //
            msg.AntennaConfiguration = new PARAM_AntennaConfiguration[1];
            var pAntConfig = new PARAM_AntennaConfiguration();

            msg.AntennaConfiguration[0] = pAntConfig;

            pAntConfig.AntennaID = 0;
            pAntConfig.AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();

            var pInventoryCommand = new PARAM_C1G2InventoryCommand();

            pAntConfig.AirProtocolInventoryCommandSettings.Add(pInventoryCommand);
            pInventoryCommand.TagInventoryStateAware = false;

            MSG_ERROR_MESSAGE?msgErr = null;
            var msgResp = this.BaseClient?.SET_READER_CONFIG(
                msg:      msg,
                msg_err:  out msgErr,
                time_out: 3000);

            this.CheckLLRPError(msgResp, msgErr);
        }
Exemple #6
0
        /// <summary></summary>
        private void SetAntennaConfig()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.ResetToFactoryDefault = false;

            msg.AntennaConfiguration = new PARAM_AntennaConfiguration[1];

            // Antenna Configuration
            PARAM_AntennaConfiguration pAntennaConfig = new PARAM_AntennaConfiguration();

            msg.AntennaConfiguration[0] = pAntennaConfig;

            pAntennaConfig.AntennaID = 0;
            pAntennaConfig.AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();

            // C1G2 Inventory Command
            PARAM_C1G2InventoryCommand pInventoryCommand = new PARAM_C1G2InventoryCommand();

            pAntennaConfig.AirProtocolInventoryCommandSettings.Add(pInventoryCommand);

            pInventoryCommand.TagInventoryStateAware = false;

            PARAM_ImpinjFixedFrequencyList pFixedFreqList = new PARAM_ImpinjFixedFrequencyList();

            pInventoryCommand.Custom.Add(pFixedFreqList);

            pFixedFreqList.FixedFrequencyMode = ENUM_ImpinjFixedFrequencyMode.Disabled;
            pFixedFreqList.ChannelList        = new UInt16Array();


            MSG_ERROR_MESSAGE?msgErr = null;
            MSG_SET_READER_CONFIG_RESPONSE?msgResp = this.BaseClient?.SET_READER_CONFIG(
                msg: msg,
                msg_err: out msgErr,
                time_out: this.Timeout);
        }
Exemple #7
0
        public void CleanUpReaderConfiguration()
        {
            Console.WriteLine("Factory Default the Reader\n");

            // factory default the reader
            MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
            MSG_ERROR_MESSAGE     msg_err;

            msg_cfg.ResetToFactoryDefault = true;
            msg_cfg.MSG_ID = 2; // not this doesn't need to bet set as the library will default

            // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
            MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

            if (rsp_cfg != null)
            {
                if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                {
                    Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                    reader.Close();
                    return;
                }
            }
            else if (msg_err != null)
            {
                Console.WriteLine(msg_err.ToString());
                reader.Close();
                return;
            }
            else
            {
                Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                reader.Close();
                return;
            }
        }
        private void SetKeepAlive()
        {
            PARAM_KeepaliveSpec kSpec = new PARAM_KeepaliveSpec();
            kSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Periodic;
            kSpec.PeriodicTriggerValue = (uint)keepAliveTrigger;

            MSG_SET_READER_CONFIG readerConfig = new MSG_SET_READER_CONFIG();
            readerConfig.KeepaliveSpec = kSpec;

            llrp.OnKeepAlive += new delegateKeepAlive(OnKeepAliveRecieved);
            try
            {
                MSG_SET_READER_CONFIG_RESPONSE configResponse = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(readerConfig);
            }
            catch (Exception ex)
            {
                throw new ReaderException(ex.Message);
            }
            finally
            {
                kSpec = null;
                readerConfig = null;
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            LLRPClient reader;
            int        i;

            #region ProcessCommandLine

            if (args.Length < 1)
            {
                usage();
                return;
            }

            /* get the options. Skip the last one as its the hostname */
            for (i = 0; i < args.Length - 1; i++)
            {
                if ((args[i] == "-p") && (i < (args.Length - 1)))
                {
                    i++;
                    m_password = System.Convert.ToUInt32(args[i]);
                }
                else if ((args[i] == "-n") && (i < (args.Length - 1)))
                {
                    i++;
                    m_newPassword = System.Convert.ToUInt32(args[i]);
                }
                else if (args[i] == "-t")
                {
                    m_tid = ENUM_ImpinjSerializedTIDMode.Enabled;
                }
                else if (args[i] == "-s")
                {
                    m_shortRange = ENUM_ImpinjQTAccessRange.Short_Range;
                }
                else if ((args[i] == "-v") && (i < (args.Length - 1)))
                {
                    i++;
                    m_Verbose = System.Convert.ToUInt32(args[i]);
                }
                else if ((args[i] == "-q") && (i < (args.Length - 1)))
                {
                    i++;
                    m_qtmode = System.Convert.ToUInt32(args[i]);
                }
                else
                {
                    usage();
                    return;
                }
            }

            m_readerName = args[i];

            Console.WriteLine(
                "Impinj C# LTK.NET RFID Application DocSample5 reader - " +
                m_readerName + "\n");

            Console.WriteLine(
                " qtMode:" + m_qtmode.ToString() +
                " Verbose:" + m_Verbose.ToString() +
                " Range:" + m_shortRange.ToString() +
                " SerializeTID:" + m_tid.ToString() +
                " OldPassword:"******" NewPassword:"******"Initializing\n");

                //Create an instance of LLRP reader client.
                reader = new LLRPClient();

                //Impinj Best Practice! Always Install the Impinj extensions
                Impinj_Installer.Install();
            }
            #endregion

            #region EventHandlers
            {
                Console.WriteLine("Adding Event Handlers\n");
                reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification);
                reader.OnRoAccessReportReceived  += new delegateRoAccessReport(reader_OnRoAccessReportReceived);
            }
            #endregion

            #region Connecting
            {
                Console.WriteLine("Connecting To Reader\n");

                ENUM_ConnectionAttemptStatusType status;

                //Open the reader connection.  Timeout after 5 seconds
                bool ret = reader.Open(m_readerName, 5000, out status);

                //Ensure that the open succeeded and that the reader
                // returned the correct connection status result

                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader \n");
                    return;
                }
            }
            #endregion

            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = msgID++;
                // note :this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = msgID++;
                //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region getReaderCapabilities
            {
                Console.WriteLine("Getting Reader Capabilities\n");

                MSG_GET_READER_CAPABILITIES cap = new MSG_GET_READER_CAPABILITIES();
                cap.MSG_ID        = msgID++;
                cap.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All;

                //Send the custom message and wait for 8 seconds
                MSG_ERROR_MESSAGE msg_err;
                MSG_GET_READER_CAPABILITIES_RESPONSE msg_rsp =
                    reader.GET_READER_CAPABILITIES(cap, out msg_err, 8000);

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("GET reader Capabilities Command Timed out\n");
                    reader.Close();
                    return;
                }

                // Get the reader model number since some features are not
                // available on Speedway revolution.
                PARAM_GeneralDeviceCapabilities dev_cap = msg_rsp.GeneralDeviceCapabilities;

                // Check to make sure the model number mathces and that this device
                // is an impinj reader (deviceManufacturerName == 25882)
                if ((dev_cap == null) ||
                    (dev_cap.DeviceManufacturerName != 25882))
                {
                    Console.WriteLine("Could not determine reader model number\n");
                    reader.Close();
                    return;
                }

                // Need to parse version number strings and compare to make sure
                // that the reader version is higher than 4.4.
                Version readerVersion  = new Version(dev_cap.ReaderFirmwareVersion);
                Version minimumVersion = new Version("4.4.0.0");

                if (readerVersion < minimumVersion)
                {
                    Console.WriteLine("Must use Octane 4.4 or later\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region SetReaderConfig
            {
                Console.WriteLine("Adding SET_READER_CONFIG n");

                // Communicate that message to the reader
                MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();
                msg.MSG_ID = msgID++;

                msg.ResetToFactoryDefault = false;

                // turn off all reports
                msg.ROReportSpec = new PARAM_ROReportSpec();
                msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
                msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID             = false;
                msg.ROReportSpec.TagReportContentSelector.EnableAntennaID                = false;
                msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex             = false;
                msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp       = false;
                msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = false;
                msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp        = false;
                msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI     = false;
                msg.ROReportSpec.TagReportContentSelector.EnableROSpecID     = false;
                msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex    = false;
                msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = false;

                /* report all tags immediately */
                msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
                msg.ROReportSpec.N = 1;

                /* turn on serialized TID if we are asked to */
                PARAM_ImpinjTagReportContentSelector impinjTagData = new PARAM_ImpinjTagReportContentSelector();
                impinjTagData.ImpinjEnableGPSCoordinates = new PARAM_ImpinjEnableGPSCoordinates();
                impinjTagData.ImpinjEnableGPSCoordinates.GPSCoordinatesMode = ENUM_ImpinjGPSCoordinatesMode.Disabled;
                impinjTagData.ImpinjEnablePeakRSSI = new PARAM_ImpinjEnablePeakRSSI();
                impinjTagData.ImpinjEnablePeakRSSI.PeakRSSIMode           = ENUM_ImpinjPeakRSSIMode.Disabled;
                impinjTagData.ImpinjEnableRFPhaseAngle                    = new PARAM_ImpinjEnableRFPhaseAngle();
                impinjTagData.ImpinjEnableRFPhaseAngle.RFPhaseAngleMode   = ENUM_ImpinjRFPhaseAngleMode.Disabled;
                impinjTagData.ImpinjEnableSerializedTID                   = new PARAM_ImpinjEnableSerializedTID();
                impinjTagData.ImpinjEnableSerializedTID.SerializedTIDMode = m_tid;
                msg.ROReportSpec.Custom.Add(impinjTagData);

                /* report access specs immediately as well */
                msg.AccessReportSpec = new PARAM_AccessReportSpec();
                msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

                // set the antenna configuration for all antennas
                msg.AntennaConfiguration              = new PARAM_AntennaConfiguration[1];
                msg.AntennaConfiguration[0]           = new PARAM_AntennaConfiguration();
                msg.AntennaConfiguration[0].AntennaID = 0; /* all antennas  */

                // use DRM autset mode
                PARAM_C1G2InventoryCommand c1g2Inv = new PARAM_C1G2InventoryCommand();
                c1g2Inv.C1G2RFControl           = new PARAM_C1G2RFControl();
                c1g2Inv.C1G2RFControl.ModeIndex = 1000;
                c1g2Inv.C1G2RFControl.Tari      = 0;

                // Use session 1 so we don't get too many reads
                c1g2Inv.C1G2SingulationControl                = new PARAM_C1G2SingulationControl();
                c1g2Inv.C1G2SingulationControl.Session        = new TwoBits(1);
                c1g2Inv.C1G2SingulationControl.TagPopulation  = 1;
                c1g2Inv.C1G2SingulationControl.TagTransitTime = 0;

                // add to the message
                msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(c1g2Inv);

                MSG_ERROR_MESSAGE msg_err;
                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDRoSpecWithXML
            {
                Console.WriteLine("Adding RoSpec from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    string filename;
                    filename = @"..\..\addRoSpec.xml";
                    FileStream   fs = new FileStream(filename, FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ROSPEC)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj;
                msg.MSG_ID = msgID++;

                // Communicate that message to the reader
                MSG_ERROR_MESSAGE       msg_err;
                MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDAccessSpec
            {
                /* This section adds a second accessSpec identical to the
                 * first (except for its ID).  This is duplicate code with
                 * the goal of showing an example of how to build LLRP specs
                 * from C# objects rather than XML */
                Console.WriteLine("Adding AccessSpec from C# objects \n");

                // create the target tag filter spec to perform access only on these tags
                // This only requires a single filter (LTK/LLRP supports up to 2 )
                PARAM_C1G2TargetTag[] targetTag = new PARAM_C1G2TargetTag[1];
                targetTag[0]         = new PARAM_C1G2TargetTag();
                targetTag[0].Match   = true;
                targetTag[0].MB      = new TwoBits(1);
                targetTag[0].Pointer = 16;
                targetTag[0].TagData = LLRPBitArray.FromHexString("");
                targetTag[0].TagMask = LLRPBitArray.FromHexString("");

                PARAM_C1G2TagSpec tagSpec = new PARAM_C1G2TagSpec();
                tagSpec.C1G2TargetTag = targetTag;

                PARAM_AccessCommand accessCmd = new PARAM_AccessCommand();
                accessCmd.AirProtocolTagSpec = new UNION_AirProtocolTagSpec();
                accessCmd.AirProtocolTagSpec.Add(tagSpec);

                switch (m_qtmode)
                {
                case 0:
                    PARAM_C1G2Read readStdTID = new PARAM_C1G2Read();
                    readStdTID.AccessPassword = 0;
                    readStdTID.MB             = new TwoBits(2);
                    readStdTID.OpSpecID       = 1;
                    readStdTID.WordCount      = 2;
                    readStdTID.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readStdTID);
                    break;

                case 1:
                    PARAM_C1G2Write writePassword = new PARAM_C1G2Write();
                    writePassword.OpSpecID       = 2;
                    writePassword.MB             = new TwoBits(0);
                    writePassword.AccessPassword = m_password;
                    writePassword.WordPointer    = 2;
                    writePassword.WriteData      = new UInt16Array();
                    writePassword.WriteData.Add((UInt16)((m_newPassword >> 16) & 0x0000ffff));
                    writePassword.WriteData.Add((UInt16)(m_newPassword & 0x0000ffff));
                    accessCmd.AccessCommandOpSpec.Add(writePassword);
                    break;

                case 2:
                    PARAM_C1G2Read readSerializedTID = new PARAM_C1G2Read();
                    readSerializedTID.AccessPassword = 0;
                    readSerializedTID.MB             = new TwoBits(2);
                    readSerializedTID.OpSpecID       = 3;
                    readSerializedTID.WordCount      = 6;
                    readSerializedTID.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readSerializedTID);

                    PARAM_C1G2Read readPublicEPC = new PARAM_C1G2Read();
                    readPublicEPC.AccessPassword = 0;
                    readPublicEPC.MB             = new TwoBits(2);
                    readPublicEPC.OpSpecID       = 4;
                    readPublicEPC.WordCount      = 6;
                    readPublicEPC.WordPointer    = 6;
                    accessCmd.AccessCommandOpSpec.Add(readPublicEPC);

                    PARAM_C1G2Read readUser = new PARAM_C1G2Read();
                    readUser.AccessPassword = 0;
                    readUser.MB             = new TwoBits(3);
                    readUser.OpSpecID       = 5;
                    readUser.WordCount      = 32;
                    readUser.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readUser);
                    break;

                case 3:
                    PARAM_ImpinjGetQTConfig getQT = new PARAM_ImpinjGetQTConfig();
                    getQT.OpSpecID       = 6;
                    getQT.AccessPassword = m_password;
                    accessCmd.AccessCommandOpSpec.Add(getQT);
                    break;

                case 4:
                    PARAM_ImpinjSetQTConfig setQTPrivate = new PARAM_ImpinjSetQTConfig();
                    setQTPrivate.OpSpecID       = 7;
                    setQTPrivate.AccessPassword = m_password;
                    setQTPrivate.Persistence    = ENUM_ImpinjQTPersistence.Permanent;
                    setQTPrivate.DataProfile    = ENUM_ImpinjQTDataProfile.Private;
                    setQTPrivate.AccessRange    = m_shortRange;
                    accessCmd.AccessCommandOpSpec.Add(setQTPrivate);
                    break;

                case 5:
                    PARAM_ImpinjSetQTConfig setQTPublic = new PARAM_ImpinjSetQTConfig();
                    setQTPublic.OpSpecID       = 8;
                    setQTPublic.AccessPassword = m_password;
                    setQTPublic.Persistence    = ENUM_ImpinjQTPersistence.Permanent;
                    setQTPublic.DataProfile    = ENUM_ImpinjQTDataProfile.Public;
                    setQTPublic.AccessRange    = m_shortRange;
                    accessCmd.AccessCommandOpSpec.Add(setQTPublic);
                    break;

                case 6:
                    PARAM_ImpinjSetQTConfig setQTPeek = new PARAM_ImpinjSetQTConfig();
                    setQTPeek.OpSpecID       = 9;
                    setQTPeek.AccessPassword = m_password;
                    setQTPeek.Persistence    = ENUM_ImpinjQTPersistence.Temporary;
                    setQTPeek.DataProfile    = ENUM_ImpinjQTDataProfile.Private;
                    setQTPeek.AccessRange    = ENUM_ImpinjQTAccessRange.Normal_Range;
                    accessCmd.AccessCommandOpSpec.Add(setQTPeek);

                    PARAM_C1G2Read readSerializedTIDPeek = new PARAM_C1G2Read();
                    readSerializedTIDPeek.AccessPassword = 0;
                    readSerializedTIDPeek.MB             = new TwoBits(2);
                    readSerializedTIDPeek.OpSpecID       = 10;
                    readSerializedTIDPeek.WordCount      = 6;
                    readSerializedTIDPeek.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readSerializedTIDPeek);

                    PARAM_C1G2Read readPrivateEPC = new PARAM_C1G2Read();
                    readPrivateEPC.AccessPassword = 0;
                    readPrivateEPC.MB             = new TwoBits(1);
                    readPrivateEPC.OpSpecID       = 11;
                    readPrivateEPC.WordCount      = 8;
                    readPrivateEPC.WordPointer    = 2;
                    accessCmd.AccessCommandOpSpec.Add(readPrivateEPC);

                    PARAM_C1G2Read readUserPeek = new PARAM_C1G2Read();
                    readUserPeek.AccessPassword = 0;
                    readUserPeek.MB             = new TwoBits(3);
                    readUserPeek.OpSpecID       = 12;
                    readUserPeek.WordCount      = 32;
                    readUserPeek.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readUserPeek);
                    break;

                case 7:
                    PARAM_C1G2Write writeUser = new PARAM_C1G2Write();
                    writeUser.AccessPassword = m_password;
                    writeUser.OpSpecID       = 13;
                    writeUser.WordPointer    = 0;
                    writeUser.MB             = new TwoBits(3);

                    writeUser.WriteData = new UInt16Array();
                    for (int x = 0; x < 32; x++)
                    {
                        writeUser.WriteData.Add((UInt16)m_random.Next(65536));
                    }

                    accessCmd.AccessCommandOpSpec.Add(writeUser);
                    break;

                case 8:
                    PARAM_C1G2Write writePubEPC = new PARAM_C1G2Write();
                    writePubEPC.AccessPassword = m_password;
                    writePubEPC.MB             = new TwoBits(2);
                    writePubEPC.OpSpecID       = 14;
                    writePubEPC.WordPointer    = 6;

                    writePubEPC.WriteData = new UInt16Array();
                    for (int x = 0; x < 6; x++)
                    {
                        writePubEPC.WriteData.Add((UInt16)m_random.Next(65536));
                    }

                    accessCmd.AccessCommandOpSpec.Add(writePubEPC);
                    break;

                case 9:
                    PARAM_C1G2Read readRsvd = new PARAM_C1G2Read();
                    readRsvd.AccessPassword = m_password;
                    readRsvd.MB             = new TwoBits(0);
                    readRsvd.OpSpecID       = 15;
                    readRsvd.WordCount      = 4;
                    readRsvd.WordPointer    = 0;
                    accessCmd.AccessCommandOpSpec.Add(readRsvd);
                    break;
                }

                // create the stop trigger for the Access Spec
                PARAM_AccessSpecStopTrigger stop = new PARAM_AccessSpecStopTrigger();
                stop.AccessSpecStopTrigger = ENUM_AccessSpecStopTriggerType.Null;
                stop.OperationCountValue   = 0;

                // Create and set up the basic accessSpec
                PARAM_AccessSpec accessSpec = new PARAM_AccessSpec();
                accessSpec.AccessSpecID = 24;
                accessSpec.AntennaID    = 0;
                accessSpec.ROSpecID     = 0;
                accessSpec.CurrentState = ENUM_AccessSpecState.Disabled;
                accessSpec.ProtocolID   = ENUM_AirProtocols.EPCGlobalClass1Gen2;

                // add the access command and stop trigger to the accessSpec
                accessSpec.AccessCommand         = accessCmd;
                accessSpec.AccessSpecStopTrigger = stop;

                // Add the Access Spec to the ADD_ACCESSSPEC message
                MSG_ADD_ACCESSSPEC addAccess = new MSG_ADD_ACCESSSPEC();
                addAccess.MSG_ID     = msgID++;
                addAccess.AccessSpec = accessSpec;

                // communicate the message to the reader
                MSG_ERROR_MESSAGE           msg_err;
                MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(addAccess, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ACCESSSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableAccessSpec
            {
                Console.WriteLine("Enabling AccessSpec\n");
                MSG_ENABLE_ACCESSSPEC msg = new MSG_ENABLE_ACCESSSPEC();
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE msg_err;
                msg.AccessSpecID = 24; // this better match the ACCESSSPEC we created above
                MSG_ENABLE_ACCESSSPEC_RESPONSE rsp = reader.ENABLE_ACCESSSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ACCESSSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableRoSpec
            {
                Console.WriteLine("Enabling RoSpec\n");
                MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
                msg.MSG_ID = msgID++;
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the ROSpec we created above
                MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region StartRoSpec
            {
                Console.WriteLine("Starting RoSpec\n");
                MSG_START_ROSPEC msg = new MSG_START_ROSPEC();
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("START_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            // this should be plenty long enough to do these commands
            Thread.Sleep(3000);

            #region StopRoSpec
            {
                Console.WriteLine("Stopping RoSpec\n");
                MSG_STOP_ROSPEC   msg = new MSG_STOP_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("STOP_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region Clean Up Reader Configuration
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = msgID++;; // note this doesn't need to bet set as the library will default

                // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }

            #endregion

            Console.WriteLine("  Received " + opSpecCount + " OpSpec Results.");
            Console.WriteLine("  Received " + reportCount + " Tag Reports.");
            Console.WriteLine("  Received " + eventCount + " Events.");
            Console.WriteLine("Closing\n");
            // clean up the reader
            reader.Close();
            reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification);
            reader.OnRoAccessReportReceived  -= new delegateRoAccessReport(reader_OnRoAccessReportReceived);
        }
Exemple #10
0
        public void ConfigReader()
        {
            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = 1; // not this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region SetReaderConfig
            {
                Console.WriteLine("Adding SET_READER_CONFIG n");

                // Communicate that message to the reader
                MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();


                msg.ResetToFactoryDefault = false;

                // turn off all reports
                msg.ROReportSpec = new PARAM_ROReportSpec();
                msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
                msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID             = true;
                msg.ROReportSpec.TagReportContentSelector.EnableAntennaID                = true;
                msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex             = true;
                msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp       = true;
                msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true;
                msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp        = true;
                msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI     = true;
                msg.ROReportSpec.TagReportContentSelector.EnableROSpecID     = true;
                msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex    = true;
                msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

                // report all tags immediately
                msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
                msg.ROReportSpec.N = 1;

                msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
                msg.ReaderEventNotificationSpec.EventNotificationState                      = new PARAM_EventNotificationState[1];
                msg.ReaderEventNotificationSpec.EventNotificationState[0]                   = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType         = ENUM_NotificationEventType.ROSpec_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = true;
                PARAM_ImpinjTagReportContentSelector impinjTagData = new PARAM_ImpinjTagReportContentSelector();
                impinjTagData.ImpinjEnableGPSCoordinates = new PARAM_ImpinjEnableGPSCoordinates();
                impinjTagData.ImpinjEnableGPSCoordinates.GPSCoordinatesMode = ENUM_ImpinjGPSCoordinatesMode.Enabled;
                impinjTagData.ImpinjEnablePeakRSSI = new PARAM_ImpinjEnablePeakRSSI();
                impinjTagData.ImpinjEnablePeakRSSI.PeakRSSIMode                     = ENUM_ImpinjPeakRSSIMode.Enabled;
                impinjTagData.ImpinjEnableRFPhaseAngle                              = new PARAM_ImpinjEnableRFPhaseAngle();
                impinjTagData.ImpinjEnableRFPhaseAngle.RFPhaseAngleMode             = ENUM_ImpinjRFPhaseAngleMode.Enabled;
                impinjTagData.ImpinjEnableRFDopplerFrequency                        = new PARAM_ImpinjEnableRFDopplerFrequency();
                impinjTagData.ImpinjEnableRFDopplerFrequency.RFDopplerFrequencyMode = ENUM_ImpinjRFDopplerFrequencyMode.Enabled;

                msg.ROReportSpec.Custom.Add(impinjTagData);



                MSG_ERROR_MESSAGE msg_err;

                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion
        }
 /// <summary>
 /// Set Antenna CheckPort
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetAntennaDetection(Object val)
 {
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     PARAM_ThingMagicAntennaDetection antennaDetection = new PARAM_ThingMagicAntennaDetection();
     antennaDetection.AntennaDetection = (bool)val;
     msgSetConfig.AddCustomParameter(antennaDetection);
     try
     {
         MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
        private string SetReaderConfig()
        {
            string response = string.Empty;
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();
            msg.AccessReportSpec = new PARAM_AccessReportSpec();
            msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

            msg.AntennaConfiguration = new PARAM_AntennaConfiguration[1];
            msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration();
            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();

            PARAM_C1G2InventoryCommand cmd = new PARAM_C1G2InventoryCommand();
            cmd.C1G2RFControl = new PARAM_C1G2RFControl();
            cmd.C1G2RFControl.ModeIndex = 2;
            cmd.C1G2RFControl.Tari = 0;
            cmd.C1G2SingulationControl = new PARAM_C1G2SingulationControl();
            cmd.C1G2SingulationControl.Session = new LTKD.TwoBits(1);
            cmd.C1G2SingulationControl.TagPopulation = 0;
            cmd.C1G2SingulationControl.TagTransitTime = 1000;
            cmd.TagInventoryStateAware = false;

            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(cmd);
            msg.AntennaConfiguration[0].AntennaID = 0;


            msg.AntennaConfiguration[0].RFReceiver = new PARAM_RFReceiver();
            msg.AntennaConfiguration[0].RFReceiver.ReceiverSensitivity = 12;

            msg.AntennaConfiguration[0].RFTransmitter = new PARAM_RFTransmitter();
            msg.AntennaConfiguration[0].RFTransmitter.ChannelIndex = 1;
            msg.AntennaConfiguration[0].RFTransmitter.HopTableID = 1;
            msg.AntennaConfiguration[0].RFTransmitter.TransmitPower = 61;

            msg.EventsAndReports = new PARAM_EventsAndReports();
            msg.EventsAndReports.HoldEventsAndReportsUponReconnect = false;

            msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
            msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Null;
            msg.KeepaliveSpec.PeriodicTriggerValue = 0;

            msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            msg.ReaderEventNotificationSpec.EventNotificationState = new PARAM_EventNotificationState[5];
            msg.ReaderEventNotificationSpec.EventNotificationState[0] = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType = ENUM_NotificationEventType.AISpec_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[1] = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType = ENUM_NotificationEventType.Antenna_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[2] = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType = ENUM_NotificationEventType.GPI_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[3] = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType = ENUM_NotificationEventType.Reader_Exception_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[4] = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType = ENUM_NotificationEventType.RFSurvey_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = true;

            msg.ROReportSpec = new PARAM_ROReportSpec();
            msg.ROReportSpec.N = 1;
            msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
            msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector = new UNION_AirProtocolEPCMemorySelector();
            PARAM_C1G2EPCMemorySelector c1g2mem = new PARAM_C1G2EPCMemorySelector();
            c1g2mem.EnableCRC = true;
            c1g2mem.EnablePCBits = true;
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector.Add(c1g2mem);

            msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = true;
            msg.ROReportSpec.TagReportContentSelector.EnableAntennaID = true;
            msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex = true;
            msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = true;
            msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true;
            msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = true;
            msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true;
            msg.ROReportSpec.TagReportContentSelector.EnableROSpecID = false;
            msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex = true;
            msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

            msg.ResetToFactoryDefault = false;

            MSG_SET_READER_CONFIG_RESPONSE rsp = llrp.SET_READER_CONFIG(msg, out errorMessage, 3000);

            if (rsp != null)
            {
                response = rsp.ToString();
            }
            else if (errorMessage != null)
            {
                response = errorMessage.ToString();
            }
            else
            {
                response = "Command time out!";
            }
            return response;

        }
Exemple #13
0
        static void Main(string[] args)
        {
            LLRPClient reader;

            if (args.Length != 1)
            {
                usage();
                return;
            }
            string readerName = args[0];


            Console.WriteLine(
                "Impinj C# LTK.NET RFID Application DocSample4 reader - " +
                readerName + "\n");

            #region Initializing
            {
                Console.WriteLine("Initializing\n");

                //Create an instance of LLRP reader client.
                reader = new LLRPClient();

                //Impinj Best Practice! Always Install the Impinj extensions
                Impinj_Installer.Install();
            }
            #endregion

            #region EventHandlers
            {
                Console.WriteLine("Adding Event Handlers\n");
                reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification);
                reader.OnRoAccessReportReceived  += new delegateRoAccessReport(reader_OnRoAccessReportReceived);
            }
            #endregion

            #region Connecting
            {
                Console.WriteLine("Connecting To Reader\n");

                ENUM_ConnectionAttemptStatusType status;

                //Open the reader connection.  Timeout after 5 seconds
                bool ret = reader.Open(readerName, 5000, out status);

                //Ensure that the open succeeded and that the reader
                // returned the correct connection status result

                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader \n");
                    return;
                }
            }
            #endregion

            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = 1; // not this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region getReaderCapabilities
            {
                Console.WriteLine("Getting Reader Capabilities\n");

                MSG_GET_READER_CAPABILITIES cap = new MSG_GET_READER_CAPABILITIES();
                cap.MSG_ID        = 2; // not this doesn't need to bet set as the library will default
                cap.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All;

                //Send the custom message and wait for 8 seconds
                MSG_ERROR_MESSAGE msg_err;
                MSG_GET_READER_CAPABILITIES_RESPONSE msg_rsp =
                    reader.GET_READER_CAPABILITIES(cap, out msg_err, 8000);

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("GET reader Capabilities Command Timed out\n");
                    reader.Close();
                    return;
                }

                // Get the reader model number
                PARAM_GeneralDeviceCapabilities dev_cap = msg_rsp.GeneralDeviceCapabilities;

                // Check to make sure the model number mathces and that this device
                // is an impinj reader (deviceManufacturerName == 25882)
                if ((dev_cap != null) &&
                    (dev_cap.DeviceManufacturerName == 25882))
                {
                    modelNumber = dev_cap.ModelName;
                }
                else
                {
                    Console.WriteLine("Could not determine reader model number\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region SetReaderConfigWithXML
            {
                Console.WriteLine("Adding SET_READER_CONFIG from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\setReaderConfig.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // Communicate that message to the reader
                MSG_SET_READER_CONFIG msg = (MSG_SET_READER_CONFIG)obj;

                MSG_ERROR_MESSAGE msg_err;
                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        Console.WriteLine(rsp.LLRPStatus.ErrorDescription.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDRoSpecWithXML
            {
                Console.WriteLine("Adding RoSpec from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\addRoSpec.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ROSPEC)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // covert to the proper message type
                MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj;

                // Communicate that message to the reader
                MSG_ERROR_MESSAGE       msg_err;
                MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableRoSpec
            {
                Console.WriteLine("Enabling RoSpec\n");
                MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the ROSpec we created above
                MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region StartRoSpec
            {
                Console.WriteLine("Starting RoSpec\n");
                MSG_START_ROSPEC  msg = new MSG_START_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("START_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            // wait around to collect some data
            Thread.Sleep(60000);

            #region StopRoSpec
            {
                Console.WriteLine("Stopping RoSpec\n");
                MSG_STOP_ROSPEC   msg = new MSG_STOP_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("STOP_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region Clean Up Reader Configuration
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; // not this doesn't need to bet set as the library will default

                // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }

            #endregion

            Console.WriteLine("  Calculated " + directionCount + " Velocity Estimates.");
            Console.WriteLine("  Received " + reportCount + " Tag Reports.");
            Console.WriteLine("  Received " + eventCount + " Events.");
            Console.WriteLine("Closing\n");
            // clean up the reader
            reader.Close();
            reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification);
            reader.OnRoAccessReportReceived  -= new delegateRoAccessReport(reader_OnRoAccessReportReceived);
        }
 /// <summary>
 /// Set Gen2Target
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetCustomGen2Target(Object val)
 { 
     PARAM_ThingMagicTargetStrategy target = new PARAM_ThingMagicTargetStrategy();
     target.ThingMagicTargetStrategyValue = (ENUM_ThingMagicC1G2TargetStrategy)val; 
     PARAM_Gen2CustomParameters custGen2 = new PARAM_Gen2CustomParameters();
     custGen2.ThingMagicTargetStrategy = target;
     PARAM_ThingMagicProtocolConfiguration protocolConfig = new PARAM_ThingMagicProtocolConfiguration();
     protocolConfig.Gen2CustomParameters = custGen2;
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     msgSetConfig.AddCustomParameter(protocolConfig);
     try
     {
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
Exemple #15
0
        private void Set_Reader_Config()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();
            //msg.AccessReportSpec = new PARAM_AccessReportSpec();
            //msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

            PARAM_C1G2InventoryCommand cmd = new PARAM_C1G2InventoryCommand();

            cmd.C1G2RFControl                         = new PARAM_C1G2RFControl();
            cmd.C1G2RFControl.ModeIndex               = 2;
            cmd.C1G2RFControl.Tari                    = 0;
            cmd.C1G2SingulationControl                = new PARAM_C1G2SingulationControl();
            cmd.C1G2SingulationControl.Session        = new TwoBits(1);
            cmd.C1G2SingulationControl.TagPopulation  = 0;
            cmd.C1G2SingulationControl.TagTransitTime = 1000;
            cmd.TagInventoryStateAware                = false;

            PARAM_ImpinjInventorySearchMode search_mode = new PARAM_ImpinjInventorySearchMode();

            search_mode.InventorySearchMode = ENUM_ImpinjInventorySearchType.Dual_Target;
            cmd.AddCustomParameter(search_mode);

            msg.AntennaConfiguration    = new PARAM_AntennaConfiguration[1];
            msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration();
            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();

            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(cmd);
            msg.AntennaConfiguration[0].AntennaID = 0;

            msg.AntennaConfiguration[0].RFReceiver = new PARAM_RFReceiver();
            msg.AntennaConfiguration[0].RFReceiver.ReceiverSensitivity = 12;

            msg.AntennaConfiguration[0].RFTransmitter = new PARAM_RFTransmitter();
            msg.AntennaConfiguration[0].RFTransmitter.ChannelIndex  = 1;
            msg.AntennaConfiguration[0].RFTransmitter.HopTableID    = 1;
            msg.AntennaConfiguration[0].RFTransmitter.TransmitPower = 61;

            ////msg.AntennaProperties = new PARAM_AntennaProperties[1];
            ////msg.AntennaProperties[0] = new PARAM_AntennaProperties();
            ////msg.AntennaProperties[0].AntennaConnected = true;
            ////msg.AntennaProperties[0].AntennaGain = 0;
            ////msg.AntennaProperties[0].AntennaID = 1;



            //PARAM_ImpinjFixedFrequencyList fix_list = new PARAM_ImpinjFixedFrequencyList();
            //fix_list.FixedFrequencyMode = ENUM_FixedFrequencyMode.Disabled;
            //cmd.AddCustomParameter(fix_list);

            //PARAM_ImpinjPresetPowerFrequencyList power_list = new PARAM_ImpinjPresetPowerFrequencyList();
            //power_list.PresetPowerMode = ENUM_PresetPowerMode.Disabled;
            //power_list.Reserved = 0;
            //cmd.AddCustomParameter(power_list);

            //PARAM_ImpinjLowDutyCycle lowDuty = new PARAM_ImpinjLowDutyCycle();
            //lowDuty.LowDutyCycleMode = ENUM_LowDutyCycleMode.Disabled;
            //lowDuty.EmptyFieldTimeout = 0;
            //lowDuty.FieldPingInterval = 0;
            //cmd.AddCustomParameter(lowDuty);

            //msg.EventsAndReports = new PARAM_EventsAndReports();
            //msg.EventsAndReports.HoldEventsAndReportsUponReconnect = false;

            //msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
            //msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Null;
            //msg.KeepaliveSpec.PeriodicTriggerValue = 0;

            //msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            //msg.ReaderEventNotificationSpec.EventNotificationState = new PARAM_EventNotificationState[5];
            //msg.ReaderEventNotificationSpec.EventNotificationState[0] = new PARAM_EventNotificationState();
            //msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType = ENUM_NotificationEventType.AISpec_Event;
            //msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = true;

            //msg.ReaderEventNotificationSpec.EventNotificationState[1] = new PARAM_EventNotificationState();
            //msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType = ENUM_NotificationEventType.Antenna_Event;
            //msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = true;

            //msg.ReaderEventNotificationSpec.EventNotificationState[2] = new PARAM_EventNotificationState();
            //msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType = ENUM_NotificationEventType.GPI_Event;
            //msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = true;

            //msg.ReaderEventNotificationSpec.EventNotificationState[3] = new PARAM_EventNotificationState();
            //msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType = ENUM_NotificationEventType.Reader_Exception_Event;
            //msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = true;

            //msg.ReaderEventNotificationSpec.EventNotificationState[4] = new PARAM_EventNotificationState();
            //msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType = ENUM_NotificationEventType.RFSurvey_Event;
            //msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = true;

            msg.ROReportSpec   = new PARAM_ROReportSpec();
            msg.ROReportSpec.N = 1;
            msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;

            msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector = new UNION_AirProtocolEPCMemorySelector();
            PARAM_C1G2EPCMemorySelector c1g2mem = new PARAM_C1G2EPCMemorySelector();

            c1g2mem.EnableCRC    = true;
            c1g2mem.EnablePCBits = true;
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector.Add(c1g2mem);

            msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID             = true;
            msg.ROReportSpec.TagReportContentSelector.EnableAntennaID                = true;
            msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex             = true;
            msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp       = true;
            msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true;
            msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp        = true;
            msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI     = true;
            msg.ROReportSpec.TagReportContentSelector.EnableROSpecID     = false;
            msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex    = true;
            msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

            msg.GPIPortCurrentState               = new PARAM_GPIPortCurrentState[1];
            msg.GPIPortCurrentState[0]            = new PARAM_GPIPortCurrentState();
            msg.GPIPortCurrentState[0].Config     = true;
            msg.GPIPortCurrentState[0].GPIPortNum = 2;
            msg.GPIPortCurrentState[0].State      = ENUM_GPIPortState.Low;

            msg.GPOWriteData                  = new PARAM_GPOWriteData[1];
            msg.GPOWriteData[0]               = new PARAM_GPOWriteData();
            msg.GPOWriteData[0].GPOData       = true;
            msg.GPOWriteData[0].GPOPortNumber = 1;

            //PARAM_ImpinjTagDirectionReporting imp_tag_reporting = new PARAM_ImpinjTagDirectionReporting();

            //imp_tag_reporting.AntennaConfiguration = ENUM_TagDirectionAntennaConfiguration.Dual_Antenna;
            //imp_tag_reporting.EnableTagDirection = true;
            //imp_tag_reporting.Reserved = 0;

            //msg.ROReportSpec.AddCustomParameter(imp_tag_reporting);

            ////PARAM_ImpinjSubRegulatoryRegion sub_region = new PARAM_ImpinjSubRegulatoryRegion();
            ////sub_region.RegulatoryRegion = ENUM_ImpinjRegulatoryRegion.FCC_Part_15_247;
            ////msg.AddCustomParameter(sub_region);

            //msg.ResetToFactoryDefault = false;

            MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);

            if (rsp != null)
            {
                textBox2.Text = rsp.ToString();
            }
            else if (msg_err != null)
            {
                textBox2.Text = rsp.ToString();
            }
            else
            {
                textBox2.Text = "Commmand time out!";
            }
        }
 /// <summary>
 /// Set Gen2Q
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetCustomGen2Q(Object val)
 {
     PARAM_Gen2Q q = new PARAM_Gen2Q();
     if (val is Gen2.StaticQ)
     {
         q.Gen2QType = ENUM_QType.Static;
         q.InitQValue = ((Gen2.StaticQ)val).InitialQ;
     }
     else
     {
         q.Gen2QType = ENUM_QType.Dynamic;
         q.InitQValue = 0;
     }
     PARAM_Gen2CustomParameters custGen2 = new PARAM_Gen2CustomParameters();
     custGen2.Gen2Q = q;
     PARAM_ThingMagicProtocolConfiguration protocolConfig = new PARAM_ThingMagicProtocolConfiguration();
     protocolConfig.Gen2CustomParameters = custGen2;
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     msgSetConfig.AddCustomParameter(protocolConfig);
     try
     {
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
 /// <summary>
 /// Set write transmit power list
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetWriteTransmitPowerList(Object val)
 {
     int power = 0;
     int[] amode = new int[antennaMax];
     string[] rpoint = new string[antennaMax];
     PARAM_ThingMagicAntennaConfiguration[] paramAntennaConfig = new PARAM_ThingMagicAntennaConfiguration[antennaMax];
     //Get readpointdescription, antennamode
     MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG();
     msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification;
     PARAM_ThingMagicDeviceControlConfiguration deviceConfig = new PARAM_ThingMagicDeviceControlConfiguration();
     deviceConfig.RequestedData = ENUM_ThingMagicControlConfiguration.ThingMagicAntennaConfiguration;
     msgGetConfig.AddCustomParameter(deviceConfig);
     try
     {
         MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig);
         for (int count = 0; count < antennaMax; count++)
         {
             paramAntennaConfig[count] = (PARAM_ThingMagicAntennaConfiguration)msgGetConfigResp.Custom[count];
         }
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     //Set PortWritePowerList
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     int[][] prpListValues = (int[][])val;
     foreach (int[] row in prpListValues)
     {
         PARAM_ThingMagicAntennaConfiguration pa = new PARAM_ThingMagicAntennaConfiguration();
         PARAM_RFTransmitter prf = new PARAM_RFTransmitter();
         List<int> pwrValueList = new List<int>();
         foreach (DictionaryEntry pwrEntry in PowerIndexTable)
         {
             pwrValueList.Add(Convert.ToInt32(pwrEntry.Key));
         }
         int[] pwrValue = pwrValueList.ToArray();
         Array.Sort(pwrValue);
         if ((row[0] > 0) && (row[0] <= antennaMax))
         {
             power = row[1];
             ValidatePowerLevel(power);
             if ((model.Equals("Astra-EX")) && (regionId.Equals(Region.NA)) && (row[0] == 1))
             {
                 if (power > 3000)
                 {
                     throw new ArgumentOutOfRangeException(String.Format("Requested power ({0:D}) too high (RFPowerMax={1:D}cdBm)", power, 3000));
                 }
             }
             if (true == PowerIndexTable.ContainsKey(Convert.ToInt16(power)))
             {
                 paramAntennaConfig[row[0] - 1].WriteTransmitPower.WriteTransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]);
             }
             else
             {
                 power = RoundOffPowerLevel(power, pwrValue);
                 paramAntennaConfig[row[0] - 1].WriteTransmitPower.WriteTransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]);
             }
             msgSetConfig.AddCustomParameter(paramAntennaConfig[row[0] - 1]);
         }
         else
         {
             throw new ArgumentOutOfRangeException("Antenna id is invalid");
         }
     }
     try
     {
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
 /// <summary>
 /// Set License Key
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetThingMagicLicenseKey(Object val)
 {   
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp = null;
     try
     {
         PARAM_ThingMagicLicenseKey licenseKey = new PARAM_ThingMagicLicenseKey();
         string key = ByteFormat.ToHex((byte[])val).Split('x')[1];
         licenseKey.LicenseKey = LTKD.ByteArray.FromHexString(key);
         msgSetConfig.AddCustomParameter(licenseKey);
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
         if (msgSetConfigResp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
         {
             throw new ReaderException(msgSetConfigResp.LLRPStatus.ErrorDescription.ToString());
         }
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
 private void SetHoldReportsAndEvents(bool objYes)
 {
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     PARAM_EventsAndReports eventsAndReports = new PARAM_EventsAndReports();
     eventsAndReports.HoldEventsAndReportsUponReconnect = objYes;
     msgSetConfig.EventsAndReports = eventsAndReports;
     try
     {
         MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
 }
 /// <summary>
 /// Set async off time
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetAsyncOffTime(Object val)
 {
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     PARAM_ThingMagicAsyncOFFTime asyncOffTime = new PARAM_ThingMagicAsyncOFFTime();            
     try
     {
         asyncOffTime.AsyncOFFTime = Convert.ToUInt32(val);
         msgSetConfig.AddCustomParameter(asyncOffTime);
         MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
Exemple #21
0
        static void Main(string[] args)
        {
            LLRPClient reader;

            if (args.Length != 1)
            {
                usage();
                return;
            }
            string readerName = args[0];


            Console.WriteLine(
                "Impinj C# LTK.NET RFID Application DocSample2 reader - " +
                readerName + "\n");

            #region Initializing
            {
                Console.WriteLine("Initializing\n");

                //Create an instance of LLRP reader client.
                reader = new LLRPClient();

                //Impinj Best Practice! Always Install the Impinj extensions
                Impinj_Installer.Install();
            }
            #endregion

            #region EventHandlers
            {
                Console.WriteLine("Adding Event Handlers\n");
                reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification);
                reader.OnRoAccessReportReceived  += new delegateRoAccessReport(reader_OnRoAccessReportReceived);
            }
            #endregion

            #region Connecting
            {
                Console.WriteLine("Connecting To Reader\n");

                ENUM_ConnectionAttemptStatusType status;

                //Open the reader connection.  Timeout after 5 seconds
                bool ret = reader.Open(readerName, 5000, out status);

                //Ensure that the open succeeded and that the reader
                // returned the correct connection status result

                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader \n");
                    return;
                }
            }
            #endregion

            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = 1; // not this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region getReaderCapabilities
            {
                Console.WriteLine("Getting Reader Capabilities\n");

                MSG_GET_READER_CAPABILITIES cap = new MSG_GET_READER_CAPABILITIES();
                cap.MSG_ID        = 2; // not this doesn't need to bet set as the library will default
                cap.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All;

                //Send the custom message and wait for 8 seconds
                MSG_ERROR_MESSAGE msg_err;
                MSG_GET_READER_CAPABILITIES_RESPONSE msg_rsp =
                    reader.GET_READER_CAPABILITIES(cap, out msg_err, 8000);

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("GET reader Capabilities Command Timed out\n");
                    reader.Close();
                    return;
                }

                // Get the reader model number
                PARAM_GeneralDeviceCapabilities dev_cap = msg_rsp.GeneralDeviceCapabilities;

                // Check to make sure the model number mathces and that this device
                // is an impinj reader (deviceManufacturerName == 25882)
                if ((dev_cap != null) &&
                    (dev_cap.DeviceManufacturerName == 25882))
                {
                }
                else
                {
                    Console.WriteLine("Could not determine reader model number\n");
                    reader.Close();
                    return;
                }


                // get the uhf band capabilities.  Inside this is the power table.
                // take the last element of the power table to get the highest power.
                PARAM_UHFBandCapabilities          uhf   = msg_rsp.RegulatoryCapabilities.UHFBandCapabilities;
                PARAM_TransmitPowerLevelTableEntry entry =
                    uhf.TransmitPowerLevelTableEntry[uhf.TransmitPowerLevelTableEntry.Length - 1];
                txPwrIndx = entry.Index;
                double power = entry.TransmitPowerValue / 100;

                Console.WriteLine("     Max Power " + power.ToString() + " dbm.");
            }
            #endregion

            #region getReaderConfig
            {
                Console.WriteLine("Getting Reader Configuration\n");

                MSG_GET_READER_CONFIG cap = new MSG_GET_READER_CONFIG();
                cap.MSG_ID        = 2; // not this doesn't need to bet set as the library will default
                cap.RequestedData = ENUM_GetReaderConfigRequestedData.All;

                //Send the custom message and wait for 8 seconds
                MSG_ERROR_MESSAGE msg_err;
                MSG_GET_READER_CONFIG_RESPONSE msg_rsp =
                    reader.GET_READER_CONFIG(cap, out msg_err, 8000);

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("GET reader Config Command Timed out\n");
                    reader.Close();
                    return;
                }

                // Get the hopTableId and Channel Index
                if ((null != msg_rsp.AntennaConfiguration) &&
                    (0 < msg_rsp.AntennaConfiguration.Length) &&
                    (null != msg_rsp.AntennaConfiguration[0].RFTransmitter))
                {
                    PARAM_RFTransmitter rftx =
                        msg_rsp.AntennaConfiguration[0].RFTransmitter;

                    // we have to get these two values as well otherwise
                    // we won't know what to fill in the RFTransmitter
                    // parameter when we set transmit power
                    ChannelIndex = rftx.ChannelIndex;
                    hopTableID   = rftx.HopTableID;
                    Console.WriteLine(" Saving ChanIndex " +
                                      ChannelIndex.ToString() +
                                      " hopTableId " +
                                      hopTableID.ToString());
                }
                else
                {
                    Console.WriteLine("Could not get rf transmitter parameters\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region SetReaderConfigWithXML
            {
                Console.WriteLine("Adding SET_READER_CONFIG from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\setReaderConfig.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // Communicate that message to the reader
                MSG_SET_READER_CONFIG msg = (MSG_SET_READER_CONFIG)obj;

                // set the max power available but don' forget to
                // apply the hoptable and channelIndex from the
                // current configuration
                PARAM_AntennaConfiguration ant = msg.AntennaConfiguration[0];
                ant.RFTransmitter.TransmitPower = (ushort)txPwrIndx;
                ant.RFTransmitter.ChannelIndex  = (ushort)ChannelIndex;
                ant.RFTransmitter.HopTableID    = (ushort)hopTableID;

                MSG_ERROR_MESSAGE msg_err;
                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDRoSpecWithXML
            {
                Console.WriteLine("Adding RoSpec from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\addRoSpec.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ROSPEC)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // covert to the proper message type
                MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj;

                // Communicate that message to the reader
                MSG_ERROR_MESSAGE       msg_err;
                MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableRoSpec
            {
                Console.WriteLine("Enabling RoSpec\n");
                MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the ROSpec we created above
                MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region StartRoSpec
            {
                Console.WriteLine("Starting RoSpec\n");
                MSG_START_ROSPEC  msg = new MSG_START_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("START_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            // wait around to collect some data
            Thread.Sleep(60000);

            #region StopRoSpec
            {
                Console.WriteLine("Stopping RoSpec\n");
                MSG_STOP_ROSPEC   msg = new MSG_STOP_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("STOP_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region Clean Up Reader Configuration
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; // not this doesn't need to bet set as the library will default

                // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }

            #endregion

            Console.WriteLine("  Received " + reportCount + " Tag Reports.");
            Console.WriteLine("  Received " + eventCount + " Events.");
            Console.WriteLine("Closing\n");
            // clean up the reader
            reader.Close();
            reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification);
            reader.OnRoAccessReportReceived  -= new delegateRoAccessReport(reader_OnRoAccessReportReceived);
        }
 /// <summary>
 /// Set Session
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetSession(Object val)
 {
     PARAM_C1G2SingulationControl singulation = new PARAM_C1G2SingulationControl();
     List<PARAM_AntennaConfiguration> antConfigList = new List<PARAM_AntennaConfiguration>();
     foreach (int antennaId in antennaPorts)
     {
         singulation.Session = new LTKD.TwoBits(Convert.ToUInt16(val));
         PARAM_AntennaConfiguration antConfig = new PARAM_AntennaConfiguration();
         UNION_AirProtocolInventoryCommandSettings airProtocolInventoryList = new UNION_AirProtocolInventoryCommandSettings();
         PARAM_C1G2InventoryCommand inventoryCommand = new PARAM_C1G2InventoryCommand();
         inventoryCommand.C1G2SingulationControl = singulation;
         airProtocolInventoryList.Add(inventoryCommand);
         antConfig.AirProtocolInventoryCommandSettings = airProtocolInventoryList;
         //Set the default AntennaId value
         antConfig.AntennaID = (ushort)(antennaId);
         antConfigList.Add(antConfig);
     }
     MSG_SET_READER_CONFIG setReadConfig = new MSG_SET_READER_CONFIG();
     setReadConfig.AntennaConfiguration = antConfigList.ToArray();
     try
     {
         MSG_SET_READER_CONFIG_RESPONSE response = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(setReadConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
Exemple #23
0
        // Sets the client's configuration
        public void Set_Reader_Config(ReaderManager.ReaderConfig readerconfig)
        {
            // find number of antennas to set
            byte   numAntennaToSet = 0;
            ushort antennaSet      = 0;

            for (int i = 0; i < readerconfig.antennaID.Length; i++)
            {
                if (readerconfig.antennaID[i])
                {
                    antennaSet = (ushort)i;
                    numAntennaToSet++;
                }
            }
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.AccessReportSpec = new PARAM_AccessReportSpec();
            msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

            PARAM_C1G2InventoryCommand cmd = new PARAM_C1G2InventoryCommand();

            cmd.C1G2RFControl = new PARAM_C1G2RFControl();
            //cmd.C1G2RFControl.ModeIndex = 1000;
            cmd.C1G2RFControl.ModeIndex               = readerconfig.modeIndex;
            cmd.C1G2RFControl.Tari                    = 0;
            cmd.C1G2SingulationControl                = new PARAM_C1G2SingulationControl();
            cmd.C1G2SingulationControl.Session        = new TwoBits(0);
            cmd.C1G2SingulationControl.TagPopulation  = readerconfig.tagPopulation;
            cmd.C1G2SingulationControl.TagTransitTime = readerconfig.tagTransitTime;
            cmd.TagInventoryStateAware                = false;

            msg.AntennaConfiguration = new PARAM_AntennaConfiguration[numAntennaToSet];
            for (ushort i = 1; i < numAntennaToSet + 1; i++)
            {
                msg.AntennaConfiguration[i - 1] = new PARAM_AntennaConfiguration();
                msg.AntennaConfiguration[i - 1].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();
                msg.AntennaConfiguration[i - 1].AirProtocolInventoryCommandSettings.Add(cmd);

                msg.AntennaConfiguration[i - 1].AntennaID = antennaSet;

                msg.AntennaConfiguration[i - 1].RFReceiver = new PARAM_RFReceiver();
                msg.AntennaConfiguration[i - 1].RFReceiver.ReceiverSensitivity = readerconfig.readerSensitivity;

                msg.AntennaConfiguration[i - 1].RFTransmitter = new PARAM_RFTransmitter();
                msg.AntennaConfiguration[i - 1].RFTransmitter.ChannelIndex  = readerconfig.channelIndex;
                msg.AntennaConfiguration[i - 1].RFTransmitter.HopTableID    = readerconfig.hopTableIndex;
                msg.AntennaConfiguration[i - 1].RFTransmitter.TransmitPower = (ushort)(61 - (readerconfig.attenuation * 4));
            }
            //msg.AntennaProperties = new PARAM_AntennaProperties[1];
            //msg.AntennaProperties[0] = new PARAM_AntennaProperties();
            //msg.AntennaProperties[0].AntennaConnected = true;
            //msg.AntennaProperties[0].AntennaGain = 0;
            //msg.AntennaProperties[0].AntennaID = 1;

            msg.EventsAndReports = new PARAM_EventsAndReports();
            msg.EventsAndReports.HoldEventsAndReportsUponReconnect = false;

            msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
            msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Null;
            msg.KeepaliveSpec.PeriodicTriggerValue = readerconfig.periodicTriggerValue;

            msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            msg.ReaderEventNotificationSpec.EventNotificationState                      = new PARAM_EventNotificationState[5];
            msg.ReaderEventNotificationSpec.EventNotificationState[0]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType         = ENUM_NotificationEventType.AISpec_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = false;

            msg.ReaderEventNotificationSpec.EventNotificationState[1]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType         = ENUM_NotificationEventType.Antenna_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[2]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType         = ENUM_NotificationEventType.GPI_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = false;

            msg.ReaderEventNotificationSpec.EventNotificationState[3]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType         = ENUM_NotificationEventType.Reader_Exception_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[4]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType         = ENUM_NotificationEventType.RFSurvey_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = true;

            msg.ROReportSpec   = new PARAM_ROReportSpec();
            msg.ROReportSpec.N = 1;
            msg.ROReportSpec.ROReportTrigger          = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_AISpec;
            msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector = new UNION_AirProtocolEPCMemorySelector();
            PARAM_C1G2EPCMemorySelector c1g2mem = new PARAM_C1G2EPCMemorySelector();

            c1g2mem.EnableCRC    = false;
            c1g2mem.EnablePCBits = false;
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector.Add(c1g2mem);

            msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID             = false;
            msg.ROReportSpec.TagReportContentSelector.EnableAntennaID                = true;
            msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex             = false;
            msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp       = true;
            msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = false;
            msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp        = false;
            msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI     = true;
            msg.ROReportSpec.TagReportContentSelector.EnableROSpecID     = false;
            msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex    = false;
            msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

            msg.ResetToFactoryDefault = false;

            MSG_SET_READER_CONFIG_RESPONSE rsp = client.SET_READER_CONFIG(msg, out msg_err, 3000);

            if (rsp != null)
            {
                //textBox2.Text = rsp.ToString() + "\n";
                WriteMessage(rsp.ToString(), "setReaderConfig");
            }
            else if (msg_err != null)
            {
                WriteMessage("setReaderConfig " + rsp.ToString() + "\n");
            }
            else
            {
                WriteMessage("setReaderConfig Commmand time out!" + "\n");
            }
        }
Exemple #24
0
    public static void ParseXMLToLLRPMessage(string xmlstr, out object msg, out ENUM_LLRP_MSG_TYPE type)
    {
        XmlDocument xdoc = new XmlDocument();

        xdoc.LoadXml(xmlstr);
        XmlNode node = (XmlNode)xdoc.DocumentElement;

        switch (node.Name)
        {
        case "CUSTOM_MESSAGE":
            msg  = (object)MSG_CUSTOM_MESSAGE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.CUSTOM_MESSAGE;
            return;

        case "GET_READER_CAPABILITIES":
            msg  = (object)MSG_GET_READER_CAPABILITIES.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES;
            return;

        case "GET_READER_CAPABILITIES_RESPONSE":
            msg  = (object)MSG_GET_READER_CAPABILITIES_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_READER_CAPABILITIES_RESPONSE;
            return;

        case "ADD_ROSPEC":
            msg  = (object)MSG_ADD_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ADD_ROSPEC;
            return;

        case "ADD_ROSPEC_RESPONSE":
            msg  = (object)MSG_ADD_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ADD_ROSPEC_RESPONSE;
            return;

        case "DELETE_ROSPEC":
            msg  = (object)MSG_DELETE_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC;
            return;

        case "DELETE_ROSPEC_RESPONSE":
            msg  = (object)MSG_DELETE_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DELETE_ROSPEC_RESPONSE;
            return;

        case "START_ROSPEC":
            msg  = (object)MSG_START_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.START_ROSPEC;
            return;

        case "START_ROSPEC_RESPONSE":
            msg  = (object)MSG_START_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.START_ROSPEC_RESPONSE;
            return;

        case "STOP_ROSPEC":
            msg  = (object)MSG_STOP_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.STOP_ROSPEC;
            return;

        case "STOP_ROSPEC_RESPONSE":
            msg  = (object)MSG_STOP_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.STOP_ROSPEC_RESPONSE;
            return;

        case "ENABLE_ROSPEC":
            msg  = (object)MSG_ENABLE_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC;
            return;

        case "ENABLE_ROSPEC_RESPONSE":
            msg  = (object)MSG_ENABLE_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ENABLE_ROSPEC_RESPONSE;
            return;

        case "DISABLE_ROSPEC":
            msg  = (object)MSG_DISABLE_ROSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC;
            return;

        case "DISABLE_ROSPEC_RESPONSE":
            msg  = (object)MSG_DISABLE_ROSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DISABLE_ROSPEC_RESPONSE;
            return;

        case "GET_ROSPECS":
            msg  = (object)MSG_GET_ROSPECS.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_ROSPECS;
            return;

        case "GET_ROSPECS_RESPONSE":
            msg  = (object)MSG_GET_ROSPECS_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_ROSPECS_RESPONSE;
            return;

        case "ADD_ACCESSSPEC":
            msg  = (object)MSG_ADD_ACCESSSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC;
            return;

        case "ADD_ACCESSSPEC_RESPONSE":
            msg  = (object)MSG_ADD_ACCESSSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC_RESPONSE;
            return;

        case "DELETE_ACCESSSPEC":
            msg  = (object)MSG_DELETE_ACCESSSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC;
            return;

        case "DELETE_ACCESSSPEC_RESPONSE":
            msg  = (object)MSG_DELETE_ACCESSSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DELETE_ACCESSSPEC_RESPONSE;
            return;

        case "ENABLE_ACCESSSPEC":
            msg  = (object)MSG_ENABLE_ACCESSSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC;
            return;

        case "ENABLE_ACCESSSPEC_RESPONSE":
            msg  = (object)MSG_ENABLE_ACCESSSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ENABLE_ACCESSSPEC_RESPONSE;
            return;

        case "DISABLE_ACCESSSPEC":
            msg  = (object)MSG_DISABLE_ACCESSSPEC.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC;
            return;

        case "DISABLE_ACCESSSPEC_RESPONSE":
            msg  = (object)MSG_DISABLE_ACCESSSPEC_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.DISABLE_ACCESSSPEC_RESPONSE;
            return;

        case "GET_ACCESSSPECS":
            msg  = (object)MSG_GET_ACCESSSPECS.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS;
            return;

        case "GET_ACCESSSPECS_RESPONSE":
            msg  = (object)MSG_GET_ACCESSSPECS_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_ACCESSSPECS_RESPONSE;
            return;

        case "GET_READER_CONFIG":
            msg  = (object)MSG_GET_READER_CONFIG.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG;
            return;

        case "GET_READER_CONFIG_RESPONSE":
            msg  = (object)MSG_GET_READER_CONFIG_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_READER_CONFIG_RESPONSE;
            return;

        case "SET_READER_CONFIG":
            msg  = (object)MSG_SET_READER_CONFIG.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG;
            return;

        case "SET_READER_CONFIG_RESPONSE":
            msg  = (object)MSG_SET_READER_CONFIG_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG_RESPONSE;
            return;

        case "CLOSE_CONNECTION":
            msg  = (object)MSG_CLOSE_CONNECTION.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION;
            return;

        case "CLOSE_CONNECTION_RESPONSE":
            msg  = (object)MSG_CLOSE_CONNECTION_RESPONSE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.CLOSE_CONNECTION_RESPONSE;
            return;

        case "GET_REPORT":
            msg  = (object)MSG_GET_REPORT.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.GET_REPORT;
            return;

        case "RO_ACCESS_REPORT":
            msg  = (object)MSG_RO_ACCESS_REPORT.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.RO_ACCESS_REPORT;
            return;

        case "KEEPALIVE":
            msg  = (object)MSG_KEEPALIVE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.KEEPALIVE;
            return;

        case "KEEPALIVE_ACK":
            msg  = (object)MSG_KEEPALIVE_ACK.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.KEEPALIVE_ACK;
            return;

        case "READER_EVENT_NOTIFICATION":
            msg  = (object)MSG_READER_EVENT_NOTIFICATION.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.READER_EVENT_NOTIFICATION;
            return;

        case "ENABLE_EVENTS_AND_REPORTS":
            msg  = (object)MSG_ENABLE_EVENTS_AND_REPORTS.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ENABLE_EVENTS_AND_REPORTS;
            return;

        case "ERROR_MESSAGE":
            msg  = (object)MSG_ERROR_MESSAGE.FromString(xmlstr);
            type = ENUM_LLRP_MSG_TYPE.ERROR_MESSAGE;
            return;

        default:
            msg  = null;
            type = 0;
            return;
        }
    }
Exemple #25
0
        private void Set_Reader_Config()
        {
            MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

            msg.AccessReportSpec = new PARAM_AccessReportSpec();
            msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

            msg.AntennaConfiguration    = new PARAM_AntennaConfiguration[1];
            msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration();
            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();

            PARAM_C1G2InventoryCommand cmd = new PARAM_C1G2InventoryCommand();

            cmd.C1G2RFControl                         = new PARAM_C1G2RFControl();
            cmd.C1G2RFControl.ModeIndex               = 2;
            cmd.C1G2RFControl.Tari                    = 0;
            cmd.C1G2SingulationControl                = new PARAM_C1G2SingulationControl();
            cmd.C1G2SingulationControl.Session        = new LTKD.TwoBits(1);
            cmd.C1G2SingulationControl.TagPopulation  = 0;
            cmd.C1G2SingulationControl.TagTransitTime = 1000;
            cmd.TagInventoryStateAware                = false;

            msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(cmd);
            msg.AntennaConfiguration[0].AntennaID = 0;


            msg.AntennaConfiguration[0].RFReceiver = new PARAM_RFReceiver();
            msg.AntennaConfiguration[0].RFReceiver.ReceiverSensitivity = 12;

            msg.AntennaConfiguration[0].RFTransmitter = new PARAM_RFTransmitter();
            msg.AntennaConfiguration[0].RFTransmitter.ChannelIndex  = 1;
            msg.AntennaConfiguration[0].RFTransmitter.HopTableID    = 1;
            msg.AntennaConfiguration[0].RFTransmitter.TransmitPower = 61;

            //msg.AntennaProperties = new PARAM_AntennaProperties[1];
            //msg.AntennaProperties[0] = new PARAM_AntennaProperties();
            //msg.AntennaProperties[0].AntennaConnected = true;
            //msg.AntennaProperties[0].AntennaGain = 0;
            //msg.AntennaProperties[0].AntennaID = 1;

            msg.EventsAndReports = new PARAM_EventsAndReports();
            msg.EventsAndReports.HoldEventsAndReportsUponReconnect = false;

            msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
            msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Null;
            msg.KeepaliveSpec.PeriodicTriggerValue = 0;

            msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            msg.ReaderEventNotificationSpec.EventNotificationState                      = new PARAM_EventNotificationState[5];
            msg.ReaderEventNotificationSpec.EventNotificationState[0]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType         = ENUM_NotificationEventType.AISpec_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[1]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType         = ENUM_NotificationEventType.Antenna_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[2]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType         = ENUM_NotificationEventType.GPI_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[3]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType         = ENUM_NotificationEventType.Reader_Exception_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = true;

            msg.ReaderEventNotificationSpec.EventNotificationState[4]                   = new PARAM_EventNotificationState();
            msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType         = ENUM_NotificationEventType.RFSurvey_Event;
            msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = true;

            msg.ROReportSpec   = new PARAM_ROReportSpec();
            msg.ROReportSpec.N = 1;
            msg.ROReportSpec.ROReportTrigger          = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
            msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector = new UNION_AirProtocolEPCMemorySelector();
            PARAM_C1G2EPCMemorySelector c1g2mem = new PARAM_C1G2EPCMemorySelector();

            c1g2mem.EnableCRC    = true;
            c1g2mem.EnablePCBits = true;
            msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector.Add(c1g2mem);

            msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID             = true;
            msg.ROReportSpec.TagReportContentSelector.EnableAntennaID                = true;
            msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex             = true;
            msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp       = true;
            msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true;
            msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp        = true;
            msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI     = true;
            msg.ROReportSpec.TagReportContentSelector.EnableROSpecID     = false;
            msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex    = true;
            msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

            msg.ResetToFactoryDefault = false;

            MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 3000);

            if (rsp != null)
            {
                textBox2.Text = rsp.ToString();
            }
            else if (msg_err != null)
            {
                textBox2.Text = rsp.ToString();
            }
            else
            {
                textBox2.Text = "Commmand time out!";
            }
        }
 private object SetReadTransmitPowerList(Object val)
 {
     int power = 0;
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigRes = new MSG_SET_READER_CONFIG_RESPONSE();
     List<PARAM_AntennaConfiguration> ac = new List<PARAM_AntennaConfiguration>();
     int[][] prpListValues = (int[][])val;
     foreach (int[] row in prpListValues)
     {
         PARAM_AntennaConfiguration pa = new PARAM_AntennaConfiguration();
         PARAM_RFTransmitter prf = new PARAM_RFTransmitter();
         if ((row[0] > 0) && (row[0] <= antennaMax))
         {
             power = row[1];
             ValidatePowerLevel(power);                    
             pa.AntennaID = (ushort)row[0];
             if ((model.Equals("Astra-EX")) && (regionId.Equals(Region.NA)) && (pa.AntennaID == 1))
             {
                 if (power > 3000)
                 {
                     throw new ArgumentOutOfRangeException(String.Format("Requested power ({0:D}) too high (RFPowerMax={1:D}cdBm)", power, 3000));
                 }
             }
             List<int> pwrValueList = new List<int>();
             foreach (DictionaryEntry pwrEntry in PowerIndexTable)
             {
                 pwrValueList.Add(Convert.ToInt32(pwrEntry.Key));
             }
             int[] pwrValue = pwrValueList.ToArray();
             Array.Sort(pwrValue);
             if (true == PowerIndexTable.ContainsKey(Convert.ToInt16(power)))
             {
                 prf.TransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]);
             }
             else
             {
                 power = RoundOffPowerLevel(power, pwrValue);
                 prf.TransmitPower = Convert.ToUInt16(PowerIndexTable[Convert.ToInt16(power)]);
             }
             pa.RFTransmitter = prf;
             ac.Add(pa);
         }
         else
         {
             throw new ArgumentOutOfRangeException("Antenna id is invalid");
         }
     }
     msgSetConfig.AntennaConfiguration = ac.ToArray();
     try
     {
         msgSetConfigRes = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
Exemple #27
0
        private void Set_Reader_Config()
        {
            try
            {
                MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();

                msg.AccessReportSpec = new PARAM_AccessReportSpec();
                msg.AccessReportSpec.AccessReportTrigger = ENUM_AccessReportTriggerType.End_Of_AccessSpec;

                PARAM_C1G2InventoryCommand cmd = new PARAM_C1G2InventoryCommand();
                cmd.C1G2RFControl = new PARAM_C1G2RFControl();

                cmd.C1G2RFControl.ModeIndex = 1000;

                // 1000 = AD - Auto Dense Interrogator
                // 1001 = AS - Auto Single Interrogator
                //    0 = 0 - High Speed 640k bps
                //    1 = 1 - Hybrid 80k/160k bps
                //    2 = 2 - Dense Reader M=4 HiSpd
                //    3 = 3 - Dense Reader M=8 LoSpd
                //    4 = 4 - Dense Reader MaxMiller
                cmd.C1G2RFControl.Tari = 0;
                cmd.C1G2SingulationControl = new PARAM_C1G2SingulationControl();
                cmd.C1G2SingulationControl.Session = new TwoBits(1);
                cmd.C1G2SingulationControl.TagPopulation = 32;

                cmd.C1G2SingulationControl.Session.Equals(1);

                cmd.C1G2SingulationControl.TagTransitTime = 0;
                cmd.TagInventoryStateAware = false;
                PARAM_ImpinjInventorySearchMode search_mode = new PARAM_ImpinjInventorySearchMode();

                search_mode.InventorySearchMode = ENUM_ImpinjInventorySearchType.Dual_Target;

                //search_mode.InventorySearchMode = ENUM_ImpinjInventorySearchType.Dual_Target;
                cmd.AddCustomParameter(search_mode);

                //msg.AntennaConfiguration[0].AntennaID = 0;  // 0 = all 4 antennas

                //msg.AntennaConfiguration = new PARAM_AntennaConfiguration[1];
                /*
                if (cbAnt1.Checked == true)
                {
                    msg.AntennaConfiguration[0].AntennaID = 1;
                }

                if (cbAnt2.Checked == true)
                {
                    msg.AntennaConfiguration[0].AntennaID = 2;
                }

                if (cbAnt3.Checked == true)
                {
                    msg.AntennaConfiguration[0].AntennaID = 3;
                }

                if (cbAnt4.Checked == true)
                {
                    msg.AntennaConfiguration[0].AntennaID = 4;
                }
               */
                msg.AntennaConfiguration = new PARAM_AntennaConfiguration[0];
                msg.AntennaConfiguration[0].AntennaID = 0;
                //
                msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration();
                msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();
                //msg.AntennaConfiguration[0] = new PARAM_AntennaConfiguration();

                msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings = new UNION_AirProtocolInventoryCommandSettings();
                msg.AntennaConfiguration[0].AirProtocolInventoryCommandSettings.Add(cmd);
                msg.AntennaConfiguration[0].RFReceiver = new PARAM_RFReceiver();
                msg.AntennaConfiguration[0].RFReceiver.ReceiverSensitivity = 1;// (ushort)tbReaderSensitivity.Value;
                // 1 = max, 2 = -70, 3 = -69, 4 = -68, 5 = -67...
                msg.AntennaConfiguration[0].RFTransmitter = new PARAM_RFTransmitter();
                msg.AntennaConfiguration[0].RFTransmitter.ChannelIndex = 1;
                msg.AntennaConfiguration[0].RFTransmitter.HopTableID = 1;
                msg.AntennaConfiguration[0].RFTransmitter.TransmitPower = 30;//(ushort)tbTxPower.Value;

                //###########################################################################################
                //###########################################################################################
                //###########################################################################################
                // made change so Matho could test channel index values for Japanese readers
                //ushort i;
                //i = ushort.Parse(tbChannelIndex.Text);
                //msg.AntennaConfiguration[0].RFTransmitter.ChannelIndex = i;
                //MessageBox.Show("Channel Index = " + i.ToString());
                // made change so Matho could test channel index values for Japanese readers
                //###########################################################################################
                //###########################################################################################
                //###########################################################################################

                //////if you want to set antenana property. un-comment following code. Impinj reader does not support
                //msg.AntennaProperties = new PARAM_AntennaProperties[1];
                //msg.AntennaProperties[0] = new PARAM_AntennaProperties();
                //msg.AntennaProperties[0].AntennaConnected = true;
                //msg.AntennaProperties[0].AntennaGain = 0;
                //msg.AntennaProperties[0].AntennaID = 0;
                //////If you want to enable fixed frequency feature. un-comment following code.
                //PARAM_ImpinjFixedFrequencyList fix_list = new PARAM_ImpinjFixedFrequencyList();
                //fix_list.FixedFrequencyMode = ENUM_FixedFrequencyMode.Disabled;
                //cmd.AddCustomParameter(fix_list);
                //////If you want to enable reduced power list, un-comment following code and add channels
                //PARAM_ImpinjReducedPowerFrequencyList power_list = new PARAM_ImpinjReducedPowerFrequencyList();
                //power_list.ReducedPowerMode = ENUM_ImpinjReducedPowerMode.Enabled;
                //power_list.ChannelList.Add(chanellist);
                //cmd.AddCustomParameter(power_list);
                //////If you want to enable low duty cycle, un-comment following code
                //PARAM_ImpinjLowDutyCycle lowDuty = new PARAM_ImpinjLowDutyCycle();
                //lowDuty.LowDutyCycleMode =  ENUM_ImpinjLowDutyCycleMode.Disabled;
                //lowDuty.EmptyFieldTimeout = 0;
                //lowDuty.FieldPingInterval = 0;
                //cmd.AddCustomParameter(lowDuty);
                //////If you want to select reader events to send to application, change the following code
                //msg.EventsAndReports = new PARAM_EventsAndReports();
                //msg.EventsAndReports.HoldEventsAndReportsUponReconnect = false;
                //msg.KeepaliveSpec = new PARAM_KeepaliveSpec();
                //msg.KeepaliveSpec.KeepaliveTriggerType = ENUM_KeepaliveTriggerType.Null;
                //msg.KeepaliveSpec.PeriodicTriggerValue = 0;
                msg.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
                msg.ReaderEventNotificationSpec.EventNotificationState = new PARAM_EventNotificationState[7];
                msg.ReaderEventNotificationSpec.EventNotificationState[0] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[0].EventType = ENUM_NotificationEventType.AISpec_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[0].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[1] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[1].EventType = ENUM_NotificationEventType.Antenna_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[1].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[2] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[2].EventType = ENUM_NotificationEventType.GPI_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[2].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[3] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[3].EventType = ENUM_NotificationEventType.Reader_Exception_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[3].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[4] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[4].EventType = ENUM_NotificationEventType.Upon_Hopping_To_Next_Channel;
                msg.ReaderEventNotificationSpec.EventNotificationState[4].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[5] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[5].EventType = ENUM_NotificationEventType.ROSpec_Event;
                msg.ReaderEventNotificationSpec.EventNotificationState[5].NotificationState = false;

                msg.ReaderEventNotificationSpec.EventNotificationState[6] = new PARAM_EventNotificationState();
                msg.ReaderEventNotificationSpec.EventNotificationState[6].EventType = ENUM_NotificationEventType.Report_Buffer_Fill_Warning;
                msg.ReaderEventNotificationSpec.EventNotificationState[6].NotificationState = false;

                msg.ROReportSpec = new PARAM_ROReportSpec();
                msg.ROReportSpec.N = 1;
                msg.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;

                msg.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();

                msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector = new UNION_AirProtocolEPCMemorySelector();
                PARAM_C1G2EPCMemorySelector c1g2mem = new PARAM_C1G2EPCMemorySelector();
                c1g2mem.EnableCRC = false;
                c1g2mem.EnablePCBits = false;
                msg.ROReportSpec.TagReportContentSelector.AirProtocolEPCMemorySelector.Add(c1g2mem);

                msg.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = false;
                msg.ROReportSpec.TagReportContentSelector.EnableAntennaID = false;
                msg.ROReportSpec.TagReportContentSelector.EnableChannelIndex = false;
                msg.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = true;
                msg.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = false;
                msg.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = false;
                msg.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true;
                msg.ROReportSpec.TagReportContentSelector.EnableROSpecID = false;
                msg.ROReportSpec.TagReportContentSelector.EnableSpecIndex = false;
                msg.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = false;

                /////If you want to enable GPIO function, un-comment following code.

                //msg.GPIPortCurrentState = new PARAM_GPIPortCurrentState[1];
                //msg.GPIPortCurrentState[0] = new PARAM_GPIPortCurrentState();
                //msg.GPIPortCurrentState[0].Config = true;
                //msg.GPIPortCurrentState[0].GPIPortNum = 2;
                //msg.GPIPortCurrentState[0].State = ENUM_GPIPortState.Low;

                //msg.GPOWriteData = new PARAM_GPOWriteData[1];
                //msg.GPOWriteData[0] = new PARAM_GPOWriteData();
                //msg.GPOWriteData[0].GPOData = true;
                //msg.GPOWriteData[0].GPOPortNumber = 1;

                //////If you want to use tag direction function, un-comment following code

                //PARAM_ImpinjTagDirectionReporting imp_tag_reporting = new PARAM_ImpinjTagDirectionReporting();

                //imp_tag_reporting.AntennaConfiguration = ENUM_ImpinjTagDirectionAntennaConfiguration.Dual_Antenna;
                //imp_tag_reporting.EnableTagDirection = true;
                //msg.ROReportSpec.AddCustomParameter(imp_tag_reporting);

                /////If you want to set sub-region, un-comment following code

                //PARAM_ImpinjSubRegulatoryRegion sub_region = new PARAM_ImpinjSubRegulatoryRegion();
                //sub_region.RegulatoryRegion = ENUM_ImpinjRegulatoryRegion.FCC_Part_15_247;
                //msg.AddCustomParameter(sub_region);

                //msg.ResetToFactoryDefault = false;

                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 2121);

            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
        }
 /// <summary>
 /// Set Reader HostName
 /// </summary>
 /// <param name="val"></param>
 /// <returns>object</returns>
 private object SetReaderHostName(Object val)
 {
     string readerDescription = string.Empty;
     string readerRole = string.Empty;
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     PARAM_ThingMagicReaderConfiguration rd = new PARAM_ThingMagicReaderConfiguration();
     MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG();
     msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification;
     PARAM_ThingMagicDeviceControlConfiguration deviceConfig = new PARAM_ThingMagicDeviceControlConfiguration();
     deviceConfig.RequestedData = ENUM_ThingMagicControlConfiguration.ThingMagicReaderConfiguration;
     msgGetConfig.AddCustomParameter(deviceConfig);
     try
     {
         MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig);
         PARAM_ThingMagicReaderConfiguration par = (PARAM_ThingMagicReaderConfiguration)msgGetConfigResp.Custom[0];
         readerDescription = par.ReaderDescription;
         readerRole = par.ReaderRole;
     }
     catch (Exception ex)
     {
         {
             throw new ReaderException(ex.Message);
         }
     }
     string value = (string)val;
     rd.ReaderHostName = value;
     rd.ReaderDescription = readerDescription;
     rd.ReaderRole = readerRole;
     msgSetConfig.AddCustomParameter(rd);
     try
     {
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
 /// <summary>
 /// Set the state of some GPO pins.
 /// </summary>
 /// <param name="state">array of GpioPin objects</param>
 public override void GpoSet(ICollection<GpioPin> state)
 {
     MSG_SET_READER_CONFIG msg = new MSG_SET_READER_CONFIG();
     List<PARAM_GPOWriteData> list = new List<PARAM_GPOWriteData>();
     if (null != state)
     {
         foreach (GpioPin pin in state)
         {
             PARAM_GPOWriteData data = new PARAM_GPOWriteData();
             data.GPOPortNumber = TmToLlrpGpo(pin.Id);
             data.GPOData = pin.High;
             list.Add(data);
         }
     }
     msg.GPOWriteData = list.ToArray();
     SendLlrpMessage(msg);
 }
        private void EnableReaderNotification()
        {
            List<PARAM_EventNotificationState> eStateList = new List<PARAM_EventNotificationState>();

            PARAM_EventNotificationState aiEvent = new PARAM_EventNotificationState();
            aiEvent.EventType = ENUM_NotificationEventType.AISpec_Event;
            aiEvent.NotificationState = true;
            eStateList.Add(aiEvent);
            PARAM_EventNotificationState roEvent = new PARAM_EventNotificationState();
            roEvent.EventType = ENUM_NotificationEventType.ROSpec_Event;
            roEvent.NotificationState = true;
            eStateList.Add(roEvent);

            MSG_SET_READER_CONFIG setReaderConfig = new MSG_SET_READER_CONFIG();
            setReaderConfig.ReaderEventNotificationSpec = new PARAM_ReaderEventNotificationSpec();
            setReaderConfig.ReaderEventNotificationSpec.EventNotificationState = eStateList.ToArray();

            try
            {
                MSG_SET_READER_CONFIG_RESPONSE setReaderConfigResponse = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(setReaderConfig);
            }
            catch (Exception ex)
            {
                throw new ReaderException(ex.Message);
            }
        }
 /// <summary>
 /// Set ISO18K6BProtocolConfigurationParams
 /// </summary>
 /// <param name="val"></param>
 /// <param name="type">enum</param>
 /// <returns>object</returns>
 private object SetCustomISO18K6BProtocolConfigurationParams(ISO18K6BProtocolConfigurationParams type, Object val)
 { 
     PARAM_ISO18K6BCustomParameters custIso18k6b = new PARAM_ISO18K6BCustomParameters();
     //Build iso18k6b protocol configuration params
     switch(type)
     {
         case ISO18K6BProtocolConfigurationParams.Delimiter:
             PARAM_ThingMagicISO180006BDelimiter delimiter = new PARAM_ThingMagicISO180006BDelimiter();
             delimiter.ISO18K6BDelimiter = (ENUM_ThingMagicCustom18K6BDelimiter)val;
             custIso18k6b.ThingMagicISO180006BDelimiter = delimiter;
             break;
         case ISO18K6BProtocolConfigurationParams.ModulationDepth:
             PARAM_ThingMagicISO18K6BModulationDepth modulationDepth = new PARAM_ThingMagicISO18K6BModulationDepth();
             modulationDepth.ISO18K6BModulationDepth = (ENUM_ThingMagicCustom18K6BModulationDepth)val;
             custIso18k6b.ThingMagicISO18K6BModulationDepth = modulationDepth;
             break;
         case ISO18K6BProtocolConfigurationParams.LinkFrequency:
             PARAM_ThingMagicISO18K6BLinkFrequency linkFrequency = new PARAM_ThingMagicISO18K6BLinkFrequency();
             linkFrequency.ISO18K6BLinkFrequency = (ENUM_ThingMagicCustom18K6BLinkFrequency)val;
             custIso18k6b.ThingMagicISO18K6BLinkFrequency = linkFrequency;
             break;
     }
     PARAM_ThingMagicProtocolConfiguration protocolConfig = new PARAM_ThingMagicProtocolConfiguration();
     protocolConfig.ISO18K6BCustomParameters = custIso18k6b;
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     msgSetConfig.AddCustomParameter(protocolConfig);
     try
     {
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
 /// <summary>
 /// Set ThingMagic DeDuplication fields such as RecordHighestRssi, UniqueByAntenna and UniqueByData.  
 /// </summary>
 /// <param name="val"></param>
 /// <param name="deDuplicationfield"></param>
 /// <returns>object</returns>
 private object SetThingMagicDeDuplicationFields(Object val, ThingMagicDeDuplication deDuplicationfield)
 {
     MSG_GET_READER_CONFIG msgGetConfig = new MSG_GET_READER_CONFIG();
     MSG_GET_READER_CONFIG_RESPONSE msgGetConfigResp;
     PARAM_ThingMagicDeDuplication defaultdeDuplicationFields;
     msgGetConfig.RequestedData = ENUM_GetReaderConfigRequestedData.Identification;
     PARAM_ThingMagicDeviceControlConfiguration deviceConfig = new PARAM_ThingMagicDeviceControlConfiguration();
     deviceConfig.RequestedData = ENUM_ThingMagicControlConfiguration.ThingMagicDeDuplication;
     msgGetConfig.AddCustomParameter(deviceConfig);
     try
     {
         msgGetConfigResp = (MSG_GET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgGetConfig);
         defaultdeDuplicationFields = (PARAM_ThingMagicDeDuplication)msgGetConfigResp.Custom[0];
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     MSG_SET_READER_CONFIG msgSetConfig = new MSG_SET_READER_CONFIG();
     MSG_SET_READER_CONFIG_RESPONSE msgSetConfigResp;
     try
     {
         switch (deDuplicationfield)
         {
             case ThingMagicDeDuplication.RecordHighestRssi:
                 defaultdeDuplicationFields.RecordHighestRSSI = (bool)val;
                 break;
             case ThingMagicDeDuplication.UniqueByAntenna:
                 defaultdeDuplicationFields.UniqueByAntenna = (bool)val;
                 break;
             case ThingMagicDeDuplication.UniqueByData:
                 defaultdeDuplicationFields.UniqueByData = (bool)val;
                 break;
         }
         msgSetConfig.AddCustomParameter(defaultdeDuplicationFields);
         msgSetConfigResp = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(msgSetConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
     return val;
 }
Exemple #33
0
        static void Main(string[] args)
        {
            LLRPClient reader;

            if (args.Length != 1)
            {
                usage();
                return;
            }
            string readerName = args[0];

            Console.WriteLine(
                "Impinj C# LTK.NET RFID Application DocSample3 reader - " +
                readerName + "\n");

            #region Initializing
            {
                Console.WriteLine("Initializing\n");

                //Create an instance of LLRP reader client.
                reader = new LLRPClient();

                //Impinj Best Practice! Always Install the Impinj extensions
                Impinj_Installer.Install();
            }
            #endregion

            #region EventHandlers
            {
                Console.WriteLine("Adding Event Handlers\n");
                reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification);
                reader.OnRoAccessReportReceived  += new delegateRoAccessReport(reader_OnRoAccessReportReceived);
            }
            #endregion

            #region Connecting
            {
                Console.WriteLine("Connecting To Reader\n");

                ENUM_ConnectionAttemptStatusType status;

                //Open the reader connection.  Timeout after 5 seconds
                bool ret = reader.Open(readerName, 5000, out status);

                //Ensure that the open succeeded and that the reader
                // returned the correct connection status result

                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader \n");
                    return;
                }
            }
            #endregion

            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = msgID++;
                // note :this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = msgID++;
                //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region getReaderCapabilities
            {
                Console.WriteLine("Getting Reader Capabilities\n");

                MSG_GET_READER_CAPABILITIES cap = new MSG_GET_READER_CAPABILITIES();
                cap.MSG_ID        = msgID++;
                cap.RequestedData = ENUM_GetReaderCapabilitiesRequestedData.All;

                //Send the custom message and wait for 8 seconds
                MSG_ERROR_MESSAGE msg_err;
                MSG_GET_READER_CAPABILITIES_RESPONSE msg_rsp =
                    reader.GET_READER_CAPABILITIES(cap, out msg_err, 8000);

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("GET reader Capabilities Command Timed out\n");
                    reader.Close();
                    return;
                }

                // Get the reader model number since some features are not
                // available on Speedway revolution.
                PARAM_GeneralDeviceCapabilities dev_cap = msg_rsp.GeneralDeviceCapabilities;

                // Check to make sure the model number mathces and that this device
                // is an impinj reader (deviceManufacturerName == 25882)
                if ((dev_cap == null) ||
                    (dev_cap.DeviceManufacturerName != 25882))
                {
                    Console.WriteLine("Could not determine reader model number\n");
                    reader.Close();
                    return;
                }

                // Find out how many inventory filters we support
                // don't run the application unless we support at least
                // two inventory filters and 1 access Spec
                PARAM_C1G2LLRPCapabilities g2_cap =
                    (PARAM_C1G2LLRPCapabilities)msg_rsp.AirProtocolLLRPCapabilities[0];
                if ((g2_cap == null) ||
                    (g2_cap.MaxNumSelectFiltersPerQuery < 2))
                {
                    Console.WriteLine("  reader supports " +
                                      g2_cap.MaxNumSelectFiltersPerQuery +
                                      " inventory filters \n");
                    Console.WriteLine("Reader does not support enough" +
                                      " inventory (select) filters--- closing\n");
                    reader.Close();
                    return;
                }

                // find out how many access spec we support.  Don't run
                // the application unless we have 1 accessSpec
                PARAM_LLRPCapabilities llrp_cap = msg_rsp.LLRPCapabilities;
                if ((llrp_cap == null) ||
                    (llrp_cap.MaxNumAccessSpecs < 1))
                {
                    Console.WriteLine("  reader supports " +
                                      llrp_cap.MaxNumAccessSpecs +
                                      " accessSpecs \n");
                    Console.WriteLine("Reader does not support enough" +
                                      " accessSpecs --- closing\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region SetReaderConfigWithXML
            {
                Console.WriteLine("Adding SET_READER_CONFIG from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\setReaderConfig.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.SET_READER_CONFIG)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // Communicate that message to the reader
                MSG_SET_READER_CONFIG msg = (MSG_SET_READER_CONFIG)obj;
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE msg_err;
                MSG_SET_READER_CONFIG_RESPONSE rsp = reader.SET_READER_CONFIG(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDRoSpecWithXML
            {
                Console.WriteLine("Adding RoSpec from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ROSPEC
                try
                {
                    string filename;
                    filename = @"..\..\addRoSpec.xml";
                    FileStream   fs = new FileStream(filename, FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ROSPEC)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                MSG_ADD_ROSPEC msg = (MSG_ADD_ROSPEC)obj;
                msg.MSG_ID = msgID++;

                // Communicate that message to the reader
                MSG_ERROR_MESSAGE       msg_err;
                MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDAccessSpecWithXML
            {
                Console.WriteLine("Adding AccessSpec from XML file \n");

                Org.LLRP.LTK.LLRPV1.DataType.Message obj;
                ENUM_LLRP_MSG_TYPE msg_type;

                // read the XML from a file and validate its an ADD_ACCESS_SPEC
                try
                {
                    FileStream   fs = new FileStream(@"..\..\addAccessSpec.xml", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    string       s  = sr.ReadToEnd();
                    fs.Close();

                    LLRPXmlParser.ParseXMLToLLRPMessage(s, out obj, out msg_type);

                    if (obj == null || msg_type != ENUM_LLRP_MSG_TYPE.ADD_ACCESSSPEC)
                    {
                        Console.WriteLine("Could not extract message from XML");
                        reader.Close();
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("Unable to convert to valid XML");
                    reader.Close();
                    return;
                }

                // Communicate that message to the reader
                MSG_ADD_ACCESSSPEC msg = (MSG_ADD_ACCESSSPEC)obj;
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE           msg_err;
                MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ACCESSSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDAccessSpec
            {
                /* This section adds a second accessSpec identical to the
                 * first (except for its ID).  This is duplicate code with
                 * the goal of showing an example of how to build LLRP specs
                 * from C# objects rather than XML */
                Console.WriteLine("Adding AccessSpec from C# objects \n");

                // create the target tag filter spec to perform access only on these tags
                // This only requires a single filter (LTK/LLRP supports up to 2 )
                PARAM_C1G2TargetTag[] targetTag = new PARAM_C1G2TargetTag[1];
                targetTag[0]         = new PARAM_C1G2TargetTag();
                targetTag[0].Match   = true;
                targetTag[0].MB      = new TwoBits(1);
                targetTag[0].Pointer = 16;
                targetTag[0].TagData = LLRPBitArray.FromHexString("300035");
                targetTag[0].TagMask = LLRPBitArray.FromHexString("f800ff");

                PARAM_C1G2TagSpec tagSpec = new PARAM_C1G2TagSpec();
                tagSpec.C1G2TargetTag = targetTag;

                // create the read operation to perform when this accessSpec is run
                PARAM_C1G2Read read = new PARAM_C1G2Read();
                read.AccessPassword = 0;
                read.MB             = new TwoBits(3);
                read.WordCount      = 2;
                read.WordPointer    = 0;
                read.OpSpecID       = 2;

                // add the opSpec and the TagSpec to the AccessCmd
                PARAM_AccessCommand accessCmd = new PARAM_AccessCommand();
                accessCmd.AirProtocolTagSpec = new UNION_AirProtocolTagSpec();
                accessCmd.AirProtocolTagSpec.Add(tagSpec);
                accessCmd.AccessCommandOpSpec.Add(read);

                // create the stop trigger for the Access Spec
                PARAM_AccessSpecStopTrigger stop = new PARAM_AccessSpecStopTrigger();
                stop.AccessSpecStopTrigger = ENUM_AccessSpecStopTriggerType.Null;
                stop.OperationCountValue   = 0;

                // Create and set up the basic accessSpec
                PARAM_AccessSpec accessSpec = new PARAM_AccessSpec();
                accessSpec.AccessSpecID = 24;
                accessSpec.AntennaID    = 0;
                accessSpec.ROSpecID     = 0;
                accessSpec.CurrentState = ENUM_AccessSpecState.Disabled;
                accessSpec.ProtocolID   = ENUM_AirProtocols.EPCGlobalClass1Gen2;

                // add the access command and stop trigger to the accessSpec
                accessSpec.AccessCommand         = accessCmd;
                accessSpec.AccessSpecStopTrigger = stop;

                // Add the Access Spec to the ADD_ACCESSSPEC message
                MSG_ADD_ACCESSSPEC addAccess = new MSG_ADD_ACCESSSPEC();
                addAccess.MSG_ID     = msgID++;
                addAccess.AccessSpec = accessSpec;

                // communicate the message to the reader
                MSG_ERROR_MESSAGE           msg_err;
                MSG_ADD_ACCESSSPEC_RESPONSE rsp = reader.ADD_ACCESSSPEC(addAccess, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ACCESSSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableAccessSpec
            {
                Console.WriteLine("Enabling AccessSpec\n");
                MSG_ENABLE_ACCESSSPEC msg = new MSG_ENABLE_ACCESSSPEC();
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE msg_err;
                msg.AccessSpecID = 23; // this better match the ACCESSSPEC we created above
                MSG_ENABLE_ACCESSSPEC_RESPONSE rsp = reader.ENABLE_ACCESSSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ACCESSSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableRoSpec
            {
                Console.WriteLine("Enabling RoSpec\n");
                MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
                msg.MSG_ID = msgID++;
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the ROSpec we created above
                MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region StartRoSpec
            {
                Console.WriteLine("Starting RoSpec\n");
                MSG_START_ROSPEC msg = new MSG_START_ROSPEC();
                msg.MSG_ID = msgID++;

                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("START_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            // wait around to collect some data.
            for (int delay = 0; delay < 5; delay++)
            {
                Thread.Sleep(30000);
                #region PollReaderReports
                {
                    Console.WriteLine("Polling Report Data\n");
                    MSG_GET_REPORT    msg = new MSG_GET_REPORT();
                    MSG_ERROR_MESSAGE msg_err;
                    msg.MSG_ID = msgID++;
                    reader.GET_REPORT(msg, out msg_err, 10000);
                }
                #endregion
            }

            #region StopRoSpec
            {
                Console.WriteLine("Stopping RoSpec\n");
                MSG_STOP_ROSPEC   msg = new MSG_STOP_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("STOP_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region Clean Up Reader Configuration
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = msgID++;; // note this doesn't need to bet set as the library will default

                // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }

            #endregion

            Console.WriteLine("  Received " + accessCount + " Access Reports.");
            Console.WriteLine("  Received " + reportCount + " Tag Reports.");
            Console.WriteLine("  Received " + eventCount + " Events.");
            Console.WriteLine("Closing\n");
            // clean up the reader
            reader.Close();
            reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification);
            reader.OnRoAccessReportReceived  -= new delegateRoAccessReport(reader_OnRoAccessReportReceived);
        }
 /// <summary>
 /// Set RF Control
 /// </summary>
 /// <param name="rfControl"></param>
 private void SetRFControl(PARAM_C1G2RFControl rfControl)
 {
     MSG_SET_READER_CONFIG setConfig = new MSG_SET_READER_CONFIG();
     List<PARAM_AntennaConfiguration> antCfglist = new List<PARAM_AntennaConfiguration>();
     PARAM_AntennaConfiguration antCfg = new PARAM_AntennaConfiguration();
     UNION_AirProtocolInventoryCommandSettings airProtocolList = new UNION_AirProtocolInventoryCommandSettings();
     PARAM_C1G2InventoryCommand airProtocol = new PARAM_C1G2InventoryCommand();
     airProtocol.C1G2RFControl = rfControl;
     airProtocolList.Add(airProtocol);
     antCfg.AirProtocolInventoryCommandSettings = airProtocolList;
     antCfg.AntennaID = (ushort)0;
     antCfglist.Add(antCfg);
     setConfig.AntennaConfiguration = antCfglist.ToArray();
     try
     {
         MSG_SET_READER_CONFIG_RESPONSE setResponse = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(setConfig);
     }
     catch (Exception ex)
     {
         throw new ReaderException(ex.Message);
     }
 }
Exemple #35
0
        static void Main(string[] args)
        {
            LLRPClient reader;

            if (args.Length != 1)
            {
                usage();
                return;
            }
            string readerName = args[0];


            Console.WriteLine(
                "Impinj C# LTK.NET RFID Application DocSample1 reader - " +
                readerName + "\n");

            #region Initializing
            {
                Console.WriteLine("Initializing\n");

                //Create an instance of LLRP reader client.
                reader = new LLRPClient();

                //Impinj Best Practice! Always Install the Impinj extensions
                Impinj_Installer.Install();
            }
            #endregion

            #region EventHandlers
            {
                Console.WriteLine("Adding Event Handlers\n");
                // don't need two kinds of reader events, just use encaped here to demonstrate
                //reader.OnReaderEventNotification += new delegateReaderEventNotification(reader_OnReaderEventNotification);
                reader.OnEncapedReaderEventNotification += new delegateEncapReaderEventNotification(reader_OnEncapedReaderEventNotification);
                reader.OnRoAccessReportReceived         += new delegateRoAccessReport(reader_OnRoAccessReportReceived);
            }
            #endregion

            #region Connecting
            {
                Console.WriteLine("Connecting To Reader\n");

                ENUM_ConnectionAttemptStatusType status;

                //Open the reader connection.  Timeout after 5 seconds
                bool ret = reader.Open(readerName, 5000, out status);

                //Ensure that the open succeeded and that the reader
                // returned the correct connection status result

                if (!ret || status != ENUM_ConnectionAttemptStatusType.Success)
                {
                    Console.WriteLine("Failed to Connect to Reader \n");
                    return;
                }
            }
            #endregion

            #region EnableExtensions
            {
                Console.WriteLine("Enabling Impinj Extensions\n");

                MSG_IMPINJ_ENABLE_EXTENSIONS imp_msg =
                    new MSG_IMPINJ_ENABLE_EXTENSIONS();
                MSG_ERROR_MESSAGE msg_err;

                imp_msg.MSG_ID = 1; // not this doesn't need to bet set as the library will default

                //Send the custom message and wait for 8 seconds
                MSG_CUSTOM_MESSAGE cust_rsp = reader.CUSTOM_MESSAGE(imp_msg, out msg_err, 8000);
                MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE msg_rsp =
                    cust_rsp as MSG_IMPINJ_ENABLE_EXTENSIONS_RESPONSE;

                if (msg_rsp != null)
                {
                    if (msg_rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(msg_rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("Enable Extensions Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region FactoryDefault
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; //this doesn't need to bet set as the library will default

                //if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region ADDRoSpecWithObjects
            {
                Console.WriteLine("Adding RoSpec\n");

                // set up the basic parameters in the ROSpec. Use all the defaults from the reader
                MSG_ADD_ROSPEC    msg = new MSG_ADD_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpec = new PARAM_ROSpec();
                msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled;
                msg.ROSpec.Priority     = 0x00;
                msg.ROSpec.ROSpecID     = 1111;

                // setup the start and stop triggers in the Boundary Spec
                msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec();
                msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger();
                msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = ENUM_ROSpecStartTriggerType.Null;

                msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger();
                msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = ENUM_ROSpecStopTriggerType.Null;
                msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue  = 0; // ignored by reader

                // Add a single Antenna Inventory to the ROSpec
                msg.ROSpec.SpecParameter = new UNION_SpecParameter();
                PARAM_AISpec aiSpec = new PARAM_AISpec();

                aiSpec.AntennaIDs = new UInt16Array();
                aiSpec.AntennaIDs.Add(0);       // all antennas
                aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger();
                aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Null;

                // use all the defaults from the reader.  Just specify the minimum required
                aiSpec.InventoryParameterSpec    = new PARAM_InventoryParameterSpec[1];
                aiSpec.InventoryParameterSpec[0] = new PARAM_InventoryParameterSpec();
                aiSpec.InventoryParameterSpec[0].InventoryParameterSpecID = 1234;
                aiSpec.InventoryParameterSpec[0].ProtocolID = ENUM_AirProtocols.EPCGlobalClass1Gen2;

                msg.ROSpec.SpecParameter.Add(aiSpec);

                MSG_ADD_ROSPEC_RESPONSE rsp = reader.ADD_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ADD_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region EnableRoSpec
            {
                Console.WriteLine("Enabling RoSpec\n");
                MSG_ENABLE_ROSPEC msg = new MSG_ENABLE_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the ROSpec we created above
                MSG_ENABLE_ROSPEC_RESPONSE rsp = reader.ENABLE_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("ENABLE_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region StartRoSpec
            {
                Console.WriteLine("Starting RoSpec\n");
                MSG_START_ROSPEC  msg = new MSG_START_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_START_ROSPEC_RESPONSE rsp = reader.START_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("START_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            // wait around to collect some data
            Thread.Sleep(10000);

            #region StopRoSpec
            {
                Console.WriteLine("Stopping RoSpec\n");
                MSG_STOP_ROSPEC   msg = new MSG_STOP_ROSPEC();
                MSG_ERROR_MESSAGE msg_err;
                msg.ROSpecID = 1111; // this better match the RoSpec we created above
                MSG_STOP_ROSPEC_RESPONSE rsp = reader.STOP_ROSPEC(msg, out msg_err, 12000);
                if (rsp != null)
                {
                    if (rsp.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("STOP_ROSPEC Command Timed out\n");
                    reader.Close();
                    return;
                }
            }
            #endregion

            #region Clean Up Reader Configuration
            {
                Console.WriteLine("Factory Default the Reader\n");

                // factory default the reader
                MSG_SET_READER_CONFIG msg_cfg = new MSG_SET_READER_CONFIG();
                MSG_ERROR_MESSAGE     msg_err;

                msg_cfg.ResetToFactoryDefault = true;
                msg_cfg.MSG_ID = 2; // not this doesn't need to bet set as the library will default

                // Note that if SET_READER_CONFIG affects antennas it could take several seconds to return
                MSG_SET_READER_CONFIG_RESPONSE rsp_cfg = reader.SET_READER_CONFIG(msg_cfg, out msg_err, 12000);

                if (rsp_cfg != null)
                {
                    if (rsp_cfg.LLRPStatus.StatusCode != ENUM_StatusCode.M_Success)
                    {
                        Console.WriteLine(rsp_cfg.LLRPStatus.StatusCode.ToString());
                        reader.Close();
                        return;
                    }
                }
                else if (msg_err != null)
                {
                    Console.WriteLine(msg_err.ToString());
                    reader.Close();
                    return;
                }
                else
                {
                    Console.WriteLine("SET_READER_CONFIG Command Timed out\n");
                    reader.Close();
                    return;
                }
            }

            #endregion

            Console.WriteLine("  Received " + reportCount + " Reports.");
            Console.WriteLine("  Received " + eventCount + " Events.");
            Console.WriteLine("Closing\n");
            // clean up the reader
            reader.Close();
            reader.OnReaderEventNotification -= new delegateReaderEventNotification(reader_OnReaderEventNotification);
            reader.OnRoAccessReportReceived  -= new delegateRoAccessReport(reader_OnRoAccessReportReceived);
        }
        /// <summary>
        /// Set Tari
        /// </summary>
        /// <param name="tari"></param>
        /// <returns>object</returns>
        private object SetTari(Object tari)
        {
            PARAM_C1G2RFControl rfControl = GetRFcontrol();
            uint modeIndex = rfControl.ModeIndex;
            PARAM_C1G2UHFRFModeTableEntry RFMode = (PARAM_C1G2UHFRFModeTableEntry)RFModeCache[modeIndex];
            uint maxTari = RFMode.MaxTariValue;
            uint minTari = RFMode.MinTariValue; 
            rfControl.Tari = Convert.ToUInt16(GetTariValue((Gen2.Tari)tari));
            if (rfControl.Tari < minTari || rfControl.Tari > maxTari)
            {
                throw new ReaderException("Tari value is out of range for this RF mode");
            }
            //Get the AntennaId value
            List<PARAM_AntennaConfiguration> antConfigList = new List<PARAM_AntennaConfiguration>();
            //Get the TagInventoryStateAware value
            foreach (int antennaId in antennaPorts)
            {
                PARAM_AntennaConfiguration antConfig = new PARAM_AntennaConfiguration();
                //Get the ModeIndex value
                UNION_AirProtocolInventoryCommandSettings airProtocolInventoryList = new UNION_AirProtocolInventoryCommandSettings();

                PARAM_C1G2InventoryCommand inventoryCommand = new PARAM_C1G2InventoryCommand();

                inventoryCommand.C1G2RFControl = rfControl;
                //Set the default TagInventoryStateAware value
                inventoryCommand.TagInventoryStateAware = false;
                airProtocolInventoryList.Add(inventoryCommand);

                antConfig.AirProtocolInventoryCommandSettings = airProtocolInventoryList;
                //Set the default AntennaId value
                antConfig.AntennaID = (ushort)(antennaId);
                antConfigList.Add(antConfig);
            }
            MSG_SET_READER_CONFIG setReadConfig = new MSG_SET_READER_CONFIG();
            setReadConfig.AntennaConfiguration = antConfigList.ToArray();
            try
            {
                MSG_SET_READER_CONFIG_RESPONSE response = (MSG_SET_READER_CONFIG_RESPONSE)SendLlrpMessage(setReadConfig);               
            }
            catch (Exception ex)
            {
                throw new ReaderException(ex.Message);
            }
            return tari;
        }