コード例 #1
0
        /// <summary>
        /// 火警开门
        /// </summary>
        public void FireOpenDoor()
        {
            if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1)
            {
                return;
            }
            if ("考勤机" == this.devtype)
            {
                return;
            }
            CmdProtocol cmdP = new CmdProtocol(false);

            setTimeout(cmdP);
            cmdP.IsResposeHandle = isResponse;
            //设置门参数
            string tag = "@设备地址=" + Convert.ToString(this.station);

            tag = basefun.setvaltag(tag, "{控制方式}", "1");
            tag = basefun.setvaltag(tag, "{延时}", "0");
            //string[,] colmapdoor ={ { "{控制方式}", "1" }, { "{延时}", "0" }, { "{门号}", "门号" } };
            this.reChecking(0);
            for (int i = 1; i < 5; i++)
            {
                tag = basefun.setvaltag(tag, "{门号}", Convert.ToString(i));
                string msg = "";
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
                myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
                cmdP.setCommand("门禁", "设置控制参数", tag);
                cmdP.ResetState();
                this.commimgr.SendCommand(this.target, cmdP);
                if (cmdP.EventWh.WaitOne(this.waitTime, false))
                {
                    msg = cmdP.ResponseFormat;
                }
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                msg = "";
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
                myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
                cmdP.setCommand("门禁", "远程开门", tag);
                cmdP.ResetState();
                this.commimgr.SendCommand(this.target, cmdP);
                if (cmdP.EventWh.WaitOne(this.waitTime, false))
                {
                    msg = cmdP.ResponseFormat;
                }
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
                if ("单门双向" == this.devtype)
                {
                    break;
                }
                if ("双门双向" == this.devtype && i > 1)
                {
                    break;
                }
            }
            this.reChecking(1);
        }
コード例 #2
0
        /// <summary>
        /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次
        /// </summary>
        /// <param name="mgr">通讯管理器</param>
        /// <param name="target">通讯目标</param>
        /// <param name="cmd">执行指令</param>
        /// <param name="timeout">超时间隔</param>
        /// <returns>返回指令响应结果</returns>
        private static string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, TimeSpan timeout)
        {
            if (null == mgr || null == target || null == cmd)
            {
                return("");
            }
            if (null == cmd.EventWh)
            {
                cmd.EventWh = new ManualResetEvent(false);
            }
            string msg = "";

            for (int i = 0; i < 5; i++)
            {
                msg = "";
                cmd.ResetState();
                mgr.SendCommand(target, cmd);
                if (cmd.EventWh.WaitOne(timeout, false))
                {
                    msg = cmd.ResponseFormat;
                }
                string suc = basefun.valtag(msg, "Success");
                if ("true" == suc)
                {
                    break;
                }
                Thread.Sleep(200);
            }
            return(msg);
        }
