/// <summary> /// 批量读数时钟 /// </summary> void _tmrReadBatchData_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { int iMacID = base.MachineID; try { //CheckMachineTime(); if (!this._isReading) { this._isReading = true; } if (this._currentDataType == EnumRecDataMode.CollectRecordMode) { OrderSend_GetBatchData(iMacID); } } catch (Exception ex) { Common.General.WriteLocalLogs(Common.General.GetCurrentFuncName(), "批量读数异常:" + ex.Message, string.Empty, SystemLog.SystemLog.LogType.Error, SystemLog.SystemLog.FileType.LogFile); ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.MachineID = iMacID; args.ExceptionObject = ex; args.RecordTime = DateTime.Now; OnReaderException(args); } }
static void r_ReadException(object sender, ReaderExceptionEventArgs e) { Reader r = (Reader)sender; Console.WriteLine("Exception reader uri {0}", (string)r.ParamGet("/reader/uri")); Console.WriteLine("Error: " + e.ReaderException.Message); }
/// <summary> /// 闲时获取机器的内部时间值并作校验 /// </summary> void _tmrCheckTime_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (this.DicReaderExDetails == null) { return; } DateTime dtStart = DateTime.Now.Date; DateTime dtEnd = DateTime.Now.Date.AddHours(1); if (DateTime.Now > dtStart && DateTime.Now < dtEnd)// 在自检时段内并且未完成自检,则重复发送时间获取时间的指令 { if (this._currentDataType != EnumRecDataMode.AdjustTimeMode) { if (this._tmrReadData.Enabled) { this._tmrReadData.Stop(); } this._currentDataType = EnumRecDataMode.AdjustTimeMode; } OrderSend_GetMacTime(base.MachineID); } else { if (this._currentDataType != EnumRecDataMode.CollectRecordMode) { foreach (KeyValuePair <int, ReaderExDetailInfo> detailPair in DicReaderExDetails) { if (detailPair.Value.Ex_dtLastTimeChk.Date < DateTime.Now.AddMinutes(-5) || detailPair.Value.Ex_dtLastTimeChk.Date > DateTime.Now.AddMinutes(5)) { if (detailPair.Value.Ex_dtLastTimeChk == DateTime.MinValue || detailPair.Value.CurrentStatus == EnumEquipmentStatus.Disconneted) { //读写器未连接或检查时间未被刷新时不作错误提醒 continue; } if (!detailPair.Value.Ex_lIsSendTimeChkWarning && detailPair.Value.CurrentStatus != EnumEquipmentStatus.TimeException) { ReaderExceptionEventArgs readerEx = new ReaderExceptionEventArgs(); readerEx.EquipmentStatus = EnumEquipmentStatus.TimeException; readerEx.MachineID = detailPair.Value.Ex_MacID; readerEx.ExceptionObject = new Exception("机器时间有误,机号:" + readerEx.MachineID); OnReaderException(readerEx); detailPair.Value.CurrentStatus = EnumEquipmentStatus.TimeException; detailPair.Value.Ex_lIsSendTimeChkWarning = true; } } } OrderSend_ResetTime("255"); if (!this._tmrReadData.Enabled) { this._tmrReadData.Start(); } this._currentDataType = EnumRecDataMode.CollectRecordMode; } } }
void _ObjReader_ReadException(object sender, ReaderExceptionEventArgs e) { try { //logger.Error(e.ReaderException.Message, e.ReaderException); writeErrorLog(e.ReaderException.Message, e.ReaderException); if (_form.InvokeRequired) { _form.Invoke(new ShowStatusDelegate(_ObjReader_ReadException), sender, e); } else { if (OnTagReadException != null) { OnTagReadException.Invoke(sender, e); } } } catch (Exception ex) { writeErrorLog(ex.Message, ex); throw ex; } }
/// <summary> /// 读取的操作 /// </summary> void readFunc() { ParameterizedThreadStart threadStart = new ParameterizedThreadStart(addTagToFilter); Thread threadActive = new Thread(threadStart); while (_isReading) { try { TagReadData[] reads = _readerAPI.Read(_readTime); List <TagEntity> entityList = new List <TagEntity>(); foreach (TagReadData read in reads) { entityList.Add(new TagEntity() { TagNo = read.EPCString, TagId = read.EPCString }); } //出发保存tag if (entityList.Count > 0) { threadActive = new Thread(threadStart); threadActive.Start(entityList); } entityList = null; Thread.Sleep(_readSpace); } catch (FatalInternalException ex) { //找读写器内部出现错误, 应该重新创建读写器 Console.WriteLine("读写器内部出现错误,系统尝试重新连接,错误信息:{0}.", ex.Message); ThreadStart threadReConnect = new ThreadStart(reConnect); Thread thread = new Thread(threadReConnect); thread.Start(); return; } catch (Exception exx) { ReaderExceptionEventArgs exceptionArgs = new ReaderExceptionEventArgs(); exceptionArgs.ExceptionObject = new Exception(); exceptionArgs.ExceptionObject.Source = "重新连接后失败,请检查网络。错误信息:" + exx.Message; OnReaderException(exceptionArgs); //throw exx; } } }
/// <summary> /// 检查设备是否无数据返回 /// </summary> void _tmrChkNullData_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (this.DicReaderDetails == null) { return; } foreach (KeyValuePair <int, ReaderExDetailInfo> detailPair in this.DicReaderDetails) { if (detailPair.Value.Ex_dtRvData < DateTime.Now.AddMinutes(-1)) { //如果超过一分钟未更新接收数据的时间,则开始累计 detailPair.Value.Ex_iCounterRvData++; } if (detailPair.Value.Ex_dtRvData < DateTime.Now.AddSeconds(_iMaxRvDataTime))//最长等待时间内无任何数据返回 { if (detailPair.Value.Ex_dtRvData == DateTime.MinValue) { continue; } if (detailPair.Value.Ex_iCounterRvData > _iRetryMaxCount)//达到最大重试次数 { if (!detailPair.Value.Ex_lIsSendNullDataWarning) { detailPair.Value.Ex_lIsSendNullDataWarning = true; ReaderExceptionEventArgs exArgs = new ReaderExceptionEventArgs(); exArgs.EquipmentStatus = EnumEquipmentStatus.Disconneted; exArgs.ExceptionObject = new Exception("连接中断,无数据返回。"); exArgs.MachineID = detailPair.Value.Ex_MacID; exArgs.RecordTime = DateTime.Now; if (detailPair.Value.CurrentStatus != EnumEquipmentStatus.Disconneted) { EquipmentStatusEventArgs statusArgs = new EquipmentStatusEventArgs(); statusArgs.EquipmentStatus = EnumEquipmentStatus.Disconneted; statusArgs.MachineID = detailPair.Value.Ex_MacID; statusArgs.RecordTime = DateTime.Now; OnStatusChange(statusArgs); detailPair.Value.CurrentStatus = EnumEquipmentStatus.Disconneted; } OnReaderException(exArgs); } } } } }
public TH24GTypeAR_Socket() { try { this._isConnected = false; this._iMaxRvDataTime = -3600; this._iRetryMaxCount = 2000; this._isReading = false; this.MachineID = 0; this._dicReaderDetails = new Dictionary <int, ReaderExDetailInfo>(); this._ConnectDone = new ManualResetEvent(false); this.OnMachineIDChanging += new MachineIDChangedDelegate(TH24GTypeAR_Socket_OnMachineIDChanging); this._tmrReadBatchData = new System.Timers.Timer(); this._tmrReadBatchData.Interval = 1000; this._tmrReadBatchData.Elapsed += new System.Timers.ElapsedEventHandler(_tmrReadBatchData_Elapsed); this._tmrChkNullData = new System.Timers.Timer(); this._tmrChkNullData.Interval = 3000; this._tmrChkNullData.Elapsed += new System.Timers.ElapsedEventHandler(_tmrChkNullData_Elapsed); this._tmrCheckTime = new System.Timers.Timer(); this._tmrCheckTime.Interval = 5000; this._tmrCheckTime.Elapsed += new System.Timers.ElapsedEventHandler(_tmrCheckTime_Elapsed); this._tmrReceiveData = new System.Timers.Timer(); this._tmrReceiveData.Interval = 4000; this._tmrReceiveData.Elapsed += new System.Timers.ElapsedEventHandler(_tmrReceiveData_Elapsed); } catch (Exception ex) { ReaderGeneral.ConsoleWrite(ex.Message); ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.ExceptionObject = ex; args.RecordTime = DateTime.Now; OnReaderException(args); } }
private void ReadException(Object sender, ReaderExceptionEventArgs e) { if (-1 != e.ReaderException.Message.IndexOf("DEBUG")) { logger.Info("ReadException listener: " + e.ReaderException.Message); return; } logger.Error("ReadException listener: " + e.ReaderException.ToString()); if (-1 != e.ReaderException.Message.IndexOf("temperature")) { this.BeginInvoke(new OverTemperatureChange(ShowOverTemperature)); } else { SetDebug(e.ReaderException.Message); logger.Debug("Calling StopReads in ReadException listener..."); StopReads(); logger.Debug("StopReads completed in ReadException listener"); } }
/// <summary> /// 确认批量数据 /// </summary> private void OrderSend_ConfirmBatchData(int iMacID, string strRecordIndex) { byte[] arrDataSend = { 0xC0, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] byMacID = BitConverter.GetBytes(iMacID); arrDataSend[1] = byMacID[0]; int iRecordIndex = Convert.ToInt32(strRecordIndex, 16); byte[] byRecordIndex = BitConverter.GetBytes(iRecordIndex); arrDataSend[4] = byRecordIndex[1]; arrDataSend[5] = byRecordIndex[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out highCRC, out lowCRC); arrDataSend[6] = lowCRC; arrDataSend[7] = highCRC; try { if (this._SendClient != null) { this._SendClient.Send(arrDataSend); //DataReceive(); } } catch (Exception ex) { ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.MachineID = iMacID; args.ExceptionObject = ex; args.RecordTime = DateTime.Now; OnReaderException(args); } }
static void r_ReadException(object sender, ReaderExceptionEventArgs e) { Console.WriteLine("Error: " + e.ReaderException.Message); }
void _reader_ReadException(object sender, ReaderExceptionEventArgs e) { //throw new NotImplementedException(); Console.WriteLine(e.ReaderException.Message); }
private void r_ReadException(object sender, ReaderExceptionEventArgs e) { MetroMessageBox.Show(this, e.ReaderException.Message, "Error"); }
public override bool Disconnect() { try { if (!this._isConnected) { return(true); } if (this._tmrChkNullData != null) { this._tmrChkNullData.Stop(); } if (this._tmrReadBatchData != null) { this._tmrReadBatchData.Stop(); } if (this._tmrReceiveData != null) { this._tmrReceiveData.Stop(); } if (this._tmrCheckTime != null) { this._tmrCheckTime.Stop(); } if (this._dicReaderDetails != null) { foreach (KeyValuePair <int, ReaderExDetailInfo> detailPair in this._dicReaderDetails) { if (detailPair.Value.CurrentStatus != EnumEquipmentStatus.Disconneted) { detailPair.Value.CurrentStatus = EnumEquipmentStatus.Disconneted; EquipmentStatusEventArgs statusArgs = new EquipmentStatusEventArgs(); statusArgs.EquipmentStatus = EnumEquipmentStatus.Disconneted; statusArgs.RecordTime = DateTime.Now; statusArgs.MachineID = detailPair.Value.Ex_MacID; OnStatusChange(statusArgs); } detailPair.Value.ResetAllSign(); } } this._listHistoryIndex.Clear(); if (this._SendClient == null) { this._SendClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } this._SendClient.Shutdown(SocketShutdown.Both); this._SendClient.Disconnect(false); this._SendClient.Close(); ReaderGeneral.ConsoleWrite("Disconnected.........."); } catch (Exception ex) { ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.ExceptionObject = ex; args.RecordTime = DateTime.Now; OnReaderException(args); return(false); } finally { this._isConnected = false; } return(true); }
/// <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; } }