public void ReceiveNewTag(string tagInfo) { TagInfo ti = TagInfo.Parse(tagInfo); if (null == ti) { return; } this.AddNewTag2Table(ti); }
public void ReceiveNewTag() { string temp1 = this.stringBuilder.ToString(); int start = temp1.IndexOf("Disc:"); int end = temp1.IndexOf("\r\n"); if (start >= 0 && end > 110 && start < end) { string temp = this.stringBuilder.ToString(start, end + 2); this.stringBuilder.Remove(0, end + 2); for (int i = 0; i < temp.Length; i++) { string tagInfo = string.Empty; int startIndex = temp.IndexOf("Disc", i); if (startIndex == -1) { return; } if (temp.Length - startIndex > 110) { tagInfo = temp.Substring(startIndex, 110); } else { return; } TagInfo ti = TagInfo.Parse(tagInfo); if (null == ti) { return; } this.AddNewTag2Table(ti); i = startIndex + 110; } } }
//接收串口或者其它方式接收到的标签信息, public void ParseDataToTag(string data) { this.tagDeleted(); //this.bBusy = true; if (data == null || data.Length <= 0) { return; } this.stringBuilder.Append(data); int tagLength = 110;//每条数据的标准长度为110 string temp1 = this.stringBuilder.ToString(); //Debug.WriteLine(temp1); int start = temp1.IndexOf("Disc:"); if (start < 0) { return; } int tempStart = start; int lastDiscIndex = start; while (true)//找到最后一个Disc,并且其后有满格式的数据,即长度为110 { int DiscIndex = temp1.IndexOf("Disc:", lastDiscIndex + 1); if (DiscIndex == -1) { break; } else { if (temp1.Length < DiscIndex + tagLength) { break; } } lastDiscIndex = DiscIndex; } //int tail = lastDiscIndex + 110; int tail = lastDiscIndex - 1; string temp = this.stringBuilder.ToString(start, tail - start + 1); //string temp = this.stringBuilder.ToString(start, tail + 2 - start + 1); this.stringBuilder.Remove(0, tail + 1);//正确数据之前的数据已经没用了 for (int i = 0; i < temp.Length; i++) { string tagInfo = string.Empty; int startIndex = temp.IndexOf("Disc", i); string restStr = "no rest"; if (startIndex >= 0) { restStr = temp.Substring(startIndex); } //Debug.WriteLine( // string.Format("TDJ_RFIDHelper.ParseDataToTag -> startIndex = {0} lastDiscIndex = {1} rest temp = {2}" // , startIndex, lastDiscIndex, restStr)); if (startIndex == -1) { return; } if (temp.Length - startIndex >= tagLength) { tagInfo = temp.Substring(startIndex, tagLength); } else { return; } TagInfo ti = TagInfo.Parse(tagInfo); if (null != ti) { this.AddNewTag2Table(ti); } i = startIndex + tagLength; } }