コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
 /// <summary>
 /// 双击打开监控画面,两个画面都已经打开则循环关闭启用新画面
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void gdGrid_DoubleClick(object sender, EventArgs e)
 {
     if (null == sender || !(sender is DataGridView))
         return;
     DataGridView gd = sender as DataGridView;
     if (gd.Rows.Count < 1 || null == gd.CurrentRow)
         return;
     DataGridViewRow dr = gd.CurrentRow;
     string devname = Convert.ToString(dr.Cells["设备名称"].Value);
     string devtype = Convert.ToString(dr.Cells["设备类型"].Value);
     string commitype = Convert.ToString(dr.Cells["通讯类别"].Value);
     string ipaddr = Convert.ToString(dr.Cells["IP地址"].Value);
     if (this.hvWatchs.ContainsKey(devname))
         return;
     if ("车牌识别器" != devtype)
         return;
     HvCarWatch hv = new HvCarWatch();
     string msg = hv.HVdiscern.Open(ipaddr);
     if (!string.IsNullOrEmpty(msg))
     {
         MessageBox.Show(msg);
         return;
     }
     hv.dslast = DateTime.Now;
     //多个监控图形,可循环选择使用
     if (this.hvDevices.Count > this.picWatchs.Count / 2 - 1)
     {
         if (this.indexWatch > this.hvDevices.Count - 1)
             this.indexWatch = 0;
         string key = this.hvDevices[this.indexWatch];
         this.hvWatchs[key].HVdiscern.Close();
         this.hvWatchs.Remove(key);
         this.hvDevices.RemoveAt(this.indexWatch);
         this.hvDevices.Insert(this.indexWatch, devname);
     }
     else
         this.hvDevices.Add(devname);
     this.hvWatchs.Add(devname, hv);
     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.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.Tag = info;
     this.indexWatch = this.picWatchs.Count / 2 - 1 == this.indexWatch ? 0 : this.indexWatch + 1;
 }