public void PrefilterEventHandler(object o, UpdateEventArgs args) { if (args.NewEvents != null) { int lastContextID = -1; int newContextID; string strResult = ""; string sendMessage = ""; try { strResult += "-----------Tags are as follows:--------------\r\n"; foreach (EventBean eb in args.NewEvents) { newContextID = Int32.Parse(eb.Get("ID").ToString()); if (newContextID == lastContextID) { continue; } XtiveTag tag = (new XtiveTag.Builder()) .SetUid(eb.Get("UID").ToString()) .SetRssi(Int32.Parse(eb.Get("Rssi").ToString())) .SetBLowPower(Boolean.Parse(eb.Get("BLowPower").ToString())) .SetBExcite(Boolean.Parse(eb.Get("BExcite").ToString())) .SetReaderIP(eb.Get("ReaderIP").ToString()) .SetAn(eb.Get("An").ToString()) .SetDateTime(eb.Get("DateTime").ToString()).Build(); nosoursejmxbroker.addXtiveTag(tag); sendCount++; sendMessage = tag.Uid + "|" + tag.Rssi + "|" + tag.BLowPower + "|" + tag.BExcite + "|" + tag.ReaderIP + "|" + tag.An + "|" + tag.DateTime; log.Info(sendMessage); strResult = strResult + sendMessage + "\r\n"; lastContextID = newContextID; } strResult += "-----------Over!--------------------------\r\n"; form1.updateMsgBoxM(strResult, sendCount.ToString()); //更新UI } catch (Exception e) { log.Error(e.Message); } } }
public bool LoadTagData(ref XtiveTag[] tagData, ref int RecordCount) { if (m_handle == IntPtr.Zero) { return(false); } RecordCount = 0; try { while (RecordCount < 100) { if (!ReaderTag(m_handle, ref btTagType, ref TagID, ref bExcite, ref bLowPower, ref ExciteID, ref RID, ref fRSSI)) // get one tag once, FIFO { // Debug.WriteLine("failed to ReaderTag"); break; } else { // Debug.WriteLine(TagID.ToString()); /*tagData[RecordCount].RSSI = Convert.ToInt32(fRSSI); * tagData[RecordCount].UID = TagID.ToString(); * // tagData[RecordCount].RID = RID; * tagData[RecordCount].bLowPower = bLowPower; * tagData[RecordCount].bExcite = bExcite; * tagData[RecordCount].An = "0"; * tagData[RecordCount].ReaderIP = ip; * tagData[RecordCount].datetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");*/ XtiveTag tag = (new XtiveTag.Builder()) .SetUid(TagID.ToString()) .SetRssi(Convert.ToInt32(fRSSI)) .SetBLowPower(bLowPower) .SetBExcite(bExcite) .SetReaderIP(ip) .SetAn("0") .SetDateTime(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Build(); tagData[RecordCount] = tag; RecordCount++; } } _ReaderErrorCode = 0; _ReaderErrorSpecified = ""; } catch (Exception e) { _ReaderErrorCode = 42; _ReaderErrorSpecified = "读写器LoadTagData函数故障:" + m_handle.ToString() + " " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); return(false); } finally { } if (RecordCount == 0) { return(false); } else { return(true); } }
/** * */ public bool LoadTagData(ref XtiveTag[] tagData, ref int RecordCount) { bool bResult = true; try { if (bResult != false) { bResult = Stop_RoSpec(); } if (bResult != false) { bResult = Delete_RoSpec(); } if (bResult != false) { bResult = DELETE_ACCESSSPEC(); } if (bResult != false) { bResult = Add_RoSpec(); } ; if (bResult != false) { bResult = Enable_RoSpec(); } if (bResult != false) { bResult = Start_RoSpec(); } } catch (Exception ex) { log.Error(ex.Message); return(false); } System.Threading.Thread.Sleep(100); try { // 读取标签 int i = 0; RecordCount = RecordTag.Count; for (i = 0; i < RecordCount; i++) { /*tagData[i].UID = RecordTag[i]; * tagData[i].RSSI = RecordRssi[i]; * tagData[i].An = AntennaID[i]; * tagData[i].bLowPower = true; * tagData[i].bExcite = true; * tagData[i].ReaderIP = ip; * tagData[i].datetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");*/ XtiveTag tag = (new XtiveTag.Builder()) .SetUid(RecordTag[i]) .SetRssi(RecordRssi[i]) .SetBLowPower(true) .SetBExcite(true) .SetReaderIP(ip) .SetAn(AntennaID[i]) .SetDateTime(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Build(); tagData[i] = tag; } RecordTag.Clear(); } catch (Exception ex) { log.Error(ex.Message); return(false); } return(true); }
public bool LoadTagData(ref XtiveTag[] tagData, ref int RecordCount) { //int cnt = 0; string strResult = null; //string strTagIDWithoutBlanks = null; RecordCount = 0; //string strReceive = null; try { strResult = mReader.TagList; Console.WriteLine("rfid string:" + strResult); if ((strResult == null || strResult.Equals("") || strResult.Equals("(No Tags)")) == false) { char split = '\n'; string a = strResult.Replace("\r", ""); string[] ListResult = a.Split(split); if (ListResult.Length > 0) { RecordCount = ListResult.Length; if (ListResult[0][0] == 'I') { for (int i = 0; i < ListResult.Length; i++) { char splitchar = ';'; string[] taglist = ListResult[i].Split(splitchar); char splitchartemp = ':'; string[] readerip = taglist[0].Split(splitchartemp); //tagData[i].ReaderIP = readerip[1]; string[] tagID = taglist[1].Split(splitchartemp); //tagData[i].UID = tagID[1]; string[] RSSI = taglist[2].Split(splitchartemp); //tagData[i].RSSI = Convert.ToInt32(Convert.ToDouble(RSSI[1].ToString())); //tagData[i].bExcite = true; //tagData[i].bLowPower = false; string[] an = taglist[3].Split(splitchartemp); //tagData[i].An = an[1]; //后面加入代码,用于测试,2013-3-28 16:14 罗元剑 //tagData[i].datetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // Random random = new Random(); ///// tagData[i].port = random.Next(100); // tagData[i].x_position = random.Next(10)+12936200; // tagData[i].y_position = random.Next(10)+4861943; XtiveTag tag = (new XtiveTag.Builder()) .SetUid(tagID[1]) .SetRssi(Convert.ToInt32(Convert.ToDouble(RSSI[1].ToString()))) .SetBLowPower(false) .SetBExcite(true) .SetReaderIP(readerip[1]) .SetAn(an[1]) .SetDateTime(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Build(); tagData[i] = tag; } } else { for (int i = 0; i < ListResult.Length; i++) { char splitchar = ','; string[] taglist = ListResult[i].Split(splitchar); char splitchartemp = ':'; string[] tagID = taglist[0].Split(splitchartemp); //tagData[i].UID = tagID[1].Replace(" ",""); //tagData[i].An = taglist[4].Split(splitchartemp)[1]; XtiveTag tag = (new rfiddata.XtiveTag.Builder()) .SetUid(tagID[1].Replace(" ", "")) .SetAn(taglist[4].Split(splitchartemp)[1]).Build(); tagData[i] = tag; } } } mReader.ClearTagList(); //Thread.Sleep(100); //strReceive= mReader.SendReceive("set TagListCustomFormat = IP:${IP};Tag:${TAGID};RSSI:${RSSI};Antenna:${Antenna}",true); _ReaderErrorCode = 0; _ReaderErrorSpecified = ""; } } catch (Exception e) { _ReaderErrorCode = 41; if (ip != null) { _ReaderErrorSpecified = "读写器LoadTagData函数故障:" + ip.ToString() + " " + e.Source.ToString() + "\r\n " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); } else { _ReaderErrorSpecified = "读写器LoadTagData函数故障:实例已丢失" + " " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); } return false; } /* if (strResult == null || (!strResult.Contains("TagID"))) { return false; } TagInfo[] aTags = null; // if no header we'll get tag list only try { TagInfo[] bTags = null; cnt = AlienUtils.ParseTagList(strResult, out bTags); if (cnt > 0) { aTags = bTags.Distinct().ToArray(); RecordCount = aTags.Count(); } else { RecordCount = cnt; } } catch (Exception ex) { // MessageBox.Show("该消息不符合规格:" + strData + "\n" + ex.Message); } #region "Show tags found"... //if (cnt > 0 && cnt < 100) //{ // for (int i = 0; i < cnt; i++) // { // tagData[i].UID = aTags[i].TagID; //aTags[i].Antenna // tagData[i].RSSI = -60; // tagData[i].bExcite = true; // tagData[i].bLowPower = false; // } //} if (cnt > 0) { int i = 0; strTagIDWithoutBlanks = aTags[0].TagID.Replace(" ", ""); tagData[0].UID = strTagIDWithoutBlanks; tagData[0].RSSI = "-60"; tagData[0].bExcite = true; tagData[0].bLowPower = false; if (cnt > 1) { for (i = 1; i < cnt; i++) { if (aTags[i - 1].TagID != aTags[i].TagID) { strTagIDWithoutBlanks = aTags[i].TagID.Replace(" ", ""); tagData[i].UID = strTagIDWithoutBlanks; tagData[i].RSSI = "-60"; tagData[i].bExcite = true; tagData[i].bLowPower = false; } if (i >= 99 ) break; } } } else { return false; } #endregion */ return true; }
public bool LoadTagData(ref XtiveTag[] tagData, ref int RecordCount) { if (m_handle == IntPtr.Zero) return false; RecordCount = 0; try { while (RecordCount < 100) { if (!ReaderTag(m_handle, ref btTagType, ref TagID, ref bExcite, ref bLowPower, ref ExciteID, ref RID, ref fRSSI)) // get one tag once, FIFO { // Debug.WriteLine("failed to ReaderTag"); break; } else { // Debug.WriteLine(TagID.ToString()); /*tagData[RecordCount].RSSI = Convert.ToInt32(fRSSI); tagData[RecordCount].UID = TagID.ToString(); // tagData[RecordCount].RID = RID; tagData[RecordCount].bLowPower = bLowPower; tagData[RecordCount].bExcite = bExcite; tagData[RecordCount].An = "0"; tagData[RecordCount].ReaderIP = ip; tagData[RecordCount].datetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");*/ XtiveTag tag = (new XtiveTag.Builder()) .SetUid(TagID.ToString()) .SetRssi(Convert.ToInt32(fRSSI)) .SetBLowPower(bLowPower) .SetBExcite(bExcite) .SetReaderIP(ip) .SetAn("0") .SetDateTime(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Build(); tagData[RecordCount] = tag; RecordCount++; } } _ReaderErrorCode = 0; _ReaderErrorSpecified = ""; } catch (Exception e) { _ReaderErrorCode = 42; _ReaderErrorSpecified = "读写器LoadTagData函数故障:" + m_handle.ToString() + " " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); return false; } finally { } if (RecordCount == 0) return false; else return true; }
public bool LoadTagData(ref XtiveTag[] tagData, ref int RecordCount) { //int cnt = 0; string strResult = null; //string strTagIDWithoutBlanks = null; RecordCount = 0; //string strReceive = null; try { strResult = mReader.TagList; Console.WriteLine("rfid string:" + strResult); if ((strResult == null || strResult.Equals("") || strResult.Equals("(No Tags)")) == false) { char split = '\n'; string a = strResult.Replace("\r", ""); string[] ListResult = a.Split(split); if (ListResult.Length > 0) { RecordCount = ListResult.Length; if (ListResult[0][0] == 'I') { for (int i = 0; i < ListResult.Length; i++) { char splitchar = ';'; string[] taglist = ListResult[i].Split(splitchar); char splitchartemp = ':'; string[] readerip = taglist[0].Split(splitchartemp); //tagData[i].ReaderIP = readerip[1]; string[] tagID = taglist[1].Split(splitchartemp); //tagData[i].UID = tagID[1]; string[] RSSI = taglist[2].Split(splitchartemp); //tagData[i].RSSI = Convert.ToInt32(Convert.ToDouble(RSSI[1].ToString())); //tagData[i].bExcite = true; //tagData[i].bLowPower = false; string[] an = taglist[3].Split(splitchartemp); //tagData[i].An = an[1]; //后面加入代码,用于测试,2013-3-28 16:14 罗元剑 //tagData[i].datetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // Random random = new Random(); ///// tagData[i].port = random.Next(100); // tagData[i].x_position = random.Next(10)+12936200; // tagData[i].y_position = random.Next(10)+4861943; XtiveTag tag = (new XtiveTag.Builder()) .SetUid(tagID[1]) .SetRssi(Convert.ToInt32(Convert.ToDouble(RSSI[1].ToString()))) .SetBLowPower(false) .SetBExcite(true) .SetReaderIP(readerip[1]) .SetAn(an[1]) .SetDateTime(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Build(); tagData[i] = tag; } } else { for (int i = 0; i < ListResult.Length; i++) { char splitchar = ','; string[] taglist = ListResult[i].Split(splitchar); char splitchartemp = ':'; string[] tagID = taglist[0].Split(splitchartemp); //tagData[i].UID = tagID[1].Replace(" ",""); //tagData[i].An = taglist[4].Split(splitchartemp)[1]; XtiveTag tag = (new rfiddata.XtiveTag.Builder()) .SetUid(tagID[1].Replace(" ", "")) .SetAn(taglist[4].Split(splitchartemp)[1]).Build(); tagData[i] = tag; } } } mReader.ClearTagList(); //Thread.Sleep(100); //strReceive= mReader.SendReceive("set TagListCustomFormat = IP:${IP};Tag:${TAGID};RSSI:${RSSI};Antenna:${Antenna}",true); _ReaderErrorCode = 0; _ReaderErrorSpecified = ""; } } catch (Exception e) { _ReaderErrorCode = 41; if (ip != null) { _ReaderErrorSpecified = "读写器LoadTagData函数故障:" + ip.ToString() + " " + e.Source.ToString() + "\r\n " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); } else { _ReaderErrorSpecified = "读写器LoadTagData函数故障:实例已丢失" + " " + e.Message.ToString(); log.Error(_ReaderErrorSpecified); } return(false); } /* * if (strResult == null || (!strResult.Contains("TagID"))) * { * return false; * } * * TagInfo[] aTags = null; // if no header we'll get tag list only * try * { * TagInfo[] bTags = null; * cnt = AlienUtils.ParseTagList(strResult, out bTags); * if (cnt > 0) * { * aTags = bTags.Distinct().ToArray(); * * RecordCount = aTags.Count(); * } * else * { * RecordCount = cnt; * } * * } * catch (Exception ex) * { * // MessageBox.Show("该消息不符合规格:" + strData + "\n" + ex.Message); * } #region "Show tags found"... * //if (cnt > 0 && cnt < 100) * //{ * // for (int i = 0; i < cnt; i++) * // { * // tagData[i].UID = aTags[i].TagID; * //aTags[i].Antenna * // tagData[i].RSSI = -60; * // tagData[i].bExcite = true; * // tagData[i].bLowPower = false; * * // } * * //} * if (cnt > 0) * { * int i = 0; * strTagIDWithoutBlanks = aTags[0].TagID.Replace(" ", ""); * tagData[0].UID = strTagIDWithoutBlanks; * tagData[0].RSSI = "-60"; * tagData[0].bExcite = true; * tagData[0].bLowPower = false; * * if (cnt > 1) * { * for (i = 1; i < cnt; i++) * { * if (aTags[i - 1].TagID != aTags[i].TagID) * { * strTagIDWithoutBlanks = aTags[i].TagID.Replace(" ", ""); * tagData[i].UID = strTagIDWithoutBlanks; * tagData[i].RSSI = "-60"; * tagData[i].bExcite = true; * tagData[i].bLowPower = false; * } * if (i >= 99 ) break; * } * } * } * else * { * return false; * } #endregion */ return(true); }