コード例 #3
0
        private void tmRefresh_Tick(object sender, EventArgs e)
        {
            if (isRunning)
            {
                return;
            }
            isRunning = true;
            //巡检过的设备地址加入devs中,避免重复巡检
            string devs = ",", tpl = "门禁";
            // isrealtime/是否实时状态,在最后刷卡时间5分钟不变化时可对累积数据大批量采集
            bool     isrealtime = false;
            DateTime dtpre      = DateTime.Now.AddMinutes(-5);
            //有信息则记录日志
            DataView dvinfo = gridViewInfo.DataSource as DataView;
            //站址/记录数列表,非实时采集状态时优先批量采集记录数大的
            Dictionary <string, int>      devrecord  = new Dictionary <string, int>();
            Dictionary <string, string[]> devinfo    = new Dictionary <string, string[]>();
            List <CommiTarget>            targetlist = new List <CommiTarget>();
            CmdProtocol cmdP = new CmdProtocol(false);

            cmdP.TimeOut       = new TimeSpan(400 * 10000);
            cmdP.TimeSendInv   = new TimeSpan(1, 0, 0);
            cmdP.TimeFailLimit = new TimeSpan(900 * 10000);
            cmdP.TimeLimit     = new TimeSpan(900 * 10000);
            NameObjectList psdata = new NameObjectList();

            for (int i = 0; i < lvDoor.Items.Count; i++)
            {
                string tag = Convert.ToString(lvDoor.Items[i].Tag);
                if (string.IsNullOrEmpty(tag))
                {
                    continue;
                }
                string[] devps = tag.Split(",".ToCharArray());
                if (devs.Contains("," + devps[7] + ","))
                {
                    continue;
                }
                CommiTarget target = this.getTarget(devps);
                if (null == target)
                {
                    continue;
                }
                targetlist.Add(target);
                tag   = "@设备地址=" + devps[7];
                devs += devps[7] + ",";
                cmdP.setCommand(tpl, "检测状态", tag);
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(target, cmdP);
                if (!cmdP.EventWh.WaitOne(300, false))
                {
                    continue;
                }
                string msg = cmdP.ResponseFormat;
                DevID = basefun.valtag(msg, "{设备地址}");
                //获得要开的门
                getDKQ(devps[10], basefun.valtag(msg, "读卡器"));
                //通讯图标显示
                ListViewItem list1 = null;
                for (int k = 0; k < lvDoor.Items.Count; k++)
                {
                    list1 = this.lvDoor.Items[k];
                    DoorStatus(list1, basefun.valtag(msg, "Success"));
                }
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    continue;
                }
                //对比最后刷卡时间
                string dtstr = basefun.valtag(msg, "{刷卡时间}");
                if (!string.IsNullOrEmpty(dtstr) && !isrealtime)
                {
                    if (dtpre < Convert.ToDateTime(dtstr))
                    {
                        isrealtime = true;
                    }
                }
                //记录数列表
                int sum = Convert.ToInt32(basefun.valtag(msg, "{刷卡记录数}"));
                devrecord.Add(devps[7], sum);
                devinfo.Add(devps[7], devps);

                //记录数少于50则直接采集
                int rdcount = 0;
                for (int j = 0; j < sum && sum <= 50; j++)
                {
                    cmdP.ResetState();
                    cmdP.setCommand(tpl, "读取记录", tag);
                    CommiManager.GlobalManager.SendCommand(target, cmdP);
                    if (!cmdP.EventWh.WaitOne(1000, false))
                    {
                        continue;
                    }
                    msg = cmdP.ResponseFormat;
                    if ("true" != basefun.valtag(msg, "Success"))
                    {
                        break;
                    }
                    string state = basefun.valtag(msg, "状态编号");
                    state         = this.getStateDoorCard(state);
                    psdata["控制器"] = devps[8];
                    psdata["读卡器"] = DKQNUN;
                    psdata["时间"]  = basefun.valtag(msg, "{刷卡时间}");
                    psdata["卡号"]  = basefun.valtag(msg, "{卡号}");
                    if (devps[10] == "考勤机")
                    {
                        psdata["状态"] = "考勤机";
                    }
                    else
                    {
                        psdata["状态"] = state;
                    }
                    this.Query.ExecuteNonQuery("采集门禁数据", psdata, psdata, psdata);
                    rdcount++;
                    //devrecord.Remove(devps[7]);
                    //DataRow drinfo = dvinfo.Table.NewRow();
                    //drinfo["状态"] = state;
                    //drinfo["卡号"] = basefun.valtag(msg, "{卡号}");
                    //int dkq = Convert.ToInt16(basefun.valtag(msg, "读卡器"));
                    //dkq = dkq + 1;
                    //drinfo["门"] = doorName + "(" + Convert.ToString(dkq) + ")";
                    //drinfo["设备地址"] = basefun.valtag(msg, "{设备地址}");
                    //drinfo["时间"] = basefun.valtag(msg, "{刷卡时间}");
                    //dvinfo.Table.Rows.InsertAt(drinfo, 0);
                    //gridViewInfo.SelectRow(0);
                }

                if (rdcount > 0)
                {
                    dataCount = rdcount.ToString();
                }
                else
                {
                    dataCount = "0";
                }
                //检查状态改变则记录
                this.validateSate(lvDoor.Items[i], devps[8], msg, devps[10]);
            }
            //当前是实时状态,则忽略采集数据
            if (isrealtime || devrecord.Count < 1)
            {
                foreach (CommiTarget tar in targetlist)
                {
                    CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
                }
                isRunning = false;
                return;
            }
            string[] info   = new string[0];
            int      summax = 0;

            foreach (string key in devrecord.Keys)
            {
                if (summax >= devrecord[key])
                {
                    continue;
                }
                summax = devrecord[key];
                info   = devinfo[key];
            }
            if (summax < 1)
            {
                foreach (CommiTarget tar in targetlist)
                {
                    CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
                }
                isRunning = false;
                return;
            }
            CommiTarget dev = this.getTarget(info);
            //记录数少于50则直接采集
            int rdcountmax = 0;

            for (int j = 0; j < summax && null != dev; j++)
            {
                string tag = "@设备地址=" + info[7];
                cmdP.ResetState();
                cmdP.setCommand(tpl, "读取记录", tag);
                CommiManager.GlobalManager.SendCommand(dev, cmdP);
                if (!cmdP.EventWh.WaitOne(1000, false))
                {
                    continue;
                }
                string msg = cmdP.ResponseFormat;
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    break;
                }
                string state = basefun.valtag(msg, "状态编号");
                state         = this.getStateDoorCard(state);
                psdata["控制器"] = info[8];
                psdata["读卡器"] = DKQNUN;
                psdata["卡号"]  = basefun.valtag(msg, "{卡号}");
                psdata["时间"]  = basefun.valtag(msg, "{刷卡时间}");
                psdata["状态"]  = state;
                this.Query.ExecuteNonQuery("采集门禁数据", psdata, psdata, psdata);
                rdcountmax++;
            }
            foreach (CommiTarget tar in targetlist)
            {
                CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
            }
            isRunning = false;
        }
