/// <summary> /// 发布读标签结果信息 /// </summary> /// <param name="eventArgs"></param> protected virtual void OnTagResult(TagInfoResultEventArgs tagArgs) { if (this.TagInformationResult != null) { this.TagInformationResult(this, tagArgs); } }
protected override void OnTagResult(TagInfoResultEventArgs tagArgs) { #region 数据返回,设置读写器状态为连通中 if (tagArgs != null && tagArgs.TagInformationList != null && tagArgs.TagInformationList.Count > 0) { int iMacIDRv = Convert.ToInt32(tagArgs.TagInformationList[0].MachineID); if (this.DicReaderExDetails.Keys.Contains(iMacIDRv)) { ReaderExDetailInfo readerChk = this.DicReaderExDetails[iMacIDRv]; readerChk.Ex_dtRvDataFormatChk = DateTime.Now; readerChk.Ex_dtRvData = DateTime.Now; readerChk.Ex_iCounterRvData = 0; if (readerChk.CurrentStatus != EnumEquipmentStatus.Conneted) { EquipmentStatusEventArgs statusArgs = new EquipmentStatusEventArgs(); statusArgs.MachineID = iMacIDRv; statusArgs.EquipmentStatus = EnumEquipmentStatus.Conneted; statusArgs.RecordTime = DateTime.Now; readerChk.CurrentStatus = EnumEquipmentStatus.Conneted; readerChk.Ex_lIsSendInvalidDataWarning = false; OnStatusChange(statusArgs); } } } #endregion base.OnTagResult(tagArgs); }
void _processTag_EventTagHandler(TagEntity tag) { TagInfoResultEventArgs args = new TagInfoResultEventArgs(); args.TagInformation = new TagInformationInfo(); args.TagInformation.TagID = tag.TagId; OnTagResult(args); }
protected override void OnTagResult(TagInfoResultEventArgs tagArgs) { #region 数据返回,设置读写器状态为连通中 if (this._isReading) { if (tagArgs != null && tagArgs.TagInformationList != null && tagArgs.TagInformationList.Count > 0) { int iMacIDRv = Convert.ToInt32(tagArgs.TagInformationList[0].MachineID); if (this.DicReaderDetails.Keys.Contains(iMacIDRv)) { ReaderExDetailInfo readerChk = this.DicReaderDetails[iMacIDRv]; readerChk.Ex_dtRvDataFormatChk = DateTime.Now; readerChk.Ex_dtRvData = DateTime.Now; readerChk.Ex_iCounterRvData = 0; if (readerChk.CurrentStatus != EnumEquipmentStatus.Conneted) { EquipmentStatusEventArgs statusArgs = new EquipmentStatusEventArgs(); statusArgs.MachineID = iMacIDRv; statusArgs.EquipmentStatus = EnumEquipmentStatus.Conneted; statusArgs.RecordTime = DateTime.Now; readerChk.CurrentStatus = EnumEquipmentStatus.Conneted; readerChk.Ex_lIsSendInvalidDataWarning = false; OnStatusChange(statusArgs); } } } } #endregion try { if (tagArgs != null) { if (tagArgs.TagInformationList != null && tagArgs.TagInformationList.Count > 0 && !string.IsNullOrEmpty(tagArgs.ExamineNum)) { if (!this._listHistoryIndex.Contains(tagArgs.ExamineNum)) { this._listHistoryIndex.Add(tagArgs.ExamineNum); base.OnTagResult(tagArgs); } OrderSend_ConfirmBatchData(int.Parse(tagArgs.TagInformationList[0].MachineID), tagArgs.ExamineNum); ReaderGeneral.ConsoleWrite("数据确认流水号:【" + tagArgs.ExamineNum + "】,数据来源机:" + tagArgs.TagInformationList[0].MachineID); } } } catch (Exception ex) { Common.General.WriteLocalLogs(Common.General.GetCurrentFuncName(), "确认数据异常:" + ex.Message, string.Empty, SystemLog.SystemLog.LogType.Error, SystemLog.SystemLog.FileType.LogFile); } }
/// <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; } }
/// <summary> /// 从虚拟COM组件处接收返回的指令数据 /// </summary> private void ReadDataFromCOM(object sender, EventArgs e) { if (this._lockRead == null) { this._lockRead = new object(); } lock (this._lockRead) { try { if (this.axMSComm05.CommEvent == (short)(MSCommLib.OnCommConstants.comEvReceive)) //查询CommEvent属性 { object objInput = this._MSCOM.Input; byte[] arrInput = (byte[])objInput; if (arrInput.Length == 0) { return; } int iMacBaseID = base.MachineID; //将返回的字节数组转换成字符串处理 string strInput = string.Empty; for (int i = 0; i <= (arrInput.Length - 1); i++) { strInput = strInput + arrInput[i].ToString("X2"); } if (this._currentDataType == EnumRecDataMode.CollectRecordMode)//收数模式 { #region 收数处理 this._iRecordMaxLen = 62; string strRecordIndex; List <TagInformationInfo> listTagInfos = DataHandling_FormatBatchTagData(strInput, out strRecordIndex); if (listTagInfos == null) { return; } if (listTagInfos.Count < 1) { return; } iMacBaseID = Convert.ToInt32(listTagInfos[0].MachineID); TagInfoResultEventArgs tagInfo = new TagInfoResultEventArgs(); tagInfo.TagInformationList = listTagInfos; //记录来自设备的最原始卡记录字符串 tagInfo.TagSourceInformation = strInput; if (!string.IsNullOrEmpty(strRecordIndex)) { string[] arrIndex = strRecordIndex.Split('-'); if (arrIndex != null && arrIndex.Length > 2) { tagInfo.ExamineNum = arrIndex[0]; } } this.OnTagResult(tagInfo); Console.WriteLine("抛数完毕。" + listTagInfos[0].MachineID); if (!string.IsNullOrEmpty(strRecordIndex)) { string[] arrIndex = strRecordIndex.Split('-'); if (arrIndex != null && arrIndex.Length > 2) { string strMacID = arrIndex[0]; int iMacIDIndex = int.Parse(strMacID); string strIndex = arrIndex[2]; string strSstatus = arrIndex[3]; if (strSstatus == "01") { OrderSend_ConfirmBatchData(iMacIDIndex, strIndex); Console.WriteLine("确认完毕。" + iMacIDIndex.ToString() + " " + DateTime.Now.ToString()); } } } #endregion } else if (this._currentDataType == EnumRecDataMode.AdjustTimeMode)//时间获取模式 { #region 时间检查处理 this._iRecordMaxLen = 28; int iMacIDChkTime = 0; DateTime?dtGet = DataHandling_FormatMacTimeVal(strInput, ref iMacIDChkTime); if (iMacIDChkTime != 0) { if (!this.DicReaderExDetails.Keys.Contains(iMacIDChkTime)) { return; } ReaderExDetailInfo readerChk = this.DicReaderExDetails[iMacIDChkTime]; if (dtGet != null) { // 获取到有效的机器时间后,将此时间值赋予获取成功标识。 readerChk.Ex_dtLastTimeChk = dtGet.Value; readerChk.Ex_iCounterTimeChk = 0; readerChk.Ex_lIsSendTimeChkWarning = false; } else { readerChk.Ex_iCounterTimeChk++; } } #endregion } } } catch (Exception ex) { this.axMSComm05 = new AxMSCommLib.AxMSComm(); InitComPort(); if (!this.axMSComm05.PortOpen) { this.axMSComm05.CommPort = base.CommPort; this.axMSComm05.PortOpen = true; } } } }