Beispiel #1
0
        public new static MSG_ADD_ROSPEC FromString(string str)
        {
            string val;

            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(str);
            XmlNode node = (XmlNode)xdoc.DocumentElement;

            MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC();
            try { msg.MSG_ID = Convert.ToUInt32(XmlUtil.GetNodeAttrValue(node, "MessageID")); }
            catch { }


            try
            {

                XmlNodeList xnl = XmlUtil.GetXmlNodes(node, "ROSpec");
                if (null != xnl)
                {
                    if (xnl.Count != 0)
                        msg.ROSpec = PARAM_ROSpec.FromXmlNode(xnl[0]);
                }

            }
            catch { }

            return msg;
        }
Beispiel #2
0
        public MSG_ADD_ROSPEC_RESPONSE ADD_ROSPEC(MSG_ADD_ROSPEC msg, out MSG_ERROR_MESSAGE msg_err, int time_out)
        {
            msg_err = null;
            //Add your code here
            _event_ADD_ROSPEC_RESPONSE = new ClientManualResetEvent(false);
            _event_ADD_ROSPEC_RESPONSE.msg_id = msg.MSG_ID;
            _event_ERROR_MESSAGE = new ClientManualResetEvent(false);

            WaitHandle[] waitHandles = new WaitHandle[] { _event_ADD_ROSPEC_RESPONSE.evt, _event_ERROR_MESSAGE.evt };

            bool[] bit_array = msg.ToBitArray();
            byte[] data = Util.ConvertBitArrayToByteArray(bit_array);

            cI.Send(data);

            int wait_result = WaitHandle.WaitAny(waitHandles, time_out, false);

            int cursor = 0;
            int length;
            BitArray bArr;

            try
            {
                switch (wait_result)
                {
                    case 0:
                        bArr = Util.ConvertByteArrayToBitArray(_event_ADD_ROSPEC_RESPONSE.data);
                        length = bArr.Count;
                        MSG_ADD_ROSPEC_RESPONSE msg_rsp = MSG_ADD_ROSPEC_RESPONSE.FromBitArray(ref bArr, ref cursor, length);
                        if (msg_rsp.MSG_ID != msg.MSG_ID) return null;
                        else
                            return msg_rsp;
                    case 1:
                        bArr = Util.ConvertByteArrayToBitArray(_event_ERROR_MESSAGE.data);
                        length = bArr.Count;
                        msg_err = MSG_ERROR_MESSAGE.FromBitArray(ref bArr, ref cursor, length);
                        return null;
                    default:
                        return null;
                }
            }
            catch
            {
                return null;
            }
        }
Beispiel #3
0
        public new static MSG_ADD_ROSPEC FromBitArray(ref BitArray bit_array, ref int cursor, int length)
        {
            if (cursor > length) return null;

            int field_len = 0;
            object obj_val;
            ArrayList param_list = new ArrayList();

            MSG_ADD_ROSPEC obj = new MSG_ADD_ROSPEC();

            int msg_type = 0;
            cursor += 6;
            msg_type = (int)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 10);

            if (msg_type != obj.msgType)
            {
                cursor -= 16;
                return null;
            }

            obj.msgLen = (UInt32)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 32);
            obj.msgID = (UInt32)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 32);


            obj.ROSpec = PARAM_ROSpec.FromBitArray(ref bit_array, ref cursor, length);

            return obj;
        }
