Пример #1
0
 /// <summary>
 /// 读取记录数据
 /// </summary>
 /// <param name="devices">设备ID,逗号分割</param>
 /// <returns>转换成表格数据</returns>
 private void FireOpenDoor(string devices)
 {
     if (string.IsNullOrEmpty(devices))
         return;
     string[] devid = devices.ToLower().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
     //检查设备,没有的添加入缓存
     CommiManager commimgr = CommiManager.GlobalManager;
     DeviceBase[] devs = devlist.ToArray();
     DeviceBase[] reqs = new DeviceBase[devid.Length];
     for (int i = 0; i < devid.Length; i++)
     {
         DeviceBase device = null;
         //检查设备已缓存
         for (int j = 0; j < devs.Length; j++)
         {
             if (devid[i] != devs[j].DevID)
                 continue;
             device = reqs[i] = devs[j];
             break;
         }
         //增加设备监控
         if (null != device)
             continue;
         NameObjectList ps = new NameObjectList();
         ps["设备ID"] = devid[i];
         DataTable tab = query.getTable("设备通讯参数", ps);
         if (null == tab || tab.Rows.Count < 1)
             continue;
         DataRow dr = tab.Rows[0];
         string dvtype = Convert.ToString(dr["通讯协议"]);
         if (string.IsNullOrEmpty(dvtype) || "门禁" != dvtype || DBNull.Value == dr["站址"])
             continue;
         string ctrltype = Convert.ToString(dr["控制器类型"]);
         if ("考勤机" == ctrltype)
             continue;
         CommiTarget target = this.getTarget(dr);
         if (null == target) continue;
         target.setProtocol(Protocol.PTLDoor);
         int station = Convert.ToInt32(dr["站址"]);
         if ("进出口" == ctrltype || "出入口" == ctrltype)
             device = new DeviceChannel();
         else
             device = new DeviceDoor();
         device.IsPatrol = false;
         device.dtBeat = DateTime.Now;
         device.SetDevice(commimgr, target, devid[i], station);
         devlist.Add(device);
         reqs[i] = device;
     }
     for (int i = 0; i < reqs.Length; i++)
     {
         if (null == reqs[i])
             continue;
         DeviceBase dv = reqs[i];
         if (!(reqs[i] is DeviceDoor) && !(reqs[i] is DeviceChannel))
             continue;
         if (dv is DeviceDoor)
             ((DeviceDoor)dv).FireOpenDoor();
         else if (dv is DeviceChannel)
             ((DeviceChannel)dv).FireOpenDoor();
     }
 }
Пример #2
0
 /// <summary>
 /// 读取记录数据
 /// </summary>
 /// <param name="devices">设备ID,逗号分割</param>
 /// <returns>转换成表格数据</returns>
 private string readRecord(string devices)
 {
     if (string.IsNullOrEmpty(devices))
         return "";
     //没有启动巡检的设备,启动巡检
     string[] devid = devices.ToLower().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
     string rdformat = "<Row><Device>{0}</Device><Dt>{1}</Dt><Data>{2}</Data></Row>";
     string data = "";
     //检查设备,没有的添加入缓存
     CommiManager commimgr = CommiManager.GlobalManager;
     DeviceBase[] devs = devlist.ToArray();
     DeviceBase[] reqs = new DeviceBase[devid.Length];
     for (int i = 0; i < devid.Length; i++)
     {
         DeviceBase device = null;
         //检查设备已缓存
         for (int j = 0; j < devs.Length; j++)
         {
             if (devid[i] != devs[j].DevID)
                 continue;
             device = reqs[i] = devs[j];
             break;
         }
         //增加设备监控
         if (null != device)
             continue;
         NameObjectList ps = new NameObjectList();
         ps["设备ID"] = devid[i];
         DataTable tab = query.getTable("设备通讯参数", ps);
         if (null == tab || tab.Rows.Count < 1)
             continue;
         DataRow dr = tab.Rows[0];
         string dvtype = Convert.ToString(dr["通讯协议"]);
         if (string.IsNullOrEmpty(dvtype) || DBNull.Value == dr["站址"])
             continue;
         int station = Convert.ToInt32(dr["站址"]);
         CommiTarget target = this.getTarget(dr);
         if (null == target) continue;
         switch (dvtype)
         {
             case "门禁":
                 string ctrltype = Convert.ToString(dr["控制器类型"]);
                 if ("进出口" == ctrltype || "出入口" == ctrltype)
                     device = new DeviceChannel();
                 else
                     device = new DeviceDoor();
                 target.setProtocol(Protocol.PTLDoor);
                 break;
             case "消费":
                 device = new DeviceEatery();
                 target.setProtocol(Protocol.PTLEatery);
                 break;
             default:
                 continue;
         }
         device.IsPatrol = false;
         device.dtBeat = DateTime.Now;
         device.SetDevice(commimgr, target, devid[i], station);
         devlist.Add(device);
         reqs[i] = device;
     }
     //通讯获取数据
     List<ManualResetEvent> ehm = new List<ManualResetEvent>();
     for (int i = 0; i < reqs.Length; i++)
     {
         DeviceSyn syn = new DeviceSyn();
         syn.dev = reqs[i];
         syn.eh = new ManualResetEvent(false);
         ehm.Add(syn.eh);
         ThreadManager.QueueUserWorkItem(delegate(object obj) { this.readRecordSyn(obj); }, syn);
     }
     ManualResetEvent[] ehs = ehm.ToArray();
     ManualResetEvent.WaitAll(ehs);
     myLog.Flush();
     return dataResult;
 }
