/// <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); }
/// <summary> /// 清空记录,重置记录位置 /// </summary> private void ClearRecord() { //清空记录 CmdProtocol cmdP = new CmdProtocol(false); setTimeout(cmdP); cmdP.IsResposeHandle = isResponse; string tag = "@设备地址=" + Convert.ToString(this.station); cmdP.setCommand("门禁", "清空记录", tag); this.commimgr.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(this.waitTime, false)) { return; } string msg = cmdP.ResponseFormat; if ("true" == basefun.valtag(msg, "Success")) { this.posRecord = 0; NameObjectList pspos = new NameObjectList(); pspos["控制器"] = this.devid; try { Monitor.Enter(objquery); this.query.ExecuteNonQuery("重置记录位置", pspos, pspos, pspos); } finally { Monitor.PulseAll(objquery); Monitor.Exit(objquery); } } }
/// <summary> /// 读取单条白名单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnReadOne_Click(object sender, EventArgs e) { DataTable tab = this.gdValList.DataSource as DataTable; if (tab.Rows.Count < 1) { return; } BindingManagerBase bindmgr = this.BindingContext[tab]; DataRow dr = tab.Rows[bindmgr.Position]; string cardnum = Convert.ToString(dr["卡号"]); if (string.IsNullOrEmpty(cardnum)) { MessageBox.Show("请确定具体卡号!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string tpl = "停车场", cmd = "查询ID白名单"; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; tagdata = basefun.setvaltag(tagdata, "{卡号}", cardnum); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); this.refresh(); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { //cmdP.ResponseFormat MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btOK_Click(object sender, EventArgs e) { //执行指令 string cmd = "管理系统远程闸控制"; string tpl = "停车场"; string tag = Convert.ToString(this.grpFeeItem.Tag); string devid = basefun.valtag(tag, "{设备地址}"); if (string.IsNullOrEmpty(devid) || null == this.target) { MessageBox.Show("当前没有设备"); return; } string tagdata = "@设备地址=" + devid; tagdata = basefun.setvaltag(tagdata, "{道闸命令}", "01"); CmdProtocol cmdP = new CmdProtocol(cmd, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(cmdP.ResponseFormat); } }
/// <summary> /// 读取收费标准 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void QueryBtn_Click(object sender, EventArgs e) { string tagdata = "@设备地址=" + this.deviceID; tagdata = this.getTagdata(this.grpCarType, tagdata); tagdata = this.getTagdata(this.grpFeeType, tagdata); tagdata = this.getTagdata(this.tabFeeStd.SelectedTab, tagdata); string cmd = "读取收费标准" + basefun.valtag(tagdata, "{方式代码}"); string tpl = "停车场"; CmdProtocol cmdP = new CmdProtocol(cmd, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { tagdata = cmdP.ResponseFormat; this.setTagdata(this.grpCarType, tagdata); this.setTagdata(this.Grpfeetp, tagdata); this.setTagdata(this.grpFeeType, tagdata); MessageBox.Show("成功检测出设备数据!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void FrmParkDeposit_Load(object sender, EventArgs e) { this.setContainerTagValue(this.grpInfo, this.tag, "pm"); //直接通讯获取停车费用 if (this.addrst < 0 || null == this.target) { return; } string cardnum = basefun.valtag(this.tag, "卡号"); string cardtype = basefun.valtag(this.tag, "卡类"); string cartype = basefun.valtag(this.tag, "车型"); string dtparkin = basefun.valtag(this.tag, "入场时间"); if (string.IsNullOrEmpty(cardtype) || string.IsNullOrEmpty(cartype) || string.IsNullOrEmpty(dtparkin)) { return; } string data = ""; NameObjectList ps = ParamManager.createParam(this.tag); foreach (string key in ps.AllKeys) { data = basefun.setvaltag(data, "{" + key + "}", Convert.ToString(ps[key])); } data = basefun.setvaltag(data, "设备地址", Convert.ToString(this.addrst)); data = basefun.setvaltag(data, "{设备地址}", Convert.ToString(this.addrst)); string dtparkout = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); data = basefun.setvaltag(data, "{出场时间}", dtparkout); data = basefun.setvaltag(data, "{出入场时间}", dtparkout); data = basefun.setvaltag(data, "{开闸方式}", "00"); this.tag = data; CmdProtocol cmdP = new CmdProtocol(false); cmdP.setCommand("停车场", "计算收费金额", data); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { return; } string money = basefun.valtag(cmdP.ResponseFormat, "{收费金额}"); if (string.IsNullOrEmpty(money)) { return; } this.tbPkmoney.Text = money; this.tag = basefun.setvaltag(this.tag, "{收费金额}", money); string cardmoney = basefun.valtag(this.tag, "{卡片余额}"); try { money = Convert.ToString(Convert.ToDecimal(money) - Convert.ToDecimal(cardmoney)); this.tbPkfee.Text = money; this.tag = basefun.setvaltag(this.tag, "{收费}", money); } catch { } }
/// <summary> /// 启动采集 /// </summary> public override void StartGather() { Debug.WriteLine("111111");; if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1) { return; } if (null != cmdGather) { return; } CmdProtocol cmdg = new CmdProtocol(false); setTimeout(cmdg); cmdg.TimeLimit = TimeSpan.MaxValue; cmdg.TimeFailLimit = TimeSpan.MaxValue; cmdg.FailProAf = FailAftPro.Ignor; cmdg.TimeSendInv = this.tsinv; cmdg.IsResposeHandle = isResponse; this.tagInfos.Clear(); NameObjectList ps = new NameObjectList(); ps["控制器"] = this.devid; Debug.WriteLine("ddddd" + cmdg); DataTable tab = null; try { Monitor.Enter(objquery); tab = this.query.getTable("门禁状态", ps); } finally { Monitor.PulseAll(objquery); Monitor.Exit(objquery); } foreach (DataRow dr in tab.Rows) { if (null == dr || DBNull.Value == dr["类别"]) { continue; } this.tagInfos.Add(Convert.ToString(dr["类别"]), Convert.ToString(dr["内容"])); } string tag = "@设备地址=" + Convert.ToString(this.station); cmdg.setCommand("门禁", "检测状态", tag); cmdg.ResponseHandle += new EventHandler <ResponseEventArgs>(cmdGather_ResponseHandle); cmdg.ResponseHandle += new EventHandler <ResponseEventArgs>(this.execResponse); this.commimgr.SendCommand(this.target, cmdg); cmdGather = cmdg; Debug.WriteLine("sssss" + cmdg); }
/// <summary> /// 切换巡检状态:0/采集记录(暂停巡检),1/巡检 /// </summary> /// <param name="stateChk">巡检类型</param> private void reChecking(int stateChk) { CmdProtocol cmd = this.cmdGather; if (null == cmd) { return; } CmdState st = cmd.CheckState(); cmd.TimeSendInv = new TimeSpan(24, 0, 0); cmd.TimeLimit = new TimeSpan(4 * cmd.TimeOut.Ticks); cmd.TimeFailLimit = cmd.TimeLimit; if (CmdState.Response == st || CmdState.Request == st || CmdState.ReqTimeout == st) { cmd.EventWh.Reset(); cmd.EventWh.WaitOne(cmd.TimeOut, false); } this.commimgr.ClearBuffer(this.target); this.stateChecking = stateChk; string tag = "@设备地址=" + Convert.ToString(this.station); if (1 == stateChk) { cmd.setCommand("门禁", "检测状态", tag); } else { cmd.setCommand(new byte[0]); } if (0 < stateChk) { cmd.TimeSendInv = this.tsinv; cmd.TimeLimit = TimeSpan.MaxValue; cmd.TimeFailLimit = TimeSpan.MaxValue; cmd.FailProAf = FailAftPro.Ignor; cmd.TimeSendInv = this.tsinv; cmd.IsResposeHandle = isResponse; this.commimgr.SendCommand(this.target, cmd); } Debug.WriteLine("巡检类型:" + stateChk); }
/// <summary> /// 清空记录,重置记录位置 /// </summary> private void ClearRecord() { //清空记录 CmdProtocol cmdP = new CmdProtocol(false); setTimeout(cmdP); cmdP.IsResposeHandle = isResponse; string tag = "@设备地址=" + Convert.ToString(this.station); cmdP.setCommand("门禁", "清空记录", tag); this.commimgr.SendCommand(this.target, cmdP); cmdP.EventWh.WaitOne(this.waitTime, false); }
/// <summary> /// 收取停车费用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btFee_Click(object sender, EventArgs e) { //删除设备入场记录,并返回tag模拟的出入场tag标记值 if (null == this.target || this.addrst < 0) { MessageBox.Show("请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string province = this.cbbProvince.Text; if (!string.IsNullOrEmpty(province)) { province = regUperCase.Replace(province, ""); } string carnum = this.tbCarnum.Text; if (!string.IsNullOrEmpty(carnum)) { carnum = province + carnum; } this.tag = basefun.setvaltag(this.tag, "{车牌号码}", carnum); //打印小票 //编号 string code = this.query.ExecuteScalar("打印编号序列号", new NameObjectList()).ToString(); this.tag = basefun.setvaltag(this.tag, "{打印编号}", code); string printer = DataAccRes.AppSettings("收费打印机"); try { if (!string.IsNullOrEmpty(printer)) { this.printFee.PrinterSettings.PrinterName = printer; } this.printFee.Print(); } catch { } //删除设备停车记录,保存出入场记录 CmdProtocol cmdP = new CmdProtocol(false); cmdP.setCommand("停车场", "删除一条停车记录", this.tag); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次 /// </summary> /// <param name="mgr">通讯管理器</param> /// <param name="target">通讯目标</param> /// <param name="cmd">执行指令</param> /// <param name="strcmd">指令名称</param> /// <param name="tag">指令内容</param> /// <param name="timeout">超时间隔</param> /// <returns>返回指令响应结果</returns> private string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, string strcmd, string tag, 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 < 3; i++) { msg = ""; cmd.setCommand("门禁", strcmd, tag); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + strcmd + " " + tag); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + strcmd + " " + tag); mgr.SendCommand(target, cmd, true); this.isexecuting = true; if (cmd.EventWh.WaitOne(timeout, false)) { msg = cmd.ResponseFormat; } this.isexecuting = false; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); string suc = basefun.valtag(msg, "Success"); if (!string.IsNullOrEmpty(suc)) { break; } if (string.IsNullOrEmpty(msg) && CommiType.SerialPort != target.ProtocolType) { Debug.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now)); myLog.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now)); bool pingcn = Ping(target, CNtimeout); Debug.WriteLine(String.Format("{0:HH:mm:ss.fff} Ping 连接 {1}", DateTime.Now, pingcn)); myLog.WriteLine(String.Format("{0:HH:mm:ss.fff} Ping 连接 {1}", DateTime.Now, pingcn)); if (!pingcn) { break; } } } return(msg); }
/// <summary> /// 查询时段代码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnQuery_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个时段", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tpl = "停车场", cmd = "查询有效时段"; string[,] colmap = { { "{时段代码}", "timeid" } }; DataTable tab = this.dsUnit.Tables["park_timese"]; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; string tagdata = "@设备地址=" + this.deviceID; for (int c = 0; c < colmap.GetLength(0); c++) { object val = dr[colmap[c, 1]]; if (true.Equals(val)) { val = "1"; } if (false.Equals(val)) { val = "0"; } tagdata = basefun.setvaltag(tagdata, colmap[c, 0], Convert.ToString(val)); } CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { MessageBox.Show(cmdP.ResponseFormat); } } MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次 /// </summary> /// <param name="mgr">通讯管理器</param> /// <param name="target">通讯目标</param> /// <param name="cmd">执行指令</param> /// <param name="strcmd">指令名称</param> /// <param name="timeout">超时间隔</param> /// <returns>返回指令响应结果</returns> private string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, string strcmd, string tag, TimeSpan timeout) { if (null == mgr || null == target || null == cmd || string.IsNullOrEmpty(strcmd) || string.IsNullOrEmpty(tag)) { return(""); } if (null == cmd.EventWh) { cmd.EventWh = new ManualResetEvent(false); } string msg = ""; for (int i = 0; i < 5; i++) { msg = ""; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 请求:" + strcmd + " " + tag); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 请求:" + strcmd + " " + tag); cmd.setCommand("消费", strcmd, tag); mgr.SendCommand(target, cmd, true); this.isexecuting = true; if (cmd.EventWh.WaitOne(timeout, false)) { msg = cmd.ResponseFormat; } this.isexecuting = false; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); string suc = basefun.valtag(msg, "Success"); if ("true" == suc) { break; } //失败时重新采集当前记录 if ("取下一条消费记录" == strcmd) { strcmd = "取当前消费记录"; } if ("取下一条补助记录" == strcmd) { strcmd = "取当前补助记录"; } Thread.Sleep(200); } return(msg); }
/// <summary> /// 加载系统时间 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetTimeBtn_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string msg = ""; string tpl = "停车场", cmd = "加载系统时间"; DataTable tab = this.dbGrid.DataSource as DataTable; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; CommiTarget target = this.getTarget(dr); CmdProtocol cmdP = new CmdProtocol(Convert.ToString(dr["名称"]), false); string tagdata = "@设备地址=" + Convert.ToString(dr["站址"]); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { msg = cmdP.CmdId + ":通讯失败,请检查设备连接或通讯参数后重试!"; } string rpmsg = basefun.valtag(cmdP.ResponseFormat, "{状态}"); if (string.IsNullOrEmpty(msg) && !string.IsNullOrEmpty(rpmsg) && "操作成功!" != rpmsg) { msg = cmdP.CmdId + ":" + rpmsg; } if (!string.IsNullOrEmpty(msg)) { break; } } if (string.IsNullOrEmpty(msg)) { MessageBox.Show("成功加载系统时间!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(msg, "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void BtnDown_Click_1(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个时段", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tpl = "停车场", cmd = "下载有效时段"; string[,] colmap = { { "{时段编号}", "时段编号" }, { "{开始时间1}", "开始时间1" }, { "{截止时间1}", "截止时间1" }, { "{开始时间2}", "开始时间2" }, { "{截止时间2}", "截止时间2" }, { "{开始日期}", "开始日期" }, { "{截止日期}", "截止日期" }, { "{星期六}", "星期六" }, { "{星期日}", "星期日" } }; DataTable tab = this.dsUnit.Tables["时段设置"]; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; string tagdata = "@设备地址=" + this.deviceID; for (int c = 0; c < colmap.GetLength(0); c++) { object val = dr[colmap[c, 1]]; if (true.Equals(val)) { val = "1"; } if (false.Equals(val)) { val = "0"; } tagdata = basefun.setvaltag(tagdata, colmap[c, 0], Convert.ToString(val)); } cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } MessageBox.Show("下载时段成功!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 删除全部白名单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDelAll_Click(object sender, EventArgs e) { DataTable tab = this.gdValList.DataSource as DataTable; if (tab.Rows.Count < 1) { return; } BindingManagerBase bindmgr = this.BindingContext[tab]; DataRow dr = tab.Rows[bindmgr.Position]; string cardnum = Convert.ToString(dr["卡号"]); string id = Convert.ToString(dr["id"]); if (string.IsNullOrEmpty(cardnum)) { MessageBox.Show("请确定具体卡号!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult result = MessageBox.Show("请确定是否要删除全部白名单?【是】将删除全部白名单,【否】则放弃操作。", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (DialogResult.Yes != result) { return; } string tpl = "停车场", cmd = "初始化ID白名单"; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { deleteAll(id); this.refresh(); MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void FrmQueryState_Load(object sender, EventArgs e) { this.lbInfonew.Text = ""; this.lbDate.Text = ""; this.lbWorker.Text = ""; string tpl = "停车场", cmd = "检测状态"; CmdProtocol cmdP = new CmdProtocol("巡检设备" + this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.cmdP_ResponseHandle(cmdP); } }
/// <summary> /// 执行指令,指令标记在tag属性@pm,@val值 /// </summary> /// <param name="sender">触发指令按钮</param> /// <param name="e"></param> private void btControl_Click(object sender, EventArgs e) { if (null == sender || !(sender is Control)) { return; } string tag = Convert.ToString(((Control)sender).Tag); string pm = basefun.valtag(tag, "pm"); if (string.IsNullOrEmpty(pm)) { return; } string val = basefun.valtag(tag, "val"); if (string.IsNullOrEmpty(val)) { return; } //执行指令 string cmd = "管理系统远程闸控制"; string tpl = "停车场"; string tagdata = "@设备地址=" + this.deviceID; tagdata = basefun.setvaltag(tagdata, "{" + pm + "}", val); CmdProtocol cmdP = new CmdProtocol(cmd, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.cmdP_ResponseHandle(cmdP); } }
private void BtnInit_Click_1(object sender, EventArgs e) { if (DialogResult.Yes != MessageBox.Show("初始化时段清除设备时段设置,确认是否执行?", "设备通讯", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } string tpl = "停车场", cmd = "初始化时段"; CmdProtocol cmdP = new CmdProtocol(false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btOK_Click(object sender, EventArgs e) { //ִ��ָ�� string cmd = "����ϵͳԶ��բ����"; string tpl = "ͣ����"; string tag = Convert.ToString(this.grpFeeItem.Tag); string devid = basefun.valtag(tag, "{�豸��ַ}"); if (string.IsNullOrEmpty(devid) || null == this.target) { MessageBox.Show("��ǰû���豸"); return; } string tagdata = "@�豸��ַ=" + devid; tagdata = basefun.setvaltag(tagdata, "{��բ����}", "01"); CmdProtocol cmdP = new CmdProtocol(cmd, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) MessageBox.Show("ͨѶʧ��,�����豸���ӻ�ͨѶ���������ԣ�", "ͨѶ��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(cmdP.ResponseFormat); }
/// <summary> /// 读取设备控制参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btRead_Click(object sender, EventArgs e) { if (null == this.ds || !this.ds.Tables.Contains("park") || this.ds.Tables["park"].Rows.Count < 1 || !this.ds.Tables["park"].Columns.Contains("dev_id")) { return; } DataTable tab = this.ds.Tables["park"]; BindingManagerBase frmmgr = this.BindingContext[tab]; if (position > 0) { frmmgr.Position = position; } DataRow dr = ((DataRowView)frmmgr.Current).Row; string addr = Convert.ToString(dr["dev_id"]); if (string.IsNullOrEmpty(addr)) { MessageBox.Show("没有维护设备地址,不能通讯!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string tpl = "停车场", cmd = "读取控制参数"; CmdProtocol cmdP = new CmdProtocol("读取控制参数" + addr, false); string tagdata = "@设备地址=" + addr; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.cmdP_ResponseHandle(cmdP); } }
/// <summary> /// 启动采集 /// </summary> public override void StartGather() { if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1) { return; } if (null != cmdGather) { return; } cmdGather = new CmdProtocol(false); cmdGather.TimeLimit = TimeSpan.MaxValue; cmdGather.TimeFailLimit = TimeSpan.MaxValue; cmdGather.FailProAf = FailAftPro.Ignor; cmdGather.TimeSendInv = this.tsinv; this.dtwork = DateTime.Now; this.tagInfos.Clear(); NameObjectList ps = new NameObjectList(); ps["消费机"] = this.devid; DataTable tab = this.query.getTable("消费机状态", ps); foreach (DataRow dr in tab.Rows) { if (null == dr || DBNull.Value == dr["类别"]) { continue; } this.tagInfos.Add(Convert.ToString(dr["类别"]), Convert.ToString(dr["内容"])); } string tag = "@设备地址=" + Convert.ToString(this.station); cmdGather.setCommand("消费", "检测状态", tag); cmdGather.ResponseHandle += new EventHandler <ResponseEventArgs>(cmdGather_ResponseHandle); this.commimgr.SendCommand(this.target, cmdGather); }
/// <summary> /// 写入控制参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btWrite_Click(object sender, EventArgs e) { if (null == this.ds || !this.ds.Tables.Contains("park") || this.ds.Tables["park"].Rows.Count < 1 || !this.ds.Tables["park"].Columns.Contains("dev_id")) { this.Close(); return; } DataTable tab = this.ds.Tables["park"]; BindingManagerBase frmmgr = this.BindingContext[tab]; if (position > 0) frmmgr.Position = position; DataRow dr = ((DataRowView)frmmgr.Current).Row; string addr = Convert.ToString(dr["dev_id"]); if (string.IsNullOrEmpty(addr)) { MessageBox.Show("没有维护设备地址,不能通讯!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string strchk = this.getCheckedsgrp(this.grpbChannel, "通道选择内容"); dr["通道选择内容"] = strchk; strchk = this.getCheckedsgrp(this.grpbCardType, "卡类允许"); dr["卡类允许"] = strchk; strchk = this.getCheckedsgrp(this.grpbAccept, "放行控制"); dr["放行控制"] = strchk; //@{出卡机欠量报警门限}=0,@{总车位数}=1000,@{脱机时间}.{脱机处理}=1,@{脱机时间}.{脱机时间}=25, //@{临时卡出卡选择}.{车型}=C,@{临时卡出卡选择}.{方式}=1,@{货币单位}=01,@{入口满位处理}.{入场}=0,@{入口满位处理}.{临时卡}=0, //@{外设配置}=00011001,@{放行控制}=00101001,@{场内场逻辑控制}=aa,@{车位占用卡处理}=01010000, //@{卡类允许}=11111111,@{通道选择}=00000110,@{有效期报警门限}=20,@{卡余额报警门警}=30, //@{中央收费}.{中央收费}=1,@{中央收费}.{有效时间}=30,@{进出逻辑控制}=AA,@{灯饰设置}.{h1}=10, //@{灯饰设置}.{m1}=30,@{灯饰设置}.{h2}=08,@{灯饰设置}.{m2}=30,@{保留车位}=10,@{场内场编号}=10,@{卡片使用区}=7,@{最高余额}=65535,@{最低余额}=20 //@{帧头}=02,@{设备地址}=1,@{状态}=操作成功!,@{命令长度}=0040,@{本机地址}=1,@{系统标识符}=2102803,@{通信密码}=0,@{系统密码}=0, //@{用户密码}=1467233176,@{出卡机欠量报警门限}=0,@{总车位数}=0,@脱机处理=1,@脱机时间=80,@车型=0,@方式=6,@{货币单位}=0A, //@{入口满位处理}=00000000,@{外设配置}=10100100,@{放行控制}=00010100,@{场内场逻辑控制}=3,@{车位占用卡处理}=00010000,@{卡类允许}=11111111, //@{通道选择}=00001100,@{有效期报警门限}=30,@{卡余额报警门警}=80,@中央收费=0,@有效时间=0,@{进出逻辑控制}=AA,@灯1=00:00,@灯2=00:00, //@{保留车位}=0,@{场内场编号}=0,@{卡片使用区}=7,@{最高余额}=0,@{最低余额}=0,@{保留字}=0,@{校验字}=82,@{帧尾}=03 string[,] colmap ={ { "{有效期报警门限}", "有效报警" }, { "{卡余额报警门警}", "卡余额报警" },{"{总车位数}","allstall"}, { "{场内场逻辑控制}", "内场逻辑" }, {"{脱机时间}.{脱机处理}","脱机"},{"{脱机时间}.{脱机时间}","脱机时间"}, {"{车位占用卡处理}","车位占用处理"}, {"{临时卡出卡选择}.{方式}","临时卡方式"}, {"{场内场逻辑控制}","内场逻辑"}, {"{中央收费}.{中央收费}","中央收费"}, {"{中央收费}.{有效时间}","有效时间"}, {"{入口满位处理}.{入场}", "满位允许" }, { "{入口满位处理}.{临时卡}", "满位临时卡" } }; string tagdata = "@设备地址=" + addr; tagdata = basefun.setvaltag(tagdata, "{货币单位}", "01"); tagdata = basefun.setvaltag(tagdata, "{卡片使用区}", "7"); for (int i = 0; i < colmap.GetLength(0); i++) { string val = Convert.ToString(dr[colmap[i, 1]]); if (true.Equals(dr[colmap[i, 1]])) val = "1"; if (false.Equals(dr[colmap[i, 1]])) val = "0"; if ("1" == val && ("满位允许" == colmap[i, 1] || "满位临时卡" == colmap[i, 1])) val = "10"; tagdata = basefun.setvaltag(tagdata, colmap[i, 0], val); } string v = Convert.ToString(dr["按键默认车型"]); tagdata = basefun.setvaltag(tagdata, "{临时卡出卡选择}.{车型}", Convert.ToString(Convert.ToInt64(v, 16))); if (true.Equals(dr["进出逻辑控制"])) tagdata = basefun.setvaltag(tagdata, "{进出逻辑控制}", "AA"); else tagdata = basefun.setvaltag(tagdata, "{进出逻辑控制}", "86"); v = Convert.ToString(dr["灯饰设置s"]) + ":" + Convert.ToString(dr["灯饰设置e"]); string[] vals = v.Split(":".ToCharArray(), 4); if (4 != vals.Length) vals = new string[] { "00", "00", "00", "00" }; string[] cols ={ "{灯饰设置}.{h1}", "{灯饰设置}.{m1}", "{灯饰设置}.{h2}", "{灯饰设置}.{m2}" }; for (int i = 0; i < cols.Length; i++) tagdata = basefun.setvaltag(tagdata, cols[i], vals[i]); cols = new string[] { "地感", "车位屏", "中文屏1", "中文屏2", "读头1", "读头2" }; v = ""; for (int i = 0; i < cols.Length; i++) v += true.Equals(dr[cols[i]]) ? "1" : "0"; tagdata = basefun.setvaltag(tagdata, "{外设配置}", v + "00"); string valk = ""; colmap = new string[,] { { "{放行控制}", "放行控制" }, { "{卡类允许}", "卡类允许" } }; for (int k = 0; k < colmap.GetLength(0); k++) { valk = "," + Convert.ToString(dr[colmap[k, 1]]) + ","; v = ""; for (int i = 0; i < 8; i++) { if (valk.Contains("," + Convert.ToString(i + 3) + ",")) v = "1" + v; else v = "0" + v; } tagdata = basefun.setvaltag(tagdata, colmap[k, 0], v); } valk = "," + Convert.ToString(dr["通道选择内容"]) + ","; v = ""; if (true.Equals(dr["通道选择类型"])) cols = new string[] { "3", "4", "6", "8", "9", "10" }; else cols = new string[] { "1", "2", "3", "4" }; for (int i = 0; i < cols.Length; i++) if (valk.Contains("," + cols[i] + ",")) v += "1"; else v += "0"; if (true.Equals(dr["通道选择类型"])) v = "10" + v; else v = "0000" + v; tagdata = basefun.setvaltag(tagdata, "{通道选择}", v); string tpl = "停车场", cmd = "下载控制参数"; CmdProtocol cmdP = new CmdProtocol(addr, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else this.cmdP_ResponseWritedHandle(cmdP); }
/// <summary> /// 写入控制参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btWrite_Click(object sender, EventArgs e) { if (null == this.ds || !this.ds.Tables.Contains("park") || this.ds.Tables["park"].Rows.Count < 1 || !this.ds.Tables["park"].Columns.Contains("dev_id")) { this.Close(); return; } DataTable tab = this.ds.Tables["park"]; BindingManagerBase frmmgr = this.BindingContext[tab]; if (position > 0) { frmmgr.Position = position; } DataRow dr = ((DataRowView)frmmgr.Current).Row; string addr = Convert.ToString(dr["dev_id"]); if (string.IsNullOrEmpty(addr)) { MessageBox.Show("没有维护设备地址,不能通讯!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string strchk = this.getCheckedsgrp(this.grpbChannel, "通道选择内容"); dr["通道选择内容"] = strchk; strchk = this.getCheckedsgrp(this.grpbCardType, "卡类允许"); dr["卡类允许"] = strchk; strchk = this.getCheckedsgrp(this.grpbAccept, "放行控制"); dr["放行控制"] = strchk; //@{出卡机欠量报警门限}=0,@{总车位数}=1000,@{脱机时间}.{脱机处理}=1,@{脱机时间}.{脱机时间}=25, //@{临时卡出卡选择}.{车型}=C,@{临时卡出卡选择}.{方式}=1,@{货币单位}=01,@{入口满位处理}.{入场}=0,@{入口满位处理}.{临时卡}=0, //@{外设配置}=00011001,@{放行控制}=00101001,@{场内场逻辑控制}=aa,@{车位占用卡处理}=01010000, //@{卡类允许}=11111111,@{通道选择}=00000110,@{有效期报警门限}=20,@{卡余额报警门警}=30, //@{中央收费}.{中央收费}=1,@{中央收费}.{有效时间}=30,@{进出逻辑控制}=AA,@{灯饰设置}.{h1}=10, //@{灯饰设置}.{m1}=30,@{灯饰设置}.{h2}=08,@{灯饰设置}.{m2}=30,@{保留车位}=10,@{场内场编号}=10,@{卡片使用区}=7,@{最高余额}=65535,@{最低余额}=20 //@{帧头}=02,@{设备地址}=1,@{状态}=操作成功!,@{命令长度}=0040,@{本机地址}=1,@{系统标识符}=2102803,@{通信密码}=0,@{系统密码}=0, //@{用户密码}=1467233176,@{出卡机欠量报警门限}=0,@{总车位数}=0,@脱机处理=1,@脱机时间=80,@车型=0,@方式=6,@{货币单位}=0A, //@{入口满位处理}=00000000,@{外设配置}=10100100,@{放行控制}=00010100,@{场内场逻辑控制}=3,@{车位占用卡处理}=00010000,@{卡类允许}=11111111, //@{通道选择}=00001100,@{有效期报警门限}=30,@{卡余额报警门警}=80,@中央收费=0,@有效时间=0,@{进出逻辑控制}=AA,@灯1=00:00,@灯2=00:00, //@{保留车位}=0,@{场内场编号}=0,@{卡片使用区}=7,@{最高余额}=0,@{最低余额}=0,@{保留字}=0,@{校验字}=82,@{帧尾}=03 string[,] colmap = { { "{有效期报警门限}", "有效报警" }, { "{卡余额报警门警}", "卡余额报警" }, { "{总车位数}", "allstall" }, { "{场内场逻辑控制}", "内场逻辑" }, { "{脱机时间}.{脱机处理}", "脱机" }, { "{脱机时间}.{脱机时间}", "脱机时间" },{ "{车位占用卡处理}", "车位占用处理" }, { "{临时卡出卡选择}.{方式}", "临时卡方式" }, { "{场内场逻辑控制}", "内场逻辑" }, { "{中央收费}.{中央收费}", "中央收费" }, { "{中央收费}.{有效时间}", "有效时间" }, { "{入口满位处理}.{入场}", "满位允许" }, { "{入口满位处理}.{临时卡}", "满位临时卡" } }; string tagdata = "@设备地址=" + addr; tagdata = basefun.setvaltag(tagdata, "{货币单位}", "01"); tagdata = basefun.setvaltag(tagdata, "{卡片使用区}", "7"); for (int i = 0; i < colmap.GetLength(0); i++) { string val = Convert.ToString(dr[colmap[i, 1]]); if (true.Equals(dr[colmap[i, 1]])) { val = "1"; } if (false.Equals(dr[colmap[i, 1]])) { val = "0"; } if ("1" == val && ("满位允许" == colmap[i, 1] || "满位临时卡" == colmap[i, 1])) { val = "10"; } tagdata = basefun.setvaltag(tagdata, colmap[i, 0], val); } string v = Convert.ToString(dr["按键默认车型"]); tagdata = basefun.setvaltag(tagdata, "{临时卡出卡选择}.{车型}", Convert.ToString(Convert.ToInt64(v, 16))); if (true.Equals(dr["进出逻辑控制"])) { tagdata = basefun.setvaltag(tagdata, "{进出逻辑控制}", "AA"); } else { tagdata = basefun.setvaltag(tagdata, "{进出逻辑控制}", "86"); } v = Convert.ToString(dr["灯饰设置s"]) + ":" + Convert.ToString(dr["灯饰设置e"]); string[] vals = v.Split(":".ToCharArray(), 4); if (4 != vals.Length) { vals = new string[] { "00", "00", "00", "00" } } ; string[] cols = { "{灯饰设置}.{h1}", "{灯饰设置}.{m1}", "{灯饰设置}.{h2}", "{灯饰设置}.{m2}" }; for (int i = 0; i < cols.Length; i++) { tagdata = basefun.setvaltag(tagdata, cols[i], vals[i]); } cols = new string[] { "地感", "车位屏", "中文屏1", "中文屏2", "读头1", "读头2" }; v = ""; for (int i = 0; i < cols.Length; i++) { v += true.Equals(dr[cols[i]]) ? "1" : "0"; } tagdata = basefun.setvaltag(tagdata, "{外设配置}", v + "00"); string valk = ""; colmap = new string[, ] { { "{放行控制}", "放行控制" }, { "{卡类允许}", "卡类允许" } }; for (int k = 0; k < colmap.GetLength(0); k++) { valk = "," + Convert.ToString(dr[colmap[k, 1]]) + ","; v = ""; for (int i = 0; i < 8; i++) { if (valk.Contains("," + Convert.ToString(i + 3) + ",")) { v = "1" + v; } else { v = "0" + v; } } tagdata = basefun.setvaltag(tagdata, colmap[k, 0], v); } valk = "," + Convert.ToString(dr["通道选择内容"]) + ","; v = ""; if (true.Equals(dr["通道选择类型"])) { cols = new string[] { "3", "4", "6", "8", "9", "10" } } ; else { cols = new string[] { "1", "2", "3", "4" } }; for (int i = 0; i < cols.Length; i++) { if (valk.Contains("," + cols[i] + ",")) { v += "1"; } else { v += "0"; } } if (true.Equals(dr["通道选择类型"])) { v = "10" + v; } else { v = "0000" + v; } tagdata = basefun.setvaltag(tagdata, "{通道选择}", v); string tpl = "停车场", cmd = "下载控制参数"; CmdProtocol cmdP = new CmdProtocol(addr, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) { MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.cmdP_ResponseWritedHandle(cmdP); } }
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; }
/// <summary> /// 监控停车场设备 /// </summary> private void Monitor() { IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName()); string ipstr = ","; foreach (IPAddress ip in IpEntry.AddressList) ipstr += ip + ","; string tpl = "停车场", cmd = "收集下一条记录"; foreach (DataGridViewRow dr in this.gdGrid.Rows) { string devname = Convert.ToString(dr.Cells["设备名称"].Value); string ipaddr = Convert.ToString(dr.Cells["IP地址"].Value); string devicetype = Convert.ToString(dr.Cells["设备类型"].Value); string commitype = Convert.ToString(dr.Cells["通讯类别"].Value); string port = Convert.ToString(dr.Cells["端口"].Value); string addrst = Convert.ToString(dr.Cells["通讯站址"].Value); //车牌监控 if ("车牌识别器" == devicetype && this.hvWatchs.Count < this.picWatchs.Count / 2) { HvCarWatch hv = new HvCarWatch(); string msg = hv.HVdiscern.Open(ipaddr); if (!string.IsNullOrEmpty(msg)) continue; hv.dslast = DateTime.Now; this.hvWatchs.Add(devname, hv); this.hvDevices.Add(devname); string info = basefun.setvaltag("", "devname", devname); info = basefun.setvaltag(info, "ipaddr", ipaddr); this.picWatchs[this.indexWatch * 2].lbHv.Text = "入口:" + devname; this.picWatchs[this.indexWatch * 2].lbHv.Enabled = true; this.picWatchs[this.indexWatch * 2].lbHv.Checked = true; this.picWatchs[this.indexWatch * 2].lbHv.Tag = info; this.picWatchs[this.indexWatch * 2 + 1].lbHv.Text = "出口:" + devname; this.picWatchs[this.indexWatch * 2 + 1].lbHv.Enabled = true; this.picWatchs[this.indexWatch * 2 + 1].lbHv.Checked = true; this.picWatchs[this.indexWatch * 2 + 1].lbHv.Tag = info; this.indexWatch++; continue; } if ("停车场验票机" != devicetype || string.IsNullOrEmpty(ipaddr)) continue; if ("Ser" == commitype && !ipstr.Contains(ipaddr)) continue; if (string.IsNullOrEmpty(addrst)) continue; //设置命令定时采集通讯 CommiTarget target = null; if ("Ser" == commitype) target = new CommiTarget(port, 19200); if ("UDP" == commitype) target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.UDP); if ("TCP" == commitype) target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.TCP); int addrdev = Convert.ToInt16(addrst); if (addrdev < 129) this.devNumIn = addrst; else this.devNumOut = addrst; string tagdata = "@设备地址=" + addrst; CmdProtocol cmdP = new CmdProtocol(devname + "(" + addrst + ")"); cmdP.setCommand(tpl, cmd, tagdata); cmdP.Tag = tagdata; target.setProtocol(Protocol.PTLPark); //持续间隔发送通过监听发现接收数据不正确 cmdP.TimeFailLimit = TimeSpan.MaxValue; cmdP.TimeLimit = TimeSpan.MaxValue; cmdP.TimeSendInv = new TimeSpan(0, 0, 1); //改为接收响应后再发起指令的方式 this.target = target; cmdP.ResponseHandle += new EventHandler<ResponseEventArgs>(cmdP_ResponseHandle); CommiManager.GlobalManager.SendCommand(target, cmdP); this.cmdDevs.Add(cmdP); } }
/// <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); }
private void BtnInit_Click_1(object sender, EventArgs e) { if (DialogResult.Yes != MessageBox.Show("初始化时段清除设备时段设置,确认是否执行?", "设备通讯", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) return; string tpl = "停车场", cmd = "初始化时段"; CmdProtocol cmdP = new CmdProtocol(false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 删除全部白名单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDelAll_Click(object sender, EventArgs e) { DataTable tab = this.gdValList.DataSource as DataTable; if (tab.Rows.Count < 1) return; BindingManagerBase bindmgr = this.BindingContext[tab]; DataRow dr = tab.Rows[bindmgr.Position]; string cardnum = Convert.ToString(dr["卡号"]); string id = Convert.ToString(dr["id"]); if (string.IsNullOrEmpty(cardnum)) { MessageBox.Show("请确定具体卡号!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult result = MessageBox.Show("请确定是否要删除全部白名单?【是】将删除全部白名单,【否】则放弃操作。", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (DialogResult.Yes != result) return; string tpl = "停车场", cmd = "初始化ID白名单"; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { deleteAll(id); this.refresh(); MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 初始化硬件设备 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InitBtn_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (DialogResult.Yes != MessageBox.Show("初始化设备会清空设备存储的数据,是否确认需要初始化!", "设备初始化", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) return; string strdevIDs = "", msg = "", strdevNames = ""; string tpl = "停车场", cmd = "格式化"; DataTable tab = this.dbGrid.DataSource as DataTable; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; CommiTarget target = this.getTarget(dr); CmdProtocol cmdP = new CmdProtocol(Convert.ToString(dr["名称"]), false); string devid = Convert.ToString(dr["站址"]); string tagdata = "@设备地址=" + devid; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) msg = cmdP.CmdId + ":通讯失败,请检查设备连接或通讯参数后重试!"; string rpmsg = basefun.valtag(cmdP.ResponseFormat, "{状态}"); if (string.IsNullOrEmpty(msg) && !string.IsNullOrEmpty(rpmsg) && "操作成功!" != rpmsg) msg = cmdP.CmdId + ":" + rpmsg; if (!string.IsNullOrEmpty(msg)) break; strdevIDs += "," + devid; strdevNames += cmdP.CmdId + ","; } //形成参数 string[] devids = strdevIDs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); NameObjectList[] psList = new NameObjectList[devids.Length]; for (int i = 0; i < devids.Length; i++) { psList[i] = new NameObjectList(); psList[i]["devID"] = devids[i]; } QueryDataRes query = new QueryDataRes(this.unitItem.DataSrcFile); if (psList.Length > 0) query.ExecuteNonQuery("删除设备白名单", psList, psList, psList); if (string.IsNullOrEmpty(msg)) MessageBox.Show("设备初始化成功!", "设备初始化", MessageBoxButtons.OK, MessageBoxIcon.Information); else { msg = string.IsNullOrEmpty(strdevNames) ? msg : strdevNames + "成功执行初始化,\r\n" + msg; MessageBox.Show(msg, "设备初始化", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// 初始化硬件设备 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InitBtn_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (DialogResult.Yes != MessageBox.Show("初始化设备会清空设备存储的数据,是否确认需要初始化!", "设备初始化", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { return; } string strdevIDs = "", msg = "", strdevNames = ""; string tpl = "停车场", cmd = "格式化"; DataTable tab = this.dbGrid.DataSource as DataTable; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; CommiTarget target = this.getTarget(dr); CmdProtocol cmdP = new CmdProtocol(Convert.ToString(dr["名称"]), false); string devid = Convert.ToString(dr["站址"]); string tagdata = "@设备地址=" + devid; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { msg = cmdP.CmdId + ":通讯失败,请检查设备连接或通讯参数后重试!"; } string rpmsg = basefun.valtag(cmdP.ResponseFormat, "{状态}"); if (string.IsNullOrEmpty(msg) && !string.IsNullOrEmpty(rpmsg) && "操作成功!" != rpmsg) { msg = cmdP.CmdId + ":" + rpmsg; } if (!string.IsNullOrEmpty(msg)) { break; } strdevIDs += "," + devid; strdevNames += cmdP.CmdId + ","; } //形成参数 string[] devids = strdevIDs.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); NameObjectList[] psList = new NameObjectList[devids.Length]; for (int i = 0; i < devids.Length; i++) { psList[i] = new NameObjectList(); psList[i]["devID"] = devids[i]; } QueryDataRes query = new QueryDataRes(this.unitItem.DataSrcFile); if (psList.Length > 0) { query.ExecuteNonQuery("删除设备白名单", psList, psList, psList); } if (string.IsNullOrEmpty(msg)) { MessageBox.Show("设备初始化成功!", "设备初始化", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { msg = string.IsNullOrEmpty(strdevNames) ? msg : strdevNames + "成功执行初始化,\r\n" + msg; MessageBox.Show(msg, "设备初始化", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
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; }
/// <summary> /// 监控停车场设备 /// </summary> private void Monitor() { IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName()); string ipstr = ","; foreach (IPAddress ip in IpEntry.AddressList) { ipstr += ip + ","; } string tpl = "停车场", cmd = "收集下一条记录"; foreach (DataGridViewRow dr in this.gdGrid.Rows) { string devname = Convert.ToString(dr.Cells["设备名称"].Value); string ipaddr = Convert.ToString(dr.Cells["IP地址"].Value); string devicetype = Convert.ToString(dr.Cells["设备类型"].Value); string commitype = Convert.ToString(dr.Cells["通讯类别"].Value); string port = Convert.ToString(dr.Cells["端口"].Value); string addrst = Convert.ToString(dr.Cells["通讯站址"].Value); if ("停车场验票机" != devicetype || string.IsNullOrEmpty(ipaddr)) { continue; } if ("Ser" == commitype && !ipstr.Contains(ipaddr)) { continue; } if (string.IsNullOrEmpty(addrst)) { continue; } //设置命令定时采集通讯 CommiTarget target = null; if ("Ser" == commitype) { target = new CommiTarget(port, 19200); } if ("UDP" == commitype) { target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.UDP); } if ("TCP" == commitype) { target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.TCP); } string tagdata = "@设备地址=" + addrst; CmdProtocol cmdP = new CmdProtocol(devname + "(" + addrst + ")"); cmdP.setCommand(tpl, cmd, tagdata); target.setProtocol(Protocol.PTLPark); //持续间隔发送通过监听发现接收数据不正确 cmdP.TimeFailLimit = TimeSpan.MaxValue; cmdP.TimeLimit = TimeSpan.MaxValue; cmdP.TimeSendInv = new TimeSpan(0, 0, 1); //改为接收响应后再发起指令的方式 this.target = target; cmdP.ResponseHandle += new EventHandler <ResponseEventArgs>(cmdP_ResponseHandle); CommiManager.GlobalManager.SendCommand(target, cmdP); } }
/// <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); }
/// <summary> /// 监控停车场设备 /// </summary> private void Monitor() { IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName()); string ipstr = ","; foreach (IPAddress ip in IpEntry.AddressList) ipstr += ip + ","; string tpl = "停车场", cmd = "检测状态"; foreach (DataGridViewRow dr in this.gdDevice.Rows) { string devicetype = Convert.ToString(dr.Cells["设备类型"].Value); string devname = Convert.ToString(dr.Cells["设备名称"].Value); string port = Convert.ToString(dr.Cells["串口"].Value); int baudrate = Convert.ToInt32(dr.Cells["波特率"].Value); CommiTarget target = this.getTarget(dr.Cells); string addrst = Convert.ToString(dr.Cells["通讯站址"].Value); int addrdev = Convert.ToInt16(addrst); string tagdata = "@设备地址=" + addrst; if (this.targets.ContainsKey(addrst.ToString())) continue; if ("发行器" == devicetype) { Parity parity = Parity.None; int databits = 8; StopBits stopbits = StopBits.One; CommiTarget targetRead = new CommiTarget(port, baudrate, parity, databits, stopbits); bool success = this.cmdCard.SetTarget(targetRead, Convert.ToInt32(addrst), false); continue; } CmdProtocol cmdP = new CmdProtocol(devname + "(" + addrst + ")"); cmdP.EventWh = new ManualResetEvent(false); //停车场 if (addrdev < 129) this.devNumIn = addrst; else this.devNumOut = addrst; cmdP.setCommand(tpl, cmd, tagdata); cmdP.ResponseHandle += new EventHandler<ResponseEventArgs>(cmdP_ResponseHandle); cmdP.Tag = tagdata; //持续间隔发送通过监听发现是否有新纪录 cmdP.TimeFailLimit = TimeSpan.MaxValue; cmdP.TimeLimit = TimeSpan.MaxValue; cmdP.TimeSendInv = new TimeSpan(0, 0, 1); //Billy Debug CommiManager.GlobalManager.SendCommand(target, cmdP); this.targets.Add(addrst, target); //Billy Debug this.cmdDevs.Add(cmdP); } }
/// <summary> /// 停车场有刷卡,读取卡信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void cmdP_ResponseHandle(object sender, ResponseEventArgs e) { CmdProtocol cmd = sender as CmdProtocol; if ("结束" == this.tagData || null == cmd) return; CommiTarget commipm = e.Target; string tag = cmd.ResponseFormat; Debug.WriteLine("返回:" + tag); string ErrorInfo = CommErrorInfo(tag); string station = basefun.valtag(Convert.ToString(cmd.Tag), "设备地址"); switch (commipm.ProtocolType) { case CommiType.TCP: case CommiType.UDP: string ip = commipm.SrvEndPoint.ToString(); error[ip] = "通讯正常"; if (!string.IsNullOrEmpty(ErrorInfo)) error[ip] = ErrorInfo; break; case CommiType.SerialPort: string portname = commipm.PortName + ":" + station; error[portname] = string.IsNullOrEmpty(ErrorInfo) ? "通讯正常" : ErrorInfo; break; } string recordCount = basefun.valtag(tag, "{新记录}"); if (recordCount == "0" || string.IsNullOrEmpty(recordCount)) return; string cardnum = ""; CardMoney = cardnum; if ("0" != recordCount) { // Thread.Sleep(200); string tpl = "停车场", cmdNextName = "收集下一条记录"; CmdProtocol cmdNext = new CmdProtocol(false); tag = basefun.setvaltag(tag, "设备地址", station); cmdNext.setCommand(tpl, cmdNextName, tag); CommiManager.GlobalManager.SendCommand(e.Target, cmdNext); if (cmdNext.EventWh.WaitOne(800, false)) { tag = cmdNext.ResponseFormat; tag = basefun.setvaltag(tag, "操作类别", "进出场管理"); tag = basefun.setvaltag(tag, "设备名称", cmd.CmdId); cardnum = basefun.valtag(tag, "{卡号}"); string carnum = basefun.valtag(tag, "{车牌号码}"); if (string.IsNullOrEmpty(carnum.Replace("0", ""))) tag = basefun.setvaltag(tag, "{车牌号码}", ""); } } NameObjectList ps = new NameObjectList(); ps["卡号"] = cardnum; Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "卡号" + cardnum); //用Query处理异常 // DataTable tab = this.Query.getTable("获得卡信息", ps); DataTable tab = getDate(cardnum); if (null == tab || tab.Rows.Count < 1) return; Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "tab记录" + tab.TableName); DataRow dr = tab.Rows[0]; foreach (DataColumn c in tab.Columns) { string fld = c.ColumnName; string val = basefun.valtag(tag, "{" + fld + "}"); string val2 = basefun.valtag(tag, fld); if (string.IsNullOrEmpty(val) && !string.IsNullOrEmpty(val2)) basefun.setvaltag(tag, "{" + fld + "}", val2); if (!string.IsNullOrEmpty(val) || !string.IsNullOrEmpty(val2)) continue; val = Convert.ToString(dr[c]); if (string.IsNullOrEmpty(val)) continue; tag = basefun.setvaltag(tag, "{" + fld + "}", val); } string strNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (string.IsNullOrEmpty(basefun.valtag(tag, "{入场时间}"))) tag = basefun.setvaltag(tag, "{入场时间}", strNow); if (string.IsNullOrEmpty(basefun.valtag(tag, "{出入场时间}"))) tag = basefun.setvaltag(tag, "{出入场时间}", strNow); if (string.IsNullOrEmpty(basefun.valtag(tag, "{出场时间}"))) tag = basefun.setvaltag(tag, "{出场时间}", basefun.valtag(tag, "{出入场时间}")); tag = basefun.setvaltag(tag, "操作类别", "进出场管理"); tagData = tag; }
private void BtnDown_Click_1(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个时段", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tpl = "停车场", cmd = "下载有效时段"; string[,] colmap ={ { "{时段编号}", "时段编号" }, { "{开始时间1}", "开始时间1" }, { "{截止时间1}", "截止时间1" }, { "{开始时间2}", "开始时间2" }, { "{截止时间2}", "截止时间2" }, { "{开始日期}", "开始日期" }, { "{截止日期}", "截止日期" }, { "{星期六}", "星期六" }, { "{星期日}", "星期日" } }; DataTable tab = this.dsUnit.Tables["时段设置"]; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; string tagdata = "@设备地址=" + this.deviceID; for (int c = 0; c < colmap.GetLength(0); c++) { object val = dr[colmap[c, 1]]; if (true.Equals(val)) val = "1"; if (false.Equals(val)) val = "0"; tagdata = basefun.setvaltag(tagdata, colmap[c, 0], Convert.ToString(val)); } cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } MessageBox.Show("下载时段成功!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); }
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; }
/// <summary> /// 执行指令; 指令执行失败时,会重新执行一次 /// </summary> /// <param name="ptl">协议</param> /// <param name="cmd">指令</param> /// <param name="tag">指令需要数据</param> /// <param name="devid">设备地址</param> /// <returns>true false</returns> private bool CmdExecute(string ptl, string cmd, string tag, string devid) { bool success = false; CmdProtocol cmdOpenP = new CmdProtocol(cmd, false); tag = basefun.setvaltag(tag, "设备地址", devid); cmdOpenP.setCommand(ptl, cmd, tag); CommiManager.GlobalManager.SendCommand(this.targets[devid], cmdOpenP); success = cmdOpenP.EventWh.WaitOne(1000, false); return success; }
/// <summary> /// 读取单条白名单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnReadOne_Click(object sender, EventArgs e) { DataTable tab = this.gdValList.DataSource as DataTable; if (tab.Rows.Count < 1) return; BindingManagerBase bindmgr = this.BindingContext[tab]; DataRow dr = tab.Rows[bindmgr.Position]; string cardnum = Convert.ToString(dr["卡号"]); if (string.IsNullOrEmpty(cardnum)) { MessageBox.Show("请确定具体卡号!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string tpl = "停车场", cmd = "查询ID白名单"; CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; tagdata = basefun.setvaltag(tagdata, "{卡号}", cardnum); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); this.refresh(); if (!cmdP.EventWh.WaitOne(2000, false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { //cmdP.ResponseFormat MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次 /// </summary> /// <param name="mgr">通讯管理器</param> /// <param name="target">通讯目标</param> /// <param name="cmd">执行指令</param> /// <param name="strcmd">指令名称</param> /// <param name="tag">指令内容</param> /// <param name="timeout">超时间隔</param> /// <returns>返回指令响应结果</returns> private string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, string strcmd, string tag, 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 < 3; i++) { msg = ""; cmd.setCommand("门禁", strcmd, tag); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + strcmd + " " + tag); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 指令:" + strcmd + " " + tag); mgr.SendCommand(target, cmd, true); this.isexecuting = true; if (cmd.EventWh.WaitOne(timeout, false)) msg = cmd.ResponseFormat; this.isexecuting = false; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); string suc = basefun.valtag(msg, "Success"); if (!string.IsNullOrEmpty(suc)) break; if (string.IsNullOrEmpty(msg) && CommiType.SerialPort != target.ProtocolType) { Debug.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now)); myLog.WriteLine(String.Format("{0:HH:mm:ss.fff} 测试网络连接...", DateTime.Now)); bool pingcn = Ping(target, CNtimeout); Debug.WriteLine(String.Format("{0:HH:mm:ss.fff} Ping 连接 {1}", DateTime.Now, pingcn)); myLog.WriteLine(String.Format("{0:HH:mm:ss.fff} Ping 连接 {1}", DateTime.Now, pingcn)); if (!pingcn) break; } } return msg; }
/// <summary> /// 加载系统时间 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetTimeBtn_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择设备", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string msg = ""; string tpl = "停车场", cmd = "加载系统时间"; DataTable tab = this.dbGrid.DataSource as DataTable; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; CommiTarget target = this.getTarget(dr); CmdProtocol cmdP = new CmdProtocol(Convert.ToString(dr["名称"]), false); string tagdata = "@设备地址=" + Convert.ToString(dr["站址"]); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) msg = cmdP.CmdId + ":通讯失败,请检查设备连接或通讯参数后重试!"; string rpmsg = basefun.valtag(cmdP.ResponseFormat, "{状态}"); if (string.IsNullOrEmpty(msg) && !string.IsNullOrEmpty(rpmsg) && "操作成功!" != rpmsg) msg = cmdP.CmdId + ":" + rpmsg; if (!string.IsNullOrEmpty(msg)) break; } if (string.IsNullOrEmpty(msg)) MessageBox.Show("成功加载系统时间!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(msg, "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
/// <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); }
/// <summary> /// 查询时段代码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnQuery_Click(object sender, EventArgs e) { int[] indexlist = this.getCheckedList(); if (indexlist.Length < 1) { MessageBox.Show("请选择一个时段", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string tpl = "停车场", cmd = "查询有效时段"; string[,] colmap ={ { "{时段代码}", "timeid" } }; DataTable tab = this.dsUnit.Tables["park_timese"]; foreach (int i in indexlist) { DataRow dr = tab.Rows[i]; string tagdata = "@设备地址=" + this.deviceID; for (int c = 0; c < colmap.GetLength(0); c++) { object val = dr[colmap[c, 1]]; if (true.Equals(val)) val = "1"; if (false.Equals(val)) val = "0"; tagdata = basefun.setvaltag(tagdata, colmap[c, 0], Convert.ToString(val)); } CmdProtocol cmdP = new CmdProtocol(this.deviceID, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000,false)) { MessageBox.Show("通讯超时失败", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else MessageBox.Show(cmdP.ResponseFormat); } MessageBox.Show("执行成功!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// ����ɼ� /// </summary> public override void StartGather() { if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1) return; if (null != cmdGather) return; cmdGather = new CmdProtocol(false); cmdGather.TimeLimit = TimeSpan.MaxValue; cmdGather.TimeFailLimit = TimeSpan.MaxValue; cmdGather.FailProAf = FailAftPro.Ignor; cmdGather.TimeSendInv = this.tsinv; this.dtwork = DateTime.Now; this.tagInfos.Clear(); NameObjectList ps = new NameObjectList(); ps["���ѻ�"] = this.devid; DataTable tab = this.query.getTable("���ѻ�״̬", ps); foreach (DataRow dr in tab.Rows) { if (null == dr || DBNull.Value == dr["���"]) continue; this.tagInfos.Add(Convert.ToString(dr["���"]), Convert.ToString(dr["����"])); } string tag = "@�豸��ַ=" + Convert.ToString(this.station); cmdGather.setCommand("����", "���״̬", tag); cmdGather.ResponseHandle += new EventHandler<ResponseEventArgs>(cmdGather_ResponseHandle); this.commimgr.SendCommand(this.target, cmdGather); }
/// <summary> /// 启动采集 /// </summary> public override void StartGather() { if (null == this.commimgr || null == this.target || string.IsNullOrEmpty(this.devid) || this.station < 1) return; if (null != cmdGather) return; CmdProtocol cmdg = new CmdProtocol(false); setTimeout(cmdg); cmdg.TimeLimit = TimeSpan.MaxValue; cmdg.TimeFailLimit = TimeSpan.MaxValue; cmdg.FailProAf = FailAftPro.Ignor; cmdg.TimeSendInv = this.tsinv; cmdg.IsResposeHandle = isResponse; this.tagInfos.Clear(); NameObjectList ps = new NameObjectList(); ps["控制器"] = this.devid; DataTable tab = null; try { Monitor.Enter(objquery); tab = this.query.getTable("道闸状态", ps); } finally { Monitor.PulseAll(objquery); Monitor.Exit(objquery); } if(null!=tab) foreach (DataRow dr in tab.Rows) { if (null == dr || DBNull.Value == dr["类别"]) continue; this.tagInfos.Add(Convert.ToString(dr["类别"]), Convert.ToString(dr["内容"])); } string tag = "@设备地址=" + Convert.ToString(this.station); cmdg.setCommand("门禁", "检测状态", tag); cmdg.ResponseHandle += new EventHandler<ResponseEventArgs>(cmdGather_ResponseHandle); cmdg.ResponseHandle += new EventHandler<ResponseEventArgs>(this.execResponse); this.commimgr.SendCommand(this.target, cmdg); cmdGather = cmdg; }
private void FrmQueryState_Load(object sender, EventArgs e) { this.lbInfonew.Text = ""; this.lbDate.Text = ""; this.lbWorker.Text = ""; string tpl = "停车场", cmd = "检测状态"; CmdProtocol cmdP = new CmdProtocol("巡检设备" + this.deviceID, false); string tagdata = "@设备地址=" + this.deviceID; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(target, cmdP); if (!cmdP.EventWh.WaitOne(2000,false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else this.cmdP_ResponseHandle(cmdP); }
/// <summary> /// 清空记录,重置记录位置 /// </summary> private void ClearRecord() { //清空记录 CmdProtocol cmdP = new CmdProtocol(false); setTimeout(cmdP); cmdP.IsResposeHandle = isResponse; string tag = "@设备地址=" + Convert.ToString(this.station); cmdP.setCommand("门禁", "清空记录", tag); this.commimgr.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(this.waitTime, false)) return; string msg = cmdP.ResponseFormat; if ("true" == basefun.valtag(msg, "Success")) { this.posRecord = 0; NameObjectList pspos = new NameObjectList(); pspos["控制器"] = this.devid; try { Monitor.Enter(objquery); this.query.ExecuteNonQuery("重置记录位置", pspos, pspos, pspos); } finally { Monitor.PulseAll(objquery); Monitor.Exit(objquery); } } }
/// <summary> /// 读取设备控制参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btRead_Click(object sender, EventArgs e) { if (null == this.ds || !this.ds.Tables.Contains("park") || this.ds.Tables["park"].Rows.Count < 1 || !this.ds.Tables["park"].Columns.Contains("dev_id")) { return; } DataTable tab = this.ds.Tables["park"]; BindingManagerBase frmmgr = this.BindingContext[tab]; if (position > 0) frmmgr.Position = position; DataRow dr = ((DataRowView)frmmgr.Current).Row; string addr = Convert.ToString(dr["dev_id"]); if (string.IsNullOrEmpty(addr)) { MessageBox.Show("没有维护设备地址,不能通讯!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string tpl = "停车场", cmd = "读取控制参数"; CmdProtocol cmdP = new CmdProtocol("读取控制参数" + addr, false); string tagdata = "@设备地址=" + addr; cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); else this.cmdP_ResponseHandle(cmdP); }
/// <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); }
private void FrmParkDeposit_Load(object sender, EventArgs e) { this.setContainerTagValue(this.grpInfo, this.tag, "pm"); //直接通讯获取停车费用 if (this.addrst < 0 || null == this.target) return; string cardnum = basefun.valtag(this.tag, "卡号"); string cardtype = basefun.valtag(this.tag, "卡类"); string cartype = basefun.valtag(this.tag, "车型"); string dtparkin = basefun.valtag(this.tag, "入场时间"); if (string.IsNullOrEmpty(cardtype) || string.IsNullOrEmpty(cartype) || string.IsNullOrEmpty(dtparkin)) return; string data=""; NameObjectList ps = ParamManager.createParam(this.tag); foreach (string key in ps.AllKeys) data = basefun.setvaltag(data, "{" + key + "}", Convert.ToString(ps[key])); data = basefun.setvaltag(data, "设备地址", Convert.ToString(this.addrst)); data = basefun.setvaltag(data, "{设备地址}", Convert.ToString(this.addrst)); string dtparkout = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); data = basefun.setvaltag(data, "{出场时间}", dtparkout); data = basefun.setvaltag(data, "{出入场时间}", dtparkout); data = basefun.setvaltag(data, "{开闸方式}", "00"); this.tag = data; CmdProtocol cmdP = new CmdProtocol(false); cmdP.setCommand("停车场", "计算收费金额", data); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) return; string money = basefun.valtag(cmdP.ResponseFormat, "{收费金额}"); if (string.IsNullOrEmpty(money)) return; this.tbPkmoney.Text = money; this.tag = basefun.setvaltag(this.tag, "{收费金额}", money); string cardmoney = basefun.valtag(this.tag, "{卡片余额}"); try { money = Convert.ToString(Convert.ToDecimal(money) - Convert.ToDecimal(cardmoney)); this.tbPkfee.Text = money; this.tag = basefun.setvaltag(this.tag, "{收费}", money); } catch { } }
/// <summary> /// 收取停车费用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btFee_Click(object sender, EventArgs e) { //删除设备入场记录,并返回tag模拟的出入场tag标记值 if (null == this.target || this.addrst < 0) { MessageBox.Show("请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string province = this.cbbProvince.Text; if (!string.IsNullOrEmpty(province)) province = regUperCase.Replace(province, ""); string carnum = this.tbCarnum.Text; if (!string.IsNullOrEmpty(carnum)) carnum = province + carnum; this.tag = basefun.setvaltag(this.tag, "{车牌号码}", carnum); //打印小票 //编号 string code = this.query.ExecuteScalar("打印编号序列号", new NameObjectList()).ToString(); this.tag = basefun.setvaltag(this.tag, "{打印编号}", code); string printer = DataAccRes.AppSettings("收费打印机"); try { if (!string.IsNullOrEmpty(printer)) this.printFee.PrinterSettings.PrinterName = printer; this.printFee.Print(); } catch { } //删除设备停车记录,保存出入场记录 CmdProtocol cmdP = new CmdProtocol(false); cmdP.setCommand("停车场", "删除一条停车记录", this.tag); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(2000, false)) { MessageBox.Show("请检查设备连接或通讯参数后重试!", "通讯提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <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 ("true" != basefun.valtag(msg, "Success")) { return; } //离线后恢复在线时,恢复巡检周期 if (cmdP.TimeSendInv > this.tsbusy) { cmdP.TimeSendInv = this.tsinv; } //工作中或没有新记录,则 string valwk = basefun.valtag(msg, "工作中"); int sum = Convert.ToInt32(basefun.valtag(msg, "{采集标志}")); if ("1" == valwk || sum < 1) { this.dtwork = DateTime.Now; } this.validateSate(msg); //有新记录且不繁忙时可采集新记录50条 if (sum < 1 || DateTime.Now - this.dtwork < tsbusy) { return; } string[] cols = { "{卡号}", "{卡类}", "{消费时间}", "{消费金额}", "{卡余额}", "{累计补助金额}", "{消费机号}", "{操作员号}" }; string tag = "@设备地址=" + Convert.ToString(this.station); this.reChecking(0); TimeSpan tswait = this.waitTime; for (int i = 0; i < 51; i++) { if (i < 1) { cmdP.setCommand("消费", "取当前消费记录", tag); } else if (i < 2) { cmdP.setCommand("消费", "取下一条消费记录", tag); } msg = getResponse(this.commimgr, this.target, cmdP, tswait); if ("true" != basefun.valtag(msg, "Success")) { break; } string cardnum = basefun.valtag(msg, "{卡号}"); if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum) { continue; } string info = ""; for (int c = 0; c < cols.Length; c++) { info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c])); } NameObjectList ps = ParamManager.createParam(info); ps["消费机"] = this.devid; 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.reChecking(1); }
/// <summary> /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次 /// </summary> /// <param name="mgr">通讯管理器</param> /// <param name="target">通讯目标</param> /// <param name="cmd">执行指令</param> /// <param name="strcmd">指令名称</param> /// <param name="timeout">超时间隔</param> /// <returns>返回指令响应结果</returns> private string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, string strcmd, string tag, TimeSpan timeout) { if (null == mgr || null == target || null == cmd || string.IsNullOrEmpty(strcmd) || string.IsNullOrEmpty(tag)) return ""; if (null == cmd.EventWh) cmd.EventWh = new ManualResetEvent(false); string msg = ""; for (int i = 0; i < 5; i++) { msg = ""; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 请求:" + strcmd + " " + tag); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 请求:" + strcmd + " " + tag); cmd.setCommand("消费", strcmd, tag); mgr.SendCommand(target, cmd, true); this.isexecuting = true; if (cmd.EventWh.WaitOne(timeout, false)) msg = cmd.ResponseFormat; this.isexecuting = false; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 响应:" + msg); string suc = basefun.valtag(msg, "Success"); if ("true" == suc) break; //失败时重新采集当前记录 if ("取下一条消费记录" == strcmd) strcmd = "取当前消费记录"; if ("取下一条补助记录" == strcmd) strcmd = "取当前补助记录"; Thread.Sleep(200); } return msg; }
/// <summary> /// ���ͣ�����豸 /// </summary> private void Monitor() { IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName()); string ipstr = ","; foreach (IPAddress ip in IpEntry.AddressList) ipstr += ip + ","; string tpl = "ͣ����", cmd = "�ռ���һ����¼"; foreach (DataGridViewRow dr in this.gdGrid.Rows) { string devname = Convert.ToString(dr.Cells["�豸����"].Value); string ipaddr = Convert.ToString(dr.Cells["IP��ַ"].Value); string devicetype = Convert.ToString(dr.Cells["�豸����"].Value); string commitype = Convert.ToString(dr.Cells["ͨѶ���"].Value); string port = Convert.ToString(dr.Cells["�˿�"].Value); string addrst = Convert.ToString(dr.Cells["ͨѶվַ"].Value); if ("ͣ������Ʊ��" != devicetype || string.IsNullOrEmpty(ipaddr)) continue; if ("Ser" == commitype && !ipstr.Contains(ipaddr)) continue; if (string.IsNullOrEmpty(addrst)) continue; //�������ʱ�ɼ�ͨѶ CommiTarget target = null; if ("Ser" == commitype) target = new CommiTarget(port, 19200); if ("UDP" == commitype) target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.UDP); if ("TCP" == commitype) target = new CommiTarget(ipaddr, Convert.ToInt16(port), CommiType.TCP); string tagdata = "@�豸��ַ=" + addrst; CmdProtocol cmdP = new CmdProtocol(devname + "(" + addrst + ")"); cmdP.setCommand(tpl, cmd, tagdata); target.setProtocol(Protocol.PTLPark); //����������ͨ���������ֽ������ݲ���ȷ cmdP.TimeFailLimit = TimeSpan.MaxValue; cmdP.TimeLimit = TimeSpan.MaxValue; cmdP.TimeSendInv = new TimeSpan(0, 0, 1); //��Ϊ������Ӧ���ٷ���ָ��ķ�ʽ this.target = target; cmdP.ResponseHandle += new EventHandler<ResponseEventArgs>(cmdP_ResponseHandle); CommiManager.GlobalManager.SendCommand(target, cmdP); } }
/// <summary> /// 执行指令; 指令执行失败时,会重新执行一次 /// </summary> /// <param name="ptl">协议</param> /// <param name="cmd">指令</param> /// <param name="tag">指令需要数据</param> /// <param name="devid">设备地址</param> /// <param name="f*g">true 返回数据 false 不返回数据</param> /// <returns>返回指令相应数据,无表示指令执行失败</returns> private string CmdExecute(string ptl, string cmd, string tag, string devid, bool f*g) { bool success = false; string responseFormat = string.Empty; CmdProtocol cmdOpenP = new CmdProtocol(cmd, false); for (int i = 0; i < 2; i++) { tag = basefun.setvaltag(tag, "设备地址", devid); cmdOpenP.setCommand(ptl, cmd, tag); CommiManager.GlobalManager.SendCommand(this.targets[devid], cmdOpenP); success = cmdOpenP.EventWh.WaitOne(800, false); if (success) break; } if (success) responseFormat = cmdOpenP.ResponseFormat; else responseFormat = string.Empty; if (f*g) return responseFormat; else return string.Empty; }
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; }
/// <summary> /// 写入通讯 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DownBtn_Click(object sender, EventArgs e) { string tagdata = "@设备地址=" + this.deviceID; tagdata = this.getTagdata(this.grpCarType, tagdata); tagdata = this.getTagdata(this.grpFeeType, tagdata); tagdata = this.getTagdata(this.tabFeeStd.SelectedTab, tagdata); string cmd = "下载收费标准" + basefun.valtag(tagdata, "{方式代码}"); string tpl = "停车场"; CmdProtocol cmdP = new CmdProtocol(cmd, false); cmdP.setCommand(tpl, cmd, tagdata); CommiManager.GlobalManager.SendCommand(this.target, cmdP); if (!cmdP.EventWh.WaitOne(5000, false)) MessageBox.Show("通讯失败,请检查设备连接或通讯参数后重试!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show("成功下载收费标准!", "设备通讯", MessageBoxButtons.OK, MessageBoxIcon.Information); }