コード例 #4
0
        private void tmRefresh_Tick(object sender, EventArgs e)
        {
            if (isRunning) return;
            isRunning = true;
            //Ѳ������豸��ַ����devs��,�����ظ�Ѳ��
            string devs = ",", tpl = "����";
            // isrealtime/�Ƿ�ʵʱ״̬,�����ˢ��ʱ��5���Ӳ��仯ʱ�ɶ��ۻ����ݴ������ɼ�
            bool isrealtime = false;
            TimeSpan tspre = new TimeSpan(0, 5, 0);
            //����Ϣ���¼��־
            DataView dvinfo = gridViewInfo.DataSource as DataView;
            //վַ/��¼���б�,��ʵʱ�ɼ�״̬ʱ���������ɼ���¼�����
            Dictionary<string, int> devrecord = new Dictionary<string, int>();
            Dictionary<string, string[]> devinfo = new Dictionary<string, string[]>();
            List<CommiTarget> targetlist = new List<CommiTarget>();
            CmdProtocol cmdP = new CmdProtocol(false);
            cmdP.TimeOut = new TimeSpan(400 * 10000);
            cmdP.TimeSendInv = new TimeSpan(1, 0, 0);
            cmdP.TimeFailLimit = new TimeSpan(900 * 10000);
            cmdP.TimeLimit = new TimeSpan(900 * 10000);
            NameObjectList psdata = new NameObjectList();
            for (int i = 0; i < lvEatery.Items.Count; i++)
            {
                string tag = Convert.ToString(lvEatery.Items[i].Tag);
                if (string.IsNullOrEmpty(tag))
                    continue;
                string[] devps = tag.Split(",".ToCharArray());
                if (devs.Contains("," + devps[7] + ","))
                    continue;
                CommiTarget target = this.getTarget(devps);
                if (null == target) continue;
                targetlist.Add(target);
                tag = "@�豸��ַ=" + devps[7];
                devs += devps[7] + ",";
                cmdP.setCommand(tpl, "���״̬", tag);
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(target, cmdP);
                ListViewItem list1 = this.lvEatery.Items[i];
                if (!cmdP.EventWh.WaitOne(300, false))
                    continue;
                string msg = cmdP.ResponseFormat;

                EateryStatus(list1, basefun.valtag(msg, "{״̬}"));
                if ("true" != basefun.valtag(msg, "Success"))
                    continue;
                string val = basefun.valtag(msg, "������");
                if (!this.dtprelist.ContainsKey(devps[7]))
                    this.dtprelist.Add(devps[7], DateTime.Now.AddMinutes(-4));
                if ("1" == val)
                    this.dtprelist[devps[7]] = DateTime.Now;
                //��¼���б�
                int sum = Convert.ToInt32(basefun.valtag(msg, "{�ɼ���־}"));
                devrecord.Add(devps[7], sum);
                devinfo.Add(devps[7], devps);
                //���״̬�ı����¼
                this.validateSate(lvEatery.Items[i], devps[8], msg);
            }
            foreach (string key in devrecord.Keys)
            {
                if (devrecord[key] < 1 || !this.dtprelist.ContainsKey(key) || !devinfo.ContainsKey(key))
                    continue;
                if (DateTime.Now - this.dtprelist[key] < tspre)
                    continue;
                //�ڼ��tspre(5����)û�й���״̬������Բɼ�10����¼
                string[] info = devinfo[key];
                for (int i = 0; i < 11; i++)
                {
                    string tag = "@�豸��ַ=" + info[7];
                    CommiTarget target = this.getTarget(info);
                    if (null == target) continue;
                    if (i < 1)
                        cmdP.setCommand(tpl, "ȡ��ǰ���Ѽ�¼", tag);
                    else
                        cmdP.setCommand(tpl, "ȡ��һ�����Ѽ�¼", tag);
                    cmdP.ResetState();
                    CommiManager.GlobalManager.SendCommand(target, cmdP);
                    if (!cmdP.EventWh.WaitOne(300, false))
                        continue;
                    string msg = cmdP.ResponseFormat;
                    if ("true" != basefun.valtag(msg, "Success"))
                        continue;
                    if (string.IsNullOrEmpty(basefun.valtag(msg, "{����}")))
                        break;
                    NameObjectList ps = ParamManager.createParam(msg);
                    ps["���ѻ�"] = info[8];
                    bool success = this.Query.ExecuteNonQuery("�ɼ�����", ps, ps, ps);
                    AddEateryStatus(msg);
                    if (!success) break;
                }
                break;
            }
            foreach (CommiTarget tar in targetlist)
                CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
            isRunning = false;
        }
