예제 #1
0
 private static void gatherData(object obj)
 {
     dtRunHdl = DateTime.Now;
     while (true)
     {
         hdlWh.Reset();
         for (int i = 0; i < 200; i++)
         {
             if (dvQueue.Count > 0)
             {
                 break;
             }
             dtRunHdl = DateTime.Now;
             hdlWh.WaitOne(20);
         }
         if (dvQueue.Count < 1)
         {
             dtRunHdl = DateTime.MinValue;
             break;
         }
         DeviceDoor door = null;
         Monitor.Enter(dvQueue);
         try { door = dvQueue.Dequeue(); }
         catch { }
         Monitor.PulseAll(dvQueue);
         Monitor.Exit(dvQueue);
         if (null == door)
         {
             continue;
         }
         //采集记录
         if (null != door.cmdGather)
         {
             door.cmdGather.TimeSendInv = door.tsbusy.Add(door.tsinv);
         }
         else
         {
             door.reChecking(0);
         }
         CmdProtocol cmdP = new CmdProtocol(false);
         setTimeout(cmdP);
         cmdP.TimeFailLimit   = cmdP.TimeOut.Add(new TimeSpan(-10 * 10000));
         cmdP.TimeLimit       = TimeSpan.MaxValue;
         cmdP.TimeSendInv     = new TimeSpan(1, 0, 0);
         cmdP.ResponseHandle += new EventHandler <ResponseEventArgs>(door.execResponse);
         cmdP.IsResposeHandle = isResponse;
         string tag = "@设备地址=" + Convert.ToString(door.station);
         NameValueCollection datainfo = new NameValueCollection();
         string msgprev = "";
         for (int i = 0; i < 200; i++)
         {
             tag = basefun.setvaltag(tag, "{记录索引}", Convert.ToString(door.posRecord));
             string msg = door.getResponse(door.commimgr, door.target, cmdP, "读取记录", tag, door.waitTime);
             if (string.IsNullOrEmpty(msg))
             {
                 continue;
             }
             if (string.IsNullOrEmpty(msgprev))
             {
                 msgprev = msg;
             }
             string cardnum = basefun.valtag(msg, "{卡号}");
             string suc     = basefun.valtag(msg, "Success");
             if ("true" != suc || "16777215" == cardnum || "0" == cardnum)
             {
                 //bool isend = door.IsEndReadDevice(-1);
                 //记录错误时记入日志,继续下一条
                 if ("false" == suc)
                 {
                     door.posRecord++;
                     datainfo["操作"] = "读取记录失败";
                     datainfo["报文"] = CommandBase.Parse(cmdP.ResponseData, true);
                     ServiceTool.LogMessage(msg, datainfo, EventLogEntryType.FailureAudit);
                 }
                 //if (isend && door.posRecord > 20000)
                 //    door.ClearRecord();
                 //if (isend)  break;
                 if (door.posRecord > 20000)
                 {
                     bool isend = door.IsEndReadDevice(-1);
                     if (isend)
                     {
                         door.ClearRecord();
                     }
                 }
                 break;
             }
             msgprev = msg;
             if ("考勤机" == door.devtype)
             {
                 door.writeRecord(msg, true);
             }
             door.posRecord++;
         }
         //门禁设备只处理最后一条记录
         if (string.IsNullOrEmpty(msgprev) && "考勤机" != door.devtype)
         {
             door.writeRecord(msgprev, false);
         }
         door.commimgr.RemoveCommand(door.target, cmdP);
         if (null != door.cmdGather)
         {
             door.cmdGather.TimeSendInv = door.tsinv;
         }
         else
         {
             door.reChecking(1);
         }
     }
 }