Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        void TH24GTypeAR_Socket_OnMachineIDChanging(object sender, MachineIDChangedEventArgs args)
        {
            if (args != null)
            {
                int iMacID = args.NewMacID;

                //添加入自检记录列表
                if (this.DicReaderDetails == null)
                {
                    this.DicReaderDetails = new Dictionary <int, ReaderExDetailInfo>();
                }
                if (!this.DicReaderDetails.Keys.Contains(iMacID))
                {
                    ReaderExDetailInfo readerExDetail = new ReaderExDetailInfo();
                    readerExDetail.Ex_MacID = iMacID;
                    this.DicReaderDetails.Add(iMacID, readerExDetail);
                }
            }
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        /// <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;
                    }
                }
            }
        }