コード例 #5
0
ファイル: DeviceEatery.cs プロジェクト: BillyWu/Granitypark
 /// <summary>
 /// ����ָ���ȡָ��������ͨѶʧ��ʱ�Զ�����ִ��5��
 /// </summary>
 /// <param name="mgr">ͨѶ������</param>
 /// <param name="target">ͨѶĿ��</param>
 /// <param name="cmd">ִ��ָ��</param>
 /// <param name="timeout">��ʱ���</param>
 /// <returns>����ָ����Ӧ���</returns>
 private static string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, TimeSpan timeout)
 {
     if (null == mgr || null == target || null == cmd)
         return "";
     if(null==cmd.EventWh)
         cmd.EventWh = new ManualResetEvent(false);
     string msg = "";
     for (int i = 0; i < 5; i++)
     {
         msg = "";
         cmd.ResetState();
         mgr.SendCommand(target, cmd);
         if (cmd.EventWh.WaitOne(timeout, false))
             msg = cmd.ResponseFormat;
         string suc = basefun.valtag(msg, "Success");
         if ("true" == suc)
             break;
         Thread.Sleep(200);
     }
     return msg;
 }
コード例 #6
0
ファイル: FrmDoorMonitor.cs プロジェクト: BillyWu/Granitypark
        private void tmRefresh_Tick(object sender, EventArgs e)
        {
            if (isRunning) return;
            isRunning = true;
            //巡检过的设备地址加入devs中,避免重复巡检
            string devs = ",", tpl = "门禁";
            // isrealtime/是否实时状态,在最后刷卡时间5分钟不变化时可对累积数据大批量采集
            bool isrealtime = false;
            DateTime dtpre = DateTime.Now.AddMinutes(-5);
            //有信息则记录日志
            DataView dvinfo = gridViewInfo.DataSource as DataView;
            //站址/记录数列表,非实时采集状态时优先批量采集记录数大的
            Dictionary<string, int> devrecord = new Dictionary<string, int>();
            Dictionary<string, string[]> devinfo = new Dictionary<string, string[]>();
            List<CommiTarget> targetlist = new List<CommiTarget>();
            CmdProtocol cmdP = new CmdProtocol(false);
            cmdP.TimeOut = new TimeSpan(400 * 10000);
            cmdP.TimeSendInv = new TimeSpan(1, 0, 0);
            cmdP.TimeFailLimit = new TimeSpan(900 * 10000);
            cmdP.TimeLimit = new TimeSpan(900 * 10000);
            NameObjectList psdata = new NameObjectList();
            for (int i = 0; i < lvDoor.Items.Count; i++)
            {
                string tag = Convert.ToString(lvDoor.Items[i].Tag);
                if (string.IsNullOrEmpty(tag))
                    continue;
                string[] devps = tag.Split(",".ToCharArray());
                if (devs.Contains("," + devps[7] + ","))
                    continue;
                CommiTarget target = this.getTarget(devps);
                if (null == target) continue;
                targetlist.Add(target);
                tag = "@设备地址=" + devps[7];
                devs += devps[7] + ",";
                cmdP.setCommand(tpl, "检测状态", tag);
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(target, cmdP);
                if (!cmdP.EventWh.WaitOne(300, false))
                    continue;
                string msg = cmdP.ResponseFormat;
                DevID = basefun.valtag(msg, "{设备地址}");
                //获得要开的门
                getDKQ(devps[10], basefun.valtag(msg, "读卡器"));
                //通讯图标显示
                ListViewItem list1 = null;
                for (int k = 0; k < lvDoor.Items.Count; k++)
                {
                    list1 = this.lvDoor.Items[k];
                    DoorStatus(list1, basefun.valtag(msg, "Success"));
                }
                if ("true" != basefun.valtag(msg, "Success"))
                    continue;
                //对比最后刷卡时间
                string dtstr = basefun.valtag(msg, "{刷卡时间}");
                if (!string.IsNullOrEmpty(dtstr) && !isrealtime)
                {
                    if (dtpre < Convert.ToDateTime(dtstr))
                        isrealtime = true;
                }
                //记录数列表
                int sum = Convert.ToInt32(basefun.valtag(msg, "{刷卡记录数}"));
                devrecord.Add(devps[7], sum);
                devinfo.Add(devps[7], devps);

                //记录数少于50则直接采集
                int rdcount = 0;
                for (int j = 0; j < sum && sum <= 50; j++)
                {
                    cmdP.ResetState();
                    cmdP.setCommand(tpl, "读取记录", tag);
                    CommiManager.GlobalManager.SendCommand(target, cmdP);
                    if (!cmdP.EventWh.WaitOne(1000, false))
                        continue;
                    msg = cmdP.ResponseFormat;
                    if ("true" != basefun.valtag(msg, "Success"))
                        break;
                    string state = basefun.valtag(msg, "状态编号");
                    state = this.getStateDoorCard(state);
                    psdata["控制器"] = devps[8];
                    psdata["读卡器"] = DKQNUN;
                    psdata["时间"] = basefun.valtag(msg, "{刷卡时间}");
                    psdata["卡号"] = basefun.valtag(msg, "{卡号}");
                    if (devps[10] == "考勤机")
                        psdata["状态"] = "考勤机";
                    else
                        psdata["状态"] = state;
                    this.Query.ExecuteNonQuery("采集门禁数据", psdata, psdata, psdata);
                    rdcount++;
                    //devrecord.Remove(devps[7]);
                    //DataRow drinfo = dvinfo.Table.NewRow();
                    //drinfo["状态"] = state;
                    //drinfo["卡号"] = basefun.valtag(msg, "{卡号}");
                    //int dkq = Convert.ToInt16(basefun.valtag(msg, "读卡器"));
                    //dkq = dkq + 1;
                    //drinfo["门"] = doorName + "(" + Convert.ToString(dkq) + ")";
                    //drinfo["设备地址"] = basefun.valtag(msg, "{设备地址}");
                    //drinfo["时间"] = basefun.valtag(msg, "{刷卡时间}");
                    //dvinfo.Table.Rows.InsertAt(drinfo, 0);
                    //gridViewInfo.SelectRow(0);
                }

                if (rdcount > 0)
                    dataCount = rdcount.ToString();
                else
                    dataCount = "0";
                //检查状态改变则记录
                this.validateSate(lvDoor.Items[i], devps[8], msg, devps[10]);
            }
            //当前是实时状态,则忽略采集数据
            if (isrealtime || devrecord.Count < 1)
            {
                foreach (CommiTarget tar in targetlist)
                    CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
                isRunning = false;
                return;
            }
            string[] info = new string[0];
            int summax = 0;
            foreach (string key in devrecord.Keys)
            {
                if (summax >= devrecord[key])
                    continue;
                summax = devrecord[key];
                info = devinfo[key];
            }
            if (summax < 1)
            {
                foreach (CommiTarget tar in targetlist)
                    CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
                isRunning = false;
                return;
            }
            CommiTarget dev = this.getTarget(info);
            //记录数少于50则直接采集
            int rdcountmax = 0;
            for (int j = 0; j < summax && null != dev; j++)
            {
                string tag = "@设备地址=" + info[7];
                cmdP.ResetState();
                cmdP.setCommand(tpl, "读取记录", tag);
                CommiManager.GlobalManager.SendCommand(dev, cmdP);
                if (!cmdP.EventWh.WaitOne(1000, false))
                    continue;
                string msg = cmdP.ResponseFormat;
                if ("true" != basefun.valtag(msg, "Success"))
                    break;
                string state = basefun.valtag(msg, "状态编号");
                state = this.getStateDoorCard(state);
                psdata["控制器"] = info[8];
                psdata["读卡器"] = DKQNUN;
                psdata["卡号"] = basefun.valtag(msg, "{卡号}");
                psdata["时间"] = basefun.valtag(msg, "{刷卡时间}");
                psdata["状态"] = state;
                this.Query.ExecuteNonQuery("采集门禁数据", psdata, psdata, psdata);
                rdcountmax++;
            }
            foreach (CommiTarget tar in targetlist)
                CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
            isRunning = false;
        }
