Ejemplo n.º 1
0
        /// <summary>
        /// 将新解析完的标签尝试添加到列表中
        /// 首先要检查列表中是否已经有新标签的epc,如果已经有标签epc,查看天线编号是否一致,如果天线编号一致,则替换原有的
        /// 标签信息,如果天线编号不一致,则查看是否在缓冲时间段内,如果是则表明这可能是误读,要用读取次数多的标签信息代替
        /// 读取次数少的标签信息;如果不在缓冲时间段内,则认为标签已经改变了位置
        /// 因此,导致表内信息改变的情况有以下几种:
        /// 1 epc不存在,加到表中
        /// 2 epc存在,且天线编号一致,新的代替旧的
        /// 3 epc存在,缓冲时间段内,天线编号不一致,用读取次数多的代替少的
        /// 4 epc存在,非缓冲时间段内,天线编号不一致,新的代替旧的
        /// </summary>
        /// <param name="ti"></param>
        public void AddNewTag2Table(TagInfo ti)
        {
#if TRACE
            Debug.WriteLine("AddNewTag2Table  -> ");
            Debug.WriteLine("AddNewTag2Table  -> ti = " + ti.toString());
#endif


            //
            DataRow[] rows = null;

            /*
             * TimeSpan ts = DateTime.Now - Program.timeBase;
             * long span = (long)(ts.TotalMilliseconds - this.lostDelay);
             * if (span > 0)
             * {
             *  //rows = tagsInfo.Select("milliSecond < '" + span.ToString() + "'");
             *  //rows = tagsInfo.Select("milliSecond < " + span.ToString() + "");
             *
             * }
             *
             * rows = tagsInfo.Select("state = 'deleted'");
             * if (rows.Length > 0)
             * {
             *  for (int i = 0; i < rows.Length; i++)
             *  {
             *      Debug.WriteLine(string.Format("span -> {0}   millis -> {1} epc -> {2}", span.ToString(), rows[i]["milliSecond"], rows[i]["epc"]));
             *
             *      this.tagsInfo.Rows.Remove(rows[i]);
             *  }
             * }
             */

            if (ti.readCount < this.minReadCount)
            {
                return;
            }
            this.resetState.WaitOne();
            this.resetState.Reset();
            rows = tagsInfo.Select("epc = '" + ti.epc + "'");
            if (rows.Length <= 0)//epc不存在,加到表中
            {
                this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
            }
            else
            {
                if (ti.antennaID == rows[0]["antennaID"].ToString())//天线编号一致
                {
                    this.tagsInfo.Rows.Remove(rows[0]);
                    this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                }
                else//天线编号不一致
                {
                    /*
                     * if (ti.getTime != rows[0]["getTime"].ToString())//超出一秒,设定为超出缓冲时间
                     * {
                     *  this.tagsInfo.Rows.Remove(rows[0]);
                     *  this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime });
                     * }
                     * else
                     * */
                    {
                        //没超出一秒,有可能超出缓冲时间,需要比较毫秒
                        long oldM = 0;
                        try
                        {
                            oldM = long.Parse(rows[0]["milliSecond"].ToString());
                        }
                        catch (System.Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        if ((ti.milliSecond - oldM) > this.milliSecondDelay)//超出缓冲时间
                        {
                            this.tagsInfo.Rows.Remove(rows[0]);
                            this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                        }
                        else
                        {
                            //读取次数多的代替少的
                            int oldC = 0;
                            try
                            {
                                oldC = int.Parse(rows[0]["readCount"].ToString());
                            }
                            catch (System.Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (ti.readCount > oldC)
                            {
                                this.tagsInfo.Rows.Remove(rows[0]);
                                this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                            }
                        }
                    }
                }
            }
            this.resetState.Set();
#if TRACE
            Debug.WriteLine("AddNewTag2Table  <- ");
#endif

            this.outputTagTable();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将新解析完的标签尝试添加到列表中
        /// 首先要检查列表中是否已经有新标签的epc,如果已经有标签epc,查看天线编号是否一致,如果天线编号一致,则替换原有的
        /// 标签信息,如果天线编号不一致,则查看是否在缓冲时间段内,如果是则表明这可能是误读,要用读取次数多的标签信息代替
        /// 读取次数少的标签信息;如果不在缓冲时间段内,则认为标签已经改变了位置
        /// 因此,导致表内信息改变的情况有以下几种:
        /// 1 epc不存在,加到表中
        /// 2 epc存在,且天线编号一致,新的代替旧的
        /// 3 epc存在,缓冲时间段内,天线编号不一致,用读取次数多的代替少的
        /// 4 epc存在,非缓冲时间段内,天线编号不一致,新的代替旧的
        /// </summary>
        /// <param name="ti"></param>
        public void AddNewTag2Table(TagInfo ti)
        {
#if TRACE
            Debug.WriteLine("AddNewTag2Table  -> ");
            Debug.WriteLine("AddNewTag2Table  -> ti = " + ti.toString());
#endif

            //
            DataRow[] rows = null;

            if (ti.readCount < this.minReadCount)
            {
                return;
            }
            this.resetState.WaitOne();
            this.resetState.Reset();
            rows = tagsInfo.Select("epc = '" + ti.epc + "'");
            if (rows.Length <= 0)//epc不存在,加到表中
            {
                this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
            }
            else
            {
                if (ti.antennaID == rows[0]["antennaID"].ToString())//天线编号一致
                {
                    this.tagsInfo.Rows.Remove(rows[0]);
                    this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                }
                else//天线编号不一致
                {
                    {
                        //没超出一秒,有可能超出缓冲时间,需要比较毫秒
                        long oldM = 0;
                        try
                        {
                            oldM = long.Parse(rows[0]["milliSecond"].ToString());
                        }
                        catch (System.Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        if ((ti.milliSecond - oldM) > this.milliSecondDelay)//超出缓冲时间
                        {
                            this.tagsInfo.Rows.Remove(rows[0]);
                            this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                        }
                        else
                        {
                            //读取次数多的代替少的
                            int oldC = 0;
                            try
                            {
                                oldC = int.Parse(rows[0]["readCount"].ToString());
                            }
                            catch (System.Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            if (ti.readCount > oldC)
                            {
                                this.tagsInfo.Rows.Remove(rows[0]);
                                this.tagsInfo.Rows.Add(new object[] { ti.epc, ti.antennaID, ti.tagType, ti.readCount, ti.milliSecond, ti.getTime, "new" });
                            }
                        }
                    }
                }
            }
            this.resetState.Set();
#if TRACE
            Debug.WriteLine("AddNewTag2Table  <- ");
#endif

            this.outputTagTable();
        }