/// <summary>
 /// Reader Exception EventArgs Constructor
 /// </summary>
 public ReaderExceptionEventArgs(ReaderException readerException)
 {
     _readerException = readerException;
 }
 /// <summary>
 /// Reader Exception EventArgs Constructor
 /// </summary>
 /// <param name="readerException">Reader Exception</param>
 public ReaderExceptionEventArgs(ReaderException readerException)
 {
     _readerException = readerException;
 }
Example #3
0
        private void ParseNotifyTag(MSG_RO_ACCESS_REPORT msg)
        {
            if (null == tagReads)
            {
                tagReads = new List<TagReadData>();
            }
            TagReadData tag = null;
            if (null != msg)
            {
                for (int i = 0; i < msg.TagReportData.Length; i++)
                {
                    try
                    {
                        tag = new TagReadData();
                        if (msg.TagReportData[i].EPCParameter.Count > 0)
                        {
                            string epc;
                            // reports come in two flavors.  Get the right flavor
                            if (msg.TagReportData[i].EPCParameter[0].GetType() == typeof(PARAM_EPC_96))
                            {
                                epc = ((PARAM_EPC_96)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            else
                            {
                                epc = ((PARAM_EPCData)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            TagData td = new TagData(ByteFormat.FromHex(epc));
                            TagProtocol tagProtocol = 0;
                            //Match the recieved rospec id with the rospec id stored in the hashtable at the time of setting readplan
                            if (roSpecProtcolTable.ContainsKey(msg.TagReportData[i].ROSpecID.ROSpecID))
                            {
                                tagProtocol = (TagProtocol)roSpecProtcolTable[msg.TagReportData[i].ROSpecID.ROSpecID];
                            }
                            if (TagProtocol.GEN2.Equals(tagProtocol))
                            {
                                //Get crc and pc bits
                                UNION_AirProtocolTagData tagdata = msg.TagReportData[i].AirProtocolTagData;
                                td = new Gen2.TagData(ByteFormat.FromHex(epc), ByteConv.EncodeU16(((PARAM_C1G2_CRC)tagdata[1]).CRC), ByteConv.EncodeU16(((PARAM_C1G2_PC)tagdata[0]).PC_Bits));
                            }
                            else if (TagProtocol.ISO180006B.Equals(tagProtocol))
                            {
                                td = new Iso180006b.TagData(ByteFormat.FromHex(epc));
                            }
                            else
                            {
                                td = new TagData(ByteFormat.FromHex(epc));
                            }
                            tag.Reader = this;
                            tag._tagData = td;
                            tag._antenna = (int)msg.TagReportData[i].AntennaID.AntennaID;
                            UInt64 usSinceEpoch = msg.TagReportData[i].LastSeenTimestampUTC.Microseconds;
                            tag._baseTime = epochTime.AddMilliseconds(usSinceEpoch / 1000);
                            tag._readOffset = 0;
                            // Since Spruce release firmware doesn't support phase, there won't be PARAM_ThingMagicTagReportContentSelector 
                            // custom paramter in ROReportSpec
                            string[] ver = softwareVersion.Split('.');
                            if (((Convert.ToInt32(ver[0]) == 4) && (Convert.ToInt32(ver[1]) >= 17)) ||
                                (Convert.ToInt32(ver[0]) > 4))
                            {
                                tag._phase = Convert.ToInt32(((PARAM_ThingMagicRFPhase)msg.TagReportData[i].Custom[0]).Phase);
                            }
                            tag.Rssi = Convert.ToInt32(msg.TagReportData[i].PeakRSSI.PeakRSSI.ToString());
                            tag.ReadCount = msg.TagReportData[i].TagSeenCount.TagCount;

                            int chIndex = Convert.ToInt32(msg.TagReportData[i].ChannelIndex.ChannelIndex);
                            List<uint> freq = frequencyHopTable[0].Frequency.data;
                            tag._frequency = Convert.ToInt32(freq[chIndex - 1]);
                            UNION_AccessCommandOpSpecResult opSpecResult = msg.TagReportData[i].AccessCommandOpSpecResult;

                            tag._data = EMPTY_DATA;
                            // Use try-finally to to keep failed tagops from preventing report of TagReadData
                            try
                            {
                                if (null != opSpecResult)
                                {
                                    if (opSpecResult.Count > 0)
                                    {
                                        ParseTagOpSpecResultType(opSpecResult, ref tag);
                                    }
                                }
                            }
                            finally
                            {
                                if (continuousReading)
                                {
                                    OnTagRead(tag);
                                }
                                else
                                {
                                    tagReads.Add(tag);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ReaderException rx;
                        if (ex is ReaderException)
                        {
                            rx = (ReaderException)ex;
                        }
                        else
                        {
                            rx = new ReaderException(ex.ToString());
                        }
                        //Release the TagQueueEmptyEvent when parsing exception raised
                        TagQueueEmptyEvent.Set();
                        ReadExceptionPublisher expub = new ReadExceptionPublisher(this, rx);

                        Thread trd = new Thread(expub.OnReadException);
                        trd.Name = "OnReadException";
                        trd.Start();
                    }
                    finally
                    {
                        tag = null;
                    }
                }
                TagQueueEmptyEvent.Set();
            }
        }
Example #4
0
 private void ProcessRoAccessReport()
 {
     UInt64 iteration = 0;
     while (!stopAsyncReadThread)
     {
         iteration++;
         try
         {
             MSG_RO_ACCESS_REPORT report = null;
             lock (tagReadQueue)
             {
                 if (0 < tagReadQueue.Count)
                 {
                     TagQueueEmptyEvent.Reset();
                     report = (MSG_RO_ACCESS_REPORT)tagReadQueue.Dequeue();                            
                 }
             }
             if (null == report)
             {
                 while (false == TagQueueAddedEvent.WaitOne(0, false))
                 {
                     Thread.Sleep(20);
                     if (stopAsyncReadThread)
                     {
                         //Release the TagQueueEmptyEvent when close the LLRP connection
                         TagQueueEmptyEvent.Set();
                         break;
                     }
                     else
                     {
                         //Continue to wiat the for the RO_ACCESS_REPORT to add
                         continue;
                     }
                 }
             }
             else
             {
                 ParseNotifyTag(report);
             }
         }
         catch (Exception ex)
         {
             ReaderException rex;
             if (ex is ReaderException)
             {
                 rex = (ReaderException)ex;
             }
             else
             {
                 rex = new ReaderException("Parser thread caught exception: " + ex.Message);
             }
             notifyExceptionListeners(rex);
         }
     }            
 }
Example #5
0
 private void ParseTagOpResponse(MSG_RO_ACCESS_REPORT response)
 {
     TagReadData td = new TagReadData();
     UNION_AccessCommandOpSpecResult opSpecResult = response.TagReportData[0].AccessCommandOpSpecResult;
     try
     {
         if (null != opSpecResult)
         {
             if (opSpecResult.Count > 0)
             {
                 ParseTagOpSpecResultType(opSpecResult, ref td);
                 TagQueueEmptyEvent.Set();
             }
         }
     }
     catch (ReaderException ex)
     {
         rx = ex;
         TagQueueEmptyEvent.Set();
     }
     finally
     {
         reportReceived = true;                
     }
     llrp.OnRoAccessReportReceived -= new delegateRoAccessReport(TagOpOnRoAccessReportReceived);
 }
Example #6
0
        /// <summary>
        /// execute a TagOp
        /// </summary>
        /// <param name="tagOP">Tag Operation</param>
        /// <param name="target">Tag filter</param>
        ///<returns>the return value of the tagOp method if available</returns>
        public override Object ExecuteTagOp(TagOp tagOP, TagFilter target)
        {
            //Delegate to receive the Ro Access report
            llrp.OnRoAccessReportReceived += new delegateRoAccessReport(TagOpOnRoAccessReportReceived);
            reportReceived = false;
            isRoAccessReportReceived = false;
            roSpecId = 0;
            
            /*  Reset Reader
            * Delete all ROSpec and AccessSpecs on the reader, so that
            * we don't have to worry about the prior configuration
            * No need to verify the error status. */

            DeleteRoSpec();
            DeleteAccessSpecs();           
            //Though its a standalone tag operation, From server point of view
            //we need to submit requests in the following order.

            // Add ROSpec 
            // Enable ROSpec
            // Add AccessSpec
            // Enable AccessSpec
            // Start ROSpec
            // Wait for response and verify the result

            SimpleReadPlan srp = new SimpleReadPlan();
            srp.Filter = target;
            roSpecProtcolTable = new Hashtable();
            if (tagOP.GetType().Equals(typeof(Iso180006b.ReadData))
                || tagOP.GetType().Equals(typeof(Iso180006b.WriteData)) 
                || tagOP.GetType().Equals(typeof(Iso180006b.LockTag)))
            {
                srp.Protocol = TagProtocol.ISO180006B;
            }
            else
            {
                srp.Protocol = (TagProtocol)ParamGet("/reader/tagop/protocol");
            }
            srp.Antennas = new int[] { (int)ParamGet("/reader/tagop/antenna")};
            srp.Op = tagOP;
            List<PARAM_ROSpec> roSpecList = new List<PARAM_ROSpec>();
            TagQueueEmptyEvent.Reset();
            try
            {
                BuildRoSpec(srp, 0, roSpecList,true);
                if (AddRoSpec(roSpecList[0]))
                {
                    if (EnableRoSpec(roSpecList[0].ROSpecID))
                    {
                        if (!StartRoSpec(roSpecList[0].ROSpecID))
                            return null;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new ReaderException(ex.ToString());
            }
            WaitForSearchEnd(0);
            //wait for ro access report
            while (!reportReceived)
            {
                Thread.Sleep(20);
            }
            ReaderException tempReaderexception = rx;
            try
            {
                if (null == rx)
                {
                    //Update tagOpResponse in UpdateRoReport;
                    if ((tagOP is Gen2.ReadData) 
                        || (tagOP is Gen2.BlockPermaLock) 
                        || (tagOP is Gen2.Impinj.Monza4.QTReadWrite) 
                        || (tagOP is Gen2.NxpGen2TagOp.Calibrate) 
                        || (tagOP is Gen2.NxpGen2TagOp.EasAlarm) 
                        || (tagOP is Gen2.NXP.G2I.ChangeConfig)
                        || (tagOP is Iso180006b.ReadData)
                        || (tagOP is Gen2.IDS.SL900A.GetBatteryLevel) 
                        || (tagOP is Gen2.IDS.SL900A.GetSensorValue)
                        || (tagOP is Gen2.IDS.SL900A.GetLogState)
                        || (tagOP is Gen2.IDS.SL900A.GetCalibrationData) 
                        || (tagOP is Gen2.IDS.SL900A.GetMeasurementSetup)
                        || (tagOP is Gen2.IDS.SL900A.AccessFifoRead)
                        || (tagOP is Gen2.IDS.SL900A.AccessFifoStatus)
                        || (tagOP is Gen2.Denatran.IAV.ActivateSecureMode)
                        || (tagOP is Gen2.Denatran.IAV.ActivateSiniavMode)
                        || (tagOP is Gen2.Denatran.IAV.AuthenticateOBU)
                        || (tagOP is Gen2.Denatran.IAV.OBUAuthFullPass1)
                        || (tagOP is Gen2.Denatran.IAV.OBUAuthFullPass2)
                        || (tagOP is Gen2.Denatran.IAV.OBUAuthID)
                        || (tagOP is Gen2.Denatran.IAV.OBUReadFromMemMap)
                        || (tagOP is Gen2.Denatran.IAV.OBUWriteToMemMap))
                    {
                        return tagOpResponse;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {
                    tempReaderexception = rx;
                    rx = null;
                    throw tempReaderexception;
                }
            }
            finally
            {
                tempReaderexception = null;
            }
        }