コード例 #7
0
ファイル: DeviceDoor.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e)
            {
                return;
            }
            CmdProtocol cmdP = sender as CmdProtocol;

            if (null == cmdP || 0 == this.stateChecking)
            {
                return;
            }
            if (!e.Success)
            {
                //连续长时间失败时,增大巡检周期
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                    {
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                    }
                }
                return;
            }
            string msg = cmdP.ResponseFormat;

            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
            {
                return;
            }
            //离线后恢复在线时,恢复巡检周期
            if (cmdP.TimeSendInv > this.tsbusy)
            {
                cmdP.TimeSendInv = this.tsinv;
            }
            this.validateSate(msg);

            //2分钟内记录数大于20条,则设备处于繁忙状态,空闲时可采集
            string sumstr = basefun.valtag(msg, "{刷卡记录数}");
            string dtstr  = basefun.valtag(msg, "{刷卡时间}");

            if (string.IsNullOrEmpty(sumstr) || string.IsNullOrEmpty(dtstr))
            {
                return;
            }
            int      sum    = Convert.ToInt32(sumstr);
            DateTime dtcard = DateTime.MinValue;

            try { dtcard = Convert.ToDateTime(dtstr); }
            catch { }
            if ("考勤机" == this.devtype && this.posRecord > sum)
            {
                this.posRecord = 0;
                NameObjectList posps = new NameObjectList();
                posps["控制器"] = this.devid;
                this.query.ExecuteNonQuery("重置记录位置", posps, posps, posps);
            }
            //判定是否繁忙状态
            if (sum < 1 || (sum > 60 && DateTime.Now - dtcard < this.tsbusy))
            {
                return;
            }

            //有新记录且不繁忙时可采集新记录50条
            string[] cols = { "{卡号}", "状态编号", "读卡器", "{刷卡时间}" };
            string   tag  = "@设备地址=" + Convert.ToString(this.station);
            int      st   = this.stateChecking;

            this.reChecking(0);
            bool isreset = false;

            if (sum > 10 && DateTime.Now - dtcard > (this.tsbusy + this.tsbusy + this.tsbusy))
            {
                isreset = sum <= 50;
                sum     = sum > 50 ? 51 : sum + 1;
            }
            else
            {
                isreset = sum <= 10;
                sum     = sum > 10 ? 11 : sum + 1;
            }
            TimeSpan tswait = this.waitTime;

            for (int i = 0; i < sum; i++)
            {
                if ("考勤机" == this.devtype)
                {
                    tag = basefun.setvaltag(tag, "{记录索引}", Convert.ToString(this.posRecord));
                }
                cmdP.setCommand("门禁", "读取记录", tag);
                msg = getResponse(this.commimgr, e.Target, cmdP, tswait);
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    break;
                }
                string cardnum = basefun.valtag(msg, "{卡号}");
                if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                {
                    this.posRecord++;
                    continue;
                }
                string info = "";
                for (int c = 0; c < cols.Length; c++)
                {
                    info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
                }
                info = basefun.setvaltag(info, "状态", this.getStateDoorCard(basefun.valtag(info, "状态编号")));
                NameObjectList ps = ParamManager.createParam(info);
                ps["控制器"] = this.devid;
                ps["时间"]  = ps["刷卡时间"];
                bool success = this.query.ExecuteNonQuery("采集门禁数据", ps, ps, ps);
                if (!success)
                {
                    ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
                }
                DateTime dt = Convert.ToDateTime(ps["刷卡时间"]);
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
                if (!success)
                {
                    break;
                }
                this.posRecord++;
                //最后一条提取记录
                if (i == sum - 1 && isreset && this.posRecord > 10000)
                {
                    cmdP.setCommand("门禁", "清空记录", tag);
                    cmdP.ResetState();
                    this.commimgr.SendCommand(this.target, cmdP);
                    if (cmdP.EventWh.WaitOne(this.waitTime, false))
                    {
                        string suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                        if ("true" == suc)
                        {
                            this.query.ExecuteNonQuery("重置记录位置", ps, ps, ps);
                        }
                    }
                }
            }
            this.reChecking(st);
        }