Пример #3
0
 private static void gatherData(object obj)
 {
     dtRunHdl = DateTime.Now;
     while (true)
     {
         hdlWh.Reset();
         for (int i = 0; i < 200; i++)
         {
             if (dvQueue.Count > 0)
             {
                 break;
             }
             dtRunHdl = DateTime.Now;
             hdlWh.WaitOne(20);
         }
         if (dvQueue.Count < 1)
         {
             dtRunHdl = DateTime.MinValue;
             break;
         }
         DeviceChannel channel = null;
         Monitor.Enter(dvQueue);
         try { channel = dvQueue.Dequeue(); }
         catch { }
         Monitor.PulseAll(dvQueue);
         Monitor.Exit(dvQueue);
         if (null == channel)
         {
             continue;
         }
         if (channel.sumRecord > 500)
         {
             channel.ClearRecord();
             continue;
         }
         //采集记录
         if (null != channel.cmdGather)
         {
             channel.cmdGather.TimeSendInv = channel.tsbusy.Add(channel.tsinv);
         }
         else
         {
             channel.reChecking(0);
         }
         CmdProtocol cmdP = new CmdProtocol(false);
         setTimeout(cmdP);
         cmdP.TimeFailLimit   = cmdP.TimeOut.Add(new TimeSpan(-10 * 10000));
         cmdP.TimeLimit       = TimeSpan.MaxValue;
         cmdP.TimeSendInv     = new TimeSpan(1, 0, 0);
         cmdP.ResponseHandle += new EventHandler <ResponseEventArgs>(channel.execResponse);
         cmdP.IsResposeHandle = isResponse;
         cmdP.DeviceType      = "通道闸.采集";
         string tag = "@设备地址=" + Convert.ToString(channel.station);
         NameValueCollection datainfo = new NameValueCollection();
         for (int i = 0; i < 200; i++)
         {
             string msg = channel.getResponse(channel.commimgr, channel.target, cmdP, "读取记录", tag, channel.waitTime);
             if (string.IsNullOrEmpty(msg))
             {
                 continue;
             }
             string cardnum = basefun.valtag(msg, "{卡号}");
             string suc     = basefun.valtag(msg, "Success");
             if ("true" != suc || "16777215" == cardnum || "0" == cardnum)
             {
                 //bool isend = channel.IsEndReadDevice(-1);
                 //记录错误时记入日志,继续下一条
                 if ("false" == suc)
                 {
                     datainfo["操作"] = "读取记录失败";
                     datainfo["报文"] = CommandBase.Parse(cmdP.ResponseData, true);
                     ServiceTool.LogMessage(msg, datainfo, EventLogEntryType.FailureAudit);
                 }
                 break;
                 //if (isend)  break;
             }
             channel.writeRecord(msg);
         }
         channel.commimgr.RemoveCommand(channel.target, cmdP);
         //channel.reChecking(1);
         if (null != channel.cmdGather)
         {
             channel.cmdGather.TimeSendInv = channel.tsinv;
         }
         else
         {
             channel.reChecking(1);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 添加监控管理的设备
        /// </summary>
        /// <param name="devid">请求的客户端</param>
        /// <param name="ispatrol">是否持续巡检</param>
        private DeviceBase addDevice(string devid, bool ispatrol)
        {
            //增加设备监控
            NameObjectList ps = new NameObjectList();

            ps["设备ID"] = devid;
            DataTable tab = this.query.getTable("设备通讯参数", ps);

            if (null == tab || tab.Rows.Count < 1)
            {
                return(null);
            }
            DataRow dr = tab.Rows[0];

            if (!tab.Columns.Contains("通讯协议"))
            {
                string msg = "";
                foreach (object obj in dr.ItemArray)
                {
                    msg += Convert.ToString(obj) + " ";
                }
                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 设备通讯参数值:" + msg);
                myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 设备通讯参数值:" + msg);
                return(null);
            }
            string dvtype = Convert.ToString(dr["通讯协议"]);

            if (string.IsNullOrEmpty(dvtype) || DBNull.Value == dr["站址"])
            {
                return(null);
            }
            int         station = Convert.ToInt32(dr["站址"]);
            CommiTarget target  = this.getTarget(dr);

            if (null == target)
            {
                return(null);
            }
            CommiManager commimgr = CommiManager.GlobalManager;
            DeviceBase   device   = null;

            switch (dvtype)
            {
            case "门禁":
                Debug.WriteLine("门禁");
                string ctrltype = Convert.ToString(dr["控制器类型"]);
                if ("进出口" == ctrltype || "出入口" == ctrltype)
                {
                    device = new DeviceChannel();
                }
                else
                {
                    device = new DeviceDoor();
                }
                target.setProtocol(Protocol.PTLDoor);
                device.AlarmHandle += new EventHandler <DvAlarmEventArgs>(device_AlarmHandle);
                break;

            case "消费":
                device = new DeviceEatery();
                target.setProtocol(Protocol.PTLEatery);
                break;

            default:
                return(null);
            }
            device.RecordHandle += new EventHandler <DvRecordEventArgs>(device_RecordHandle);
            Monitor.Enter(devlist);
            this.devlist.Add(device);
            Monitor.PulseAll(devlist);
            Monitor.Exit(devlist);
            device.IsPatrol = ispatrol;
            device.dtBeat   = DateTime.Now;
            device.SetDevice(commimgr, target, devid, station);
            device.StartGather();
            Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 启动:" + Convert.ToString(station) + " 设备ID:" + devid);
            myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 启动:" + Convert.ToString(station) + " 设备ID:" + devid);
            return(device);
        }
Пример #5
0
 /// <summary>
 /// 添加监控管理的设备
 /// </summary>
 /// <param name="devid">请求的客户端</param>
 /// <param name="ispatrol">是否持续巡检</param>
 private DeviceBase addDevice(string devid, bool ispatrol)
 {
     //增加设备监控
     NameObjectList ps = new NameObjectList();
     ps["设备ID"] = devid;
     DataTable tab = this.query.getTable("设备通讯参数", ps);
     if (null == tab || tab.Rows.Count < 1)
         return null;
     DataRow dr = tab.Rows[0];
     if (!tab.Columns.Contains("通讯协议"))
     {
         string msg = "";
         foreach (object obj in dr.ItemArray)
             msg += Convert.ToString(obj) + " ";
         Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 设备通讯参数值:" + msg);
         myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 设备通讯参数值:" + msg);
         return null;
     }
     string dvtype = Convert.ToString(dr["通讯协议"]);
     if (string.IsNullOrEmpty(dvtype) || DBNull.Value == dr["站址"])
         return null;
     int station = Convert.ToInt32(dr["站址"]);
     CommiTarget target = this.getTarget(dr);
     if (null == target) return null;
     CommiManager commimgr = CommiManager.GlobalManager;
     DeviceBase device = null;
     switch (dvtype)
     {
             
         case "门禁":
             Debug.WriteLine("门禁");
             string ctrltype = Convert.ToString(dr["控制器类型"]);
             if ("进出口" == ctrltype || "出入口" == ctrltype)
                 device = new DeviceChannel();
             else
                 device = new DeviceDoor();
             target.setProtocol(Protocol.PTLDoor);
             device.AlarmHandle += new EventHandler<DvAlarmEventArgs>(device_AlarmHandle);
             break;
         case "消费":
             device = new DeviceEatery();
             target.setProtocol(Protocol.PTLEatery);
             break;
         default:
             return null;
     }
     device.RecordHandle += new EventHandler<DvRecordEventArgs>(device_RecordHandle);
     Monitor.Enter(devlist);
     this.devlist.Add(device);
     Monitor.PulseAll(devlist);
     Monitor.Exit(devlist);
     device.IsPatrol = ispatrol;
     device.dtBeat = DateTime.Now;
     device.SetDevice(commimgr, target, devid, station);
     device.StartGather();
     Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 启动:" + Convert.ToString(station) + " 设备ID:" + devid);
     myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 启动:" + Convert.ToString(station) + " 设备ID:" + devid);
     return device;
 }