Beispiel #4
0
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////




        #region RO Spec
        /// <summary>
        /// Communicates the information of a ROSpec to the Reader.
        /// </summary>
        public void Add_RoSpec(ReaderManager.InventoryConfig inventoryconfig, ReaderManager.ReaderConfig readerconfig)
        {
            // Create a new message to be sent to the client
            MSG_ADD_ROSPEC msg = new MSG_ADD_ROSPEC();

            msg.ROSpec = new PARAM_ROSpec();
            msg.ROSpec.CurrentState = ENUM_ROSpecState.Disabled;   // Reader's current state: Disable 
            msg.ROSpec.Priority = 0x00;     // specifies the priority of the rospect                           
            msg.ROSpec.ROSpecID = 123;

            //==============================
            // Start condition
            msg.ROSpec.ROBoundarySpec = new PARAM_ROBoundarySpec();
            msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger = new PARAM_ROSpecStartTrigger();
            // Null – No start trigger. The only way to start the ROSpec is with a START_ROSPEC from the Client.
            // 1 Immediate
            // 2 Periodic
            // 3 GPI
            // Note: This ROSpect starts immediatelly
            msg.ROSpec.ROBoundarySpec.ROSpecStartTrigger.ROSpecStartTriggerType = inventoryconfig.startTrigger;


            // Stop condition
            msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger = new PARAM_ROSpecStopTrigger();
            // 0 Null – Stop when all AISpecs are done, or when preempted, or with a STOP_ROSPEC from the Client.
            // 1 Duration
            // 2 GPI with a timeout value
            // DurationTriggerValue: Duration in milliseconds

            // Trigger 1
            msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.ROSpecStopTriggerType = inventoryconfig.stopTrigger;

            //msg.ROSpec.ROBoundarySpec.ROSpecStopTrigger.DurationTriggerValue = 1000;


            // ROReportSpec triger 
            // 0 None
            // 1 (Upon N TagReportData Parameters or End of AISpec) Or (End of RFSurveySpec) - N=0 is unlimited.
            // 2 Upon N TagReportData Parameters or End of ROSpec N=0 is unlimited.

            // N: Unsigned Short Integer. This is the number of TagReportData Parameters used in ROReportTrigger = 1 and 2.
            // If N = 0, there is no limit on the number of TagReportData Parameters. 
            // This field SHALL be ignored when ROReportTrigger = 0.
            msg.ROSpec.ROReportSpec = new PARAM_ROReportSpec();
            msg.ROSpec.ROReportSpec.ROReportTrigger = inventoryconfig.reportTrigger;
            msg.ROSpec.ROReportSpec.N = inventoryconfig.reportN;


            // Report 2
            //msg.ROSpec.ROReportSpec.ROReportTrigger = ENUM_ROReportTriggerType.Upon_N_Tags_Or_End_Of_ROSpec;
            //msg.ROSpec.ROReportSpec.N = 0; 

            msg.ROSpec.ROReportSpec.TagReportContentSelector = new PARAM_TagReportContentSelector();
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAccessSpecID = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableAntennaID = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableChannelIndex = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableFirstSeenTimestamp = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableInventoryParameterSpecID = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableLastSeenTimestamp = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnablePeakRSSI = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableROSpecID = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableSpecIndex = true;
            msg.ROSpec.ROReportSpec.TagReportContentSelector.EnableTagSeenCount = true;

            msg.ROSpec.SpecParameter = new UNION_SpecParameter();

            // Antena inventory operation
            PARAM_AISpec aiSpec = new PARAM_AISpec();

            // 12345

            aiSpec.AntennaIDs = new UInt16Array();
            //aiSpec.AntennaIDs.Add(0);       //0 :  applys to all antennae,
            for (ushort i = 1; i < readerconfig.antennaID.Length + 1; i++)
                if (readerconfig.antennaID[i - 1])
                {
                    aiSpec.AntennaIDs.Add(i);
                }
            // Stop trigger parameter 
            // 0 Null – Stop when ROSpec is done.
            // 1 Duration
            // 2 GPI with a timeout value
            // 3 Tag observation

            //if (inventorymode)
            //{
                // TriggerType: Integer
                // Possible Values: Value Modulation
                // ------ ------------
                // 0 Upon seeing N tag observations, or timeout
                // 1 Upon seeing no more new tag observations for t ms,or timeout
                // 2 N attempts to see all tags in the FOV, or timeout

                if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.Tag_Observation)
                {
                    // Antena inventory operation
                    aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger();
                    aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Tag_Observation;
                    aiSpec.AISpecStopTrigger.TagObservationTrigger = new PARAM_TagObservationTrigger();

                    if (inventoryconfig.numAttempts == 0)
                    {
                        // Trigger type 1: works
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.TriggerType = ENUM_TagObservationTriggerType.Upon_Seeing_N_Tags_Or_Timeout;
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.NumberOfTags = inventoryconfig.numTags;
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.Timeout = inventoryconfig.AITimeout;   // There is no time out
                    }
                    else
                    {
                        // Trigger type 2
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.TriggerType = ENUM_TagObservationTriggerType.N_Attempts_To_See_All_Tags_In_FOV_Or_Timeout;
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.NumberOfAttempts = inventoryconfig.numAttempts;
                        aiSpec.AISpecStopTrigger.TagObservationTrigger.Timeout = inventoryconfig.AITimeout;   // There is no time out
                    }

                }
                else if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.Duration)
                {
                    // Antena inventory operation
                    aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger();
                    aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.Duration;
                    aiSpec.AISpecStopTrigger.DurationTrigger = inventoryconfig.duration;
                }

                else if (inventoryconfig.AITriggerType == ENUM_AISpecStopTriggerType.GPI_With_Timeout)
                {
                    aiSpec.AISpecStopTrigger = new PARAM_AISpecStopTrigger();
                    aiSpec.AISpecStopTrigger.AISpecStopTriggerType = ENUM_AISpecStopTriggerType.GPI_With_Timeout;
                    aiSpec.AISpecStopTrigger.GPITriggerValue.Timeout = inventoryconfig.AITimeout;
                }

            //}


            // Operational parameters for an inventory using a single air protocol.
            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);   // Add operational parameters to Add_ROSpec msg

            // Send message to client and get the response

            MSG_ADD_ROSPEC_RESPONSE rsp = client.ADD_ROSPEC(msg, out msg_err, 3000);


            if (rsp != null)
            {
                //textBox2.Text = rsp.ToString() + "\n";
                WriteMessage(rsp.ToString(), "Add_RoSpec");
                WriteMessage("Add_RoSpec \n");
            }
            else if (msg_err != null)
            {
                WriteMessage("Add_RoSpec " + msg_err.ToString() + "\n");
            }
            else
                WriteMessage("Add_RoSpec Command time out!" + "\n");

        }