コード例 #8
0
        private void tmRefresh_Tick(object sender, EventArgs e)
        {
            if (isRunning)
            {
                return;
            }
            isRunning = true;
            //巡检过的设备地址加入devs中,避免重复巡检
            string devs = ",", tpl = "消费";
            // isrealtime/是否实时状态,在最后刷卡时间5分钟不变化时可对累积数据大批量采集
            bool     isrealtime = false;
            TimeSpan tspre      = new TimeSpan(0, 5, 0);
            //有信息则记录日志
            DataView dvinfo = gridViewInfo.DataSource as DataView;
            //站址/记录数列表,非实时采集状态时优先批量采集记录数大的
            Dictionary <string, int>      devrecord  = new Dictionary <string, int>();
            Dictionary <string, string[]> devinfo    = new Dictionary <string, string[]>();
            List <CommiTarget>            targetlist = new List <CommiTarget>();
            CmdProtocol cmdP = new CmdProtocol(false);

            cmdP.TimeOut       = new TimeSpan(400 * 10000);
            cmdP.TimeSendInv   = new TimeSpan(1, 0, 0);
            cmdP.TimeFailLimit = new TimeSpan(900 * 10000);
            cmdP.TimeLimit     = new TimeSpan(900 * 10000);
            NameObjectList psdata = new NameObjectList();

            for (int i = 0; i < lvEatery.Items.Count; i++)
            {
                string tag = Convert.ToString(lvEatery.Items[i].Tag);
                if (string.IsNullOrEmpty(tag))
                {
                    continue;
                }
                string[] devps = tag.Split(",".ToCharArray());
                if (devs.Contains("," + devps[7] + ","))
                {
                    continue;
                }
                CommiTarget target = this.getTarget(devps);
                if (null == target)
                {
                    continue;
                }
                targetlist.Add(target);
                tag   = "@设备地址=" + devps[7];
                devs += devps[7] + ",";
                cmdP.setCommand(tpl, "检测状态", tag);
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(target, cmdP);
                ListViewItem list1 = this.lvEatery.Items[i];
                if (!cmdP.EventWh.WaitOne(300, false))
                {
                    continue;
                }
                string msg = cmdP.ResponseFormat;

                EateryStatus(list1, basefun.valtag(msg, "{状态}"));
                if ("true" != basefun.valtag(msg, "Success"))
                {
                    continue;
                }
                string val = basefun.valtag(msg, "工作中");
                if (!this.dtprelist.ContainsKey(devps[7]))
                {
                    this.dtprelist.Add(devps[7], DateTime.Now.AddMinutes(-4));
                }
                if ("1" == val)
                {
                    this.dtprelist[devps[7]] = DateTime.Now;
                }
                //记录数列表
                int sum = Convert.ToInt32(basefun.valtag(msg, "{采集标志}"));
                devrecord.Add(devps[7], sum);
                devinfo.Add(devps[7], devps);
                //检查状态改变则记录
                this.validateSate(lvEatery.Items[i], devps[8], msg);
            }
            foreach (string key in devrecord.Keys)
            {
                if (devrecord[key] < 1 || !this.dtprelist.ContainsKey(key) || !devinfo.ContainsKey(key))
                {
                    continue;
                }
                if (DateTime.Now - this.dtprelist[key] < tspre)
                {
                    continue;
                }
                //在间隔tspre(5分钟)没有工作状态,则可以采集10条记录
                string[] info = devinfo[key];
                for (int i = 0; i < 11; i++)
                {
                    string      tag    = "@设备地址=" + info[7];
                    CommiTarget target = this.getTarget(info);
                    if (null == target)
                    {
                        continue;
                    }
                    if (i < 1)
                    {
                        cmdP.setCommand(tpl, "取当前消费记录", tag);
                    }
                    else
                    {
                        cmdP.setCommand(tpl, "取下一条消费记录", tag);
                    }
                    cmdP.ResetState();
                    CommiManager.GlobalManager.SendCommand(target, cmdP);
                    if (!cmdP.EventWh.WaitOne(300, false))
                    {
                        continue;
                    }
                    string msg = cmdP.ResponseFormat;
                    if ("true" != basefun.valtag(msg, "Success"))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(basefun.valtag(msg, "{卡号}")))
                    {
                        break;
                    }
                    NameObjectList ps = ParamManager.createParam(msg);
                    ps["消费机"] = info[8];
                    bool success = this.Query.ExecuteNonQuery("采集数据", ps, ps, ps);
                    AddEateryStatus(msg);
                    if (!success)
                    {
                        break;
                    }
                }
                break;
            }
            foreach (CommiTarget tar in targetlist)
            {
                CommiManager.GlobalManager.RemoveCommand(tar, cmdP);
            }
            isRunning = false;
        }
