/// <summary> /// 獲得標簽的實體信息 /// </summary> /// <param name="tabString">標簽字符串</param> /// <returns></returns> private TagInformationInfo GetTagInformation(string tabString) { TagInformationInfo info = new TagInformationInfo(); info.TabNum = tabString; return(info); }
/// <summary> /// 獲得標簽的實體信息 /// </summary> /// <param name="tabString">標簽字符串</param> /// <returns></returns> private TagInformationInfo GetTagInformation(string tabString) { TagInformationInfo info = new TagInformationInfo(); tabString = tabString.Trim().Substring(0, 24); info.BegFlg = tabString.Substring(0, 2); info.Address = tabString.Substring(2, 2); info.States = tabString.Substring(4, 2); info.DataLength = tabString.Substring(6, 2); info.Keyboard = tabString.Substring(8, 2); info.Power = tabString.Substring(10, 2); info.IDNum = tabString.Substring(12, 6); // 按键,电量和ID号组成与A型一致的标签序列串。 //info.TagID = info.Keyboard + info.Power + info.IDNum; info.CRC = tabString.Substring(18, 4); info.EndFlg = tabString.Substring(22, 2); if (info.BegFlg == "C2" && info.EndFlg == "C3") { info.IsActiveTab = true; info.TabNum = tabString; } else { info.IsActiveTab = false; } ///選項按鈕 switch (int.Parse(info.Keyboard)) { case 8: info.OptionalValue = "A"; break; case 4: info.OptionalValue = "B"; break; case 2: info.OptionalValue = "C"; break; case 1: info.OptionalValue = "D"; break; case 9: info.OptionalValue = "A,D"; break; default: info.OptionalValue = ""; break; } info.ReadTimes = 1; return(info); }
/// <summary> /// 实体转换,将TabFormat类型实体数组转换成TagInformationInfo实体数组(弃用) /// </summary> /// <param name="listTabFormat"></param> /// <returns></returns> private List <TagInformationInfo> DataHandling_TagDataListExChange(List <TagFormat> listTagFormat) { List <TagInformationInfo> listTagInfo = new List <TagInformationInfo>(); if (listTagFormat != null) { for (int i = 0; i < listTagFormat.Count; i++) { TagInformationInfo tagInfo = new TagInformationInfo(); int iMacID = Convert.ToInt32(listTagFormat[i].StrMacID, 16); tagInfo.MachineID = iMacID.ToString(); tagInfo.IDNum = listTagFormat[i].StrID; tagInfo.ReaderKey = iMacID.ToString(); tagInfo.TagExistFirstDatetime = DateTime.Parse(listTagFormat[i].StrFirstReadTime); tagInfo.ReadDatetime = DateTime.Parse(listTagFormat[i].StrLastReadTime); tagInfo.TabNum = listTagFormat[i].StrRecordIndex; tagInfo.ReadTimes = int.Parse(listTagFormat[i].StrReadTimes); tagInfo.CRC = listTagFormat[i].StrCRC; tagInfo.Keyboard = listTagFormat[i].StrTagKey.Substring(0, 2); tagInfo.Power = listTagFormat[i].StrTagKey.Substring(2, 2); #region 电量值处理 if (listTagFormat[i].StrPowerValue == "00") { tagInfo.IsPowerLow = false; } else { tagInfo.IsPowerLow = true; } #endregion tagInfo.TagID = listTagFormat[i].StrTagID; tagInfo.Antenna = 1; listTagInfo.Add(tagInfo); } return(listTagInfo); } return(null); }
/// <summary> /// Tab 格式的處理 /// </summary> /// <param name="tabNum"></param> private void HandleTab(string tabNum) { string _tabNum; _tabNum = tabNum.Trim(); //if (_tabNum.Length >= 24) //{ // _tabNum = _tabNum.Substring(0, 24); //} //else //{ // return; //} TagInformationInfo info = GetTagInformation(_tabNum); TagInfoResultEventArgs infoEventArgs = new TagInfoResultEventArgs(); infoEventArgs.TagInformation = info; base.OnTagResult(infoEventArgs); }
private void DataReceive() { this._IsReceiving = true; try { if (!this._isReading) { this._IsReceiving = false; return; } ReaderGeneral.ConsoleWrite("开始接收数据:" + DateTime.Now.ToString()); byte[] arrBuff = new byte[10240]; int iRecLen = this._SendClient.Receive(arrBuff); ReaderGeneral.ConsoleWrite("接收到数据长度为:" + iRecLen); List <byte> listBuff = arrBuff.ToList(); listBuff.RemoveRange(iRecLen, listBuff.Count - iRecLen); ReaderGeneral.ConsoleWrite("数据池数据填充完毕:" + DateTime.Now.ToString()); //转换正常格式数据列 //string strChange = ReaderGeneral.ChangeHexArrayToString(arrBuff); List <string> listSource = ReaderGeneral.HandleSourceDataToList(listBuff.ToArray()); ReaderGeneral.ConsoleWrite("接收数据量:" + listSource.Count + "条。 " + DateTime.Now.ToString()); //符合正常监控数据的长度。 List <string> listRecord = listSource.Where(x => x.Length == 62).ToList(); if (listRecord != null && listRecord.Count > 0) { ReaderGeneral.ConsoleWrite("正常数据数量:" + listRecord.Count); } //符合确认返回数据的长度。 List <string> listConfirm = listSource.Where(x => x.Length == 14).ToList(); if (listConfirm != null && listConfirm.Count > 0) { ReaderGeneral.ConsoleWrite("确认数据:" + listConfirm.Count); } //符合时间数据的长度。 List <string> listTime = listSource.Where(x => x.Length == 28).ToList(); if (listTime != null && listTime.Count > 0) { ReaderGeneral.ConsoleWrite("时间值数据:" + listTime.Count); } if (this._currentDataType == EnumRecDataMode.CollectRecordMode) { #region 处理正常监控数据 Dictionary <string, TagInfoResultEventArgs> dicReceive = new Dictionary <string, TagInfoResultEventArgs>(); foreach (string strTag in listRecord) { TagInformationInfo tagInfo = new TagInformationInfo(); try { tagInfo = tagInfo.GetTagInformationInfoIns(strTag); } catch (Exception ex) { ReaderGeneral.ConsoleWrite(ex.Message); if (!string.IsNullOrEmpty(ex.Message)) { string[] arrString = ex.Message.Split('-'); if (arrString.Length > 1) { TagInfoResultEventArgs args = new TagInfoResultEventArgs(); args.TagInformationList = new List <TagInformationInfo>(); TagInformationInfo tagThrow = new TagInformationInfo(); tagThrow.MachineID = arrString[1]; args.TagInformationList.Add(tagThrow); OnTagResult(args); } } tagInfo = null; } if (tagInfo != null) { if (dicReceive.Keys.Contains(tagInfo.MachineID)) { if (dicReceive[tagInfo.MachineID] == null) { dicReceive[tagInfo.MachineID] = new TagInfoResultEventArgs(); dicReceive[tagInfo.MachineID].TagInformationList = new List <TagInformationInfo>(); } dicReceive[tagInfo.MachineID].TagInformationList.Add(tagInfo); } else { TagInfoResultEventArgs args = new TagInfoResultEventArgs(); args.TagInformationList = new List <TagInformationInfo>(); args.TagInformationList.Add(tagInfo); dicReceive.Add(tagInfo.MachineID, args); } if (tagInfo.States == "01") { dicReceive[tagInfo.MachineID].ExamineNum = tagInfo.RecordIndex; } } } if (dicReceive != null && dicReceive.Count > 0) { foreach (KeyValuePair <string, TagInfoResultEventArgs> kvPair in dicReceive) { ReaderGeneral.ConsoleWrite("抛出数据量:" + kvPair.Value.TagInformationList.Count); OnTagResult(kvPair.Value); } } #endregion #region 处理确认数据 foreach (string confirmItem in listConfirm) { try { int iMacID = Convert.ToInt32(confirmItem.Substring(2, 2), 16); string strFinish = GetFinishedCollectionInstruction(iMacID); string strUpload = GetUploadedCollectionInstruction(iMacID); if (confirmItem == strFinish || confirmItem == strUpload) { TagInfoResultEventArgs arg = new TagInfoResultEventArgs(); arg.TagInformationList = new List <TagInformationInfo>(); TagInformationInfo tagInfo = new TagInformationInfo(); tagInfo.MachineID = iMacID.ToString(); arg.TagInformationList.Add(tagInfo); ReaderGeneral.ConsoleWrite("no more data .................................................." + iMacID.ToString()); this.OnTagResult(arg); } } catch (Exception ex) { ReaderGeneral.ConsoleWrite("Error: " + ex.Message); } } #endregion } else if (this._currentDataType == EnumRecDataMode.AdjustTimeMode) { #region 处理时间检查 if (listTime != null && listTime.Count > 0) { foreach (string timeItem in listTime) { int iMacIDChkTime = 0; DateTime?dtGet = DataHandling_FormatMacTimeVal(timeItem, ref iMacIDChkTime); if (iMacIDChkTime != 0) { if (!this.DicReaderDetails.Keys.Contains(iMacIDChkTime)) { return; } ReaderExDetailInfo readerChk = this.DicReaderDetails[iMacIDChkTime]; if (dtGet != null) { // 获取到有效的机器时间后,将此时间值赋予获取成功标识。 readerChk.Ex_dtLastTimeChk = dtGet.Value; readerChk.Ex_iCounterTimeChk = 0; readerChk.Ex_lIsSendTimeChkWarning = false; } else { readerChk.Ex_iCounterTimeChk++; } readerChk.Ex_dtLastRunTime = DateTime.Now; } } } #endregion } ReaderGeneral.ConsoleWrite("数据接收完毕。" + DateTime.Now.ToString()); } catch (Exception ex) { ReaderGeneral.ConsoleWrite(ex.Message); } this._IsReceiving = false; }
/// <summary> /// 格式化处理批量数据 /// </summary> /// <param name="strSourceData">需要处理的返回指令数据</param> /// <param name="strRecordIndex">返回需要被确认的流水号</param> /// <returns></returns> private List <TagInformationInfo> DataHandling_FormatBatchTagData(string strSourceData, out string strRecordIndex) { try { List <TagInformationInfo> listTagInfos = new List <TagInformationInfo>(); strSourceData = strSourceData.Trim(); string[] arrStrData = new string[this._iRecordListMaxLen]; strRecordIndex = string.Empty; if (strSourceData.Length >= 14) { //处理正常数据 List <string> listSourceData = ReaderGeneral.HandleSourceDataToList(strSourceData, this._iRecordMaxLen); List <ReaderExceptionEventArgs> listExArgs = new List <ReaderExceptionEventArgs>(); if (listSourceData != null && listSourceData.Count > 0) { #region 处理正常数据返回 for (int i = 0; i < listSourceData.Count; i++) { try { TagInformationInfo tagFormat = new TagInformationInfo(); tagFormat = tagFormat.GetTagInformationInfoIns(listSourceData[i]); if (tagFormat != null) { listTagInfos.Add(tagFormat); } //转换 if (i == listSourceData.Count - 1) { strRecordIndex = tagFormat.MachineID + "-" + tagFormat.IDNum + "-" + tagFormat.RecordIndex + "-" + tagFormat.States; } } catch (Exception exFormat) { #region 异常处理 ReaderExceptionEventArgs readerEX = new ReaderExceptionEventArgs(); readerEX.EquipmentStatus = EnumEquipmentStatus.SigleRecordException; exFormat.Source = " COM:" + base.CommPort.ToString() + " " + listSourceData[i]; readerEX.ExceptionObject = exFormat; readerEX.RecordTime = DateTime.Now; listExArgs.Add(readerEX); //OnReaderException(readerEX); if (i == listSourceData.Count - 1) { strRecordIndex = Convert.ToInt32(listSourceData[i].Substring(0, 2), 16).ToString() + "-" + listSourceData[i].Substring(4, 8) + "-" + listSourceData[i].Substring(12, 4) + "-" + listSourceData[i].Substring(2, 2); } #endregion } } this._listTagInfos = listTagInfos; #endregion List <string> listLog = new List <string>(); if (listTagInfos.Count == 0) { ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.EquipmentStatus = EnumEquipmentStatus.BatchRecordException; args.ExceptionObject = new Exception("COM:" + base.CommPort.ToString() + ",批量数据异常,请注意最近无数据返回的读写器。"); args.RecordTime = DateTime.Now; OnReaderException(args); } else if (listTagInfos.Count > 0) { if (listExArgs.Count > 0 && listExArgs.Count <= listTagInfos.Count) { foreach (ReaderExceptionEventArgs args in listExArgs) { if (args == null) { continue; } if (!listLog.Contains(args.ExceptionObject.Message)) { args.MachineID = int.Parse(listTagInfos[0].MachineID); OnReaderException(args); } } } } return(listTagInfos); } //处理确认信息数据数据 List <string> listEmptyData = ReaderGeneral.HandleSourceDataToList(strSourceData); if (listEmptyData != null && listEmptyData.Count > 0) { #region 处理确认信息数据数据返回 int iMacIDFinish = Convert.ToInt32(strSourceData.Substring(2, 2), 16); //当读写器无未确认数据或未采集到数据时,会返回一条为7字节的数据。 string strFinished = GetFinishedCollectionInstruction(iMacIDFinish); string strUploaded = GetUploadedCollectionInstruction(iMacIDFinish); if (listEmptyData.Contains(strFinished) || listEmptyData.Contains(strUploaded)) { TagInfoResultEventArgs arg = new TagInfoResultEventArgs(); arg.TagInformationList = new List <TagInformationInfo>(); TagInformationInfo tagInfo = new TagInformationInfo(); tagInfo.MachineID = iMacIDFinish.ToString(); arg.TagInformationList.Add(tagInfo); this.OnTagResult(arg); } #endregion } } return(listTagInfos); } catch (Exception Ex) { throw Ex; } }