コード例 #9
0
ファイル: FrmReadRecord.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// �ɼ���¼
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btPick_Click(object sender, EventArgs e)
        {
            if (null == this.target || string.IsNullOrEmpty(this.deviceID) || string.IsNullOrEmpty(this.deviceName))
                return;
            string tpl = "ͣ����", cmd = "�ռ���һ����¼";
            if (this.rdbRetry.Checked)
                cmd = "�ռ���ǰ��¼";

            CmdProtocol cmdP = new CmdProtocol(this.deviceID, false);
            string tagdata = "@�豸��ַ=" + this.deviceID;
            cmdP.setCommand(tpl, cmd, tagdata);
            cmdP.TimeLimit = new TimeSpan(0, 10, 0);
            cmdP.TimeFailLimit = new TimeSpan(0, 10, 0);
            cmdP.TimeSendInv = new TimeSpan(0, 10, 0);
            target.setProtocol(Protocol.PTLPark);

            this.gdRecord.Rows.Clear();
            DataGridViewColumnCollection cols = this.gdRecord.Columns;
            string msg = "";
            while (string.IsNullOrEmpty(msg))
            {
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(this.target, cmdP);
                if (!cmdP.EventWh.WaitOne(2000, false))
                    msg = "ͨѶʧ��,�����豸���ӻ�ͨѶ���������ԣ�";
                string tag = cmdP.ResponseFormat;
                if (string.IsNullOrEmpty(msg) && string.IsNullOrEmpty(tag))
                    msg = "�ɼ���ɣ�";
                if (!string.IsNullOrEmpty(msg))
                    continue;

                //�ɼ���������
                object[] data = new object[cols.Count];
                for (int i = 0; i < cols.Count; i++)
                {
                    if ("���ƺ���" == cols[i].Name)
                        continue;
                    string val = basefun.valtag(tag, "{" + cols[i].Name + "}");
                    if (string.IsNullOrEmpty(val))
                        val = basefun.valtag(tag, cols[i].Name);
                    if ("����" == cols[i].Name || "����" == cols[i].Name)
                        data[i] = Convert.ToInt32(val);
                    else
                        data[i] = val;
                }
                this.gdRecord.Rows.Add(data);
            }
            CommiManager.GlobalManager.RemoveCommand(this.target, cmdP);
            //���ɲ����б�
            NameObjectList[] psList = new NameObjectList[this.gdRecord.Rows.Count];
            for (int i = 0; i < psList.Length; i++)
            {
                NameObjectList p = new NameObjectList();
                ParamManager.MergeParam(p, this.paramSystem, false);
                DataGridViewRow row = this.gdRecord.Rows[i];
                foreach (DataGridViewColumn c in cols)
                    p[c.Name] = row.Cells[c.Name].Value;
                psList[i] = p;
            }
            int devid = Convert.ToInt32(this.deviceID);
            if (devid < 129)
                this.Query.ExecuteNonQuery("�볡�Ǽ�", psList, psList, psList);
            else
                this.Query.ExecuteNonQuery("�����Ǽ�", psList, psList, psList);
            MessageBox.Show(msg);
        }
コード例 #10
0
ファイル: FrmReadRecord.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// 采集记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btPick_Click(object sender, EventArgs e)
        {
            if (null == this.target || string.IsNullOrEmpty(this.deviceID) || string.IsNullOrEmpty(this.deviceName))
            {
                return;
            }
            string tpl = "停车场", cmd = "收集下一条记录";

            if (this.rdbRetry.Checked)
            {
                cmd = "收集当前记录";
            }

            CmdProtocol cmdP    = new CmdProtocol(this.deviceID, false);
            string      tagdata = "@设备地址=" + this.deviceID;

            cmdP.setCommand(tpl, cmd, tagdata);
            cmdP.TimeLimit     = new TimeSpan(0, 10, 0);
            cmdP.TimeFailLimit = new TimeSpan(0, 10, 0);
            cmdP.TimeSendInv   = new TimeSpan(0, 10, 0);
            target.setProtocol(Protocol.PTLPark);

            this.gdRecord.Rows.Clear();
            DataGridViewColumnCollection cols = this.gdRecord.Columns;
            string msg = "";

            while (string.IsNullOrEmpty(msg))
            {
                cmdP.ResetState();
                CommiManager.GlobalManager.SendCommand(this.target, cmdP);
                if (!cmdP.EventWh.WaitOne(2000, false))
                {
                    msg = "通讯失败,请检查设备连接或通讯参数后重试!";
                }
                string tag = cmdP.ResponseFormat;
                if (string.IsNullOrEmpty(msg) && string.IsNullOrEmpty(tag))
                {
                    msg = "采集完成!";
                }
                if (!string.IsNullOrEmpty(msg))
                {
                    continue;
                }

                //采集加入数据
                object[] data = new object[cols.Count];
                for (int i = 0; i < cols.Count; i++)
                {
                    if ("车牌号码" == cols[i].Name)
                    {
                        continue;
                    }
                    string val = basefun.valtag(tag, "{" + cols[i].Name + "}");
                    if (string.IsNullOrEmpty(val))
                    {
                        val = basefun.valtag(tag, cols[i].Name);
                    }
                    if ("卡类" == cols[i].Name || "车型" == cols[i].Name)
                    {
                        data[i] = Convert.ToInt32(val);
                    }
                    else
                    {
                        data[i] = val;
                    }
                }
                this.gdRecord.Rows.Add(data);
            }
            CommiManager.GlobalManager.RemoveCommand(this.target, cmdP);
            //生成参数列表
            NameObjectList[] psList = new NameObjectList[this.gdRecord.Rows.Count];
            for (int i = 0; i < psList.Length; i++)
            {
                NameObjectList p = new NameObjectList();
                ParamManager.MergeParam(p, this.paramSystem, false);
                DataGridViewRow row = this.gdRecord.Rows[i];
                foreach (DataGridViewColumn c in cols)
                {
                    p[c.Name] = row.Cells[c.Name].Value;
                }
                psList[i] = p;
            }
            int devid = Convert.ToInt32(this.deviceID);

            if (devid < 129)
            {
                this.Query.ExecuteNonQuery("入场登记", psList, psList, psList);
            }
            else
            {
                this.Query.ExecuteNonQuery("出场登记", psList, psList, psList);
            }
            MessageBox.Show(msg);
        }
コード例 #11
0
 /// <summary>
 /// 火警开门
 /// </summary>
 public void FireOpenDoor()
 {
     if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1)
         return;
     if ("考勤机" == this.devtype)
         return;
     CmdProtocol cmdP = new CmdProtocol(false);
     setTimeout(cmdP);
     cmdP.IsResposeHandle = isResponse;
     //设置门参数
     string tag = "@设备地址=" + Convert.ToString(this.station);
     tag = basefun.setvaltag(tag, "{控制方式}", "1");
     tag = basefun.setvaltag(tag, "{延时}", "0");
     //string[,] colmapdoor ={ { "{控制方式}", "1" }, { "{延时}", "0" }, { "{门号}", "门号" } };
     this.reChecking(0);
     for (int i = 1; i < 5; i++)
     {
         tag = basefun.setvaltag(tag, "{门号}", Convert.ToString(i));
         string msg = "";
         Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
         myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
         cmdP.setCommand("门禁", "设置控制参数", tag);
         cmdP.ResetState();
         this.commimgr.SendCommand(this.target, cmdP);
         if (cmdP.EventWh.WaitOne(this.waitTime, false))
             msg = cmdP.ResponseFormat;
         Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
         myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
         msg = "";
         Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
         myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + tag);
         cmdP.setCommand("门禁", "远程开门", tag);
         cmdP.ResetState();
         this.commimgr.SendCommand(this.target, cmdP);
         if (cmdP.EventWh.WaitOne(this.waitTime, false))
             msg = cmdP.ResponseFormat;
         Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
         myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg);
         if (i > 1)
             break;
     }
     this.reChecking(1);
 }