Exemplo n.º 1
0
        /// <summary>
        /// 设置通讯设备
        /// </summary>
        /// <param name="devid">设备ID</param>
        /// <param name="target">通讯目标</param>
        /// <param name="station">站址</param>
        public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
        {
            if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
            {
                return;
            }
            this.commimgr = mgr;
            this.target   = target;
            this.devid    = devid;
            this.station  = station;
            NameObjectList ps = new NameObjectList();

            ps["分组ID"] = devid;
            DataTable tab = this.query.getTable("门禁设备", ps);

            if (null == tab || tab.Rows.Count < 1)
            {
                return;
            }
            object val = tab.Rows[0]["记录位置"];

            if (null == val || DBNull.Value == val)
            {
                val = 0;
            }
            this.posRecord = Convert.ToInt32(val);
            val            = tab.Rows[0]["控制器类型"];
            this.devtype   = Convert.ToString(val);
            if (string.IsNullOrEmpty(this.devtype))
            {
                this.devtype = "考勤机";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发送指令,获取指令结果,在通讯失败时自动尝试执行5次
        /// </summary>
        /// <param name="mgr">通讯管理器</param>
        /// <param name="target">通讯目标</param>
        /// <param name="cmd">执行指令</param>
        /// <param name="timeout">超时间隔</param>
        /// <returns>返回指令响应结果</returns>
        private static string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, TimeSpan timeout)
        {
            if (null == mgr || null == target || null == cmd)
            {
                return("");
            }
            if (null == cmd.EventWh)
            {
                cmd.EventWh = new ManualResetEvent(false);
            }
            string msg = "";

            for (int i = 0; i < 5; i++)
            {
                msg = "";
                cmd.ResetState();
                mgr.SendCommand(target, cmd);
                if (cmd.EventWh.WaitOne(timeout, false))
                {
                    msg = cmd.ResponseFormat;
                }
                string suc = basefun.valtag(msg, "Success");
                if ("true" == suc)
                {
                    break;
                }
                Thread.Sleep(200);
            }
            return(msg);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 对目标通讯关闭心跳
 /// </summary>
 /// <param name="mgr">通讯管理器</param>
 /// <param name="target">通讯目标</param>
 public static void CloseHeaderBeat(CommiManager mgr, CommiTarget target)
 {
     if (null == mgr || null == target)
     {
         return;
     }
     mgr.RemoveCommand(target, CmdHeaderBeat);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 对目标通讯启动心跳,已经有则不会重复
 /// </summary>
 /// <param name="mgr">通讯管理器</param>
 /// <param name="target">通讯目标</param>
 public static void OpenHeaderBeat(CommiManager mgr, CommiTarget target)
 {
     if (null == mgr || null == target)
     {
         return;
     }
     target.setProtocol(CmdFileTrans.PTL);
     mgr.SendCommand(target, CmdHeaderBeat);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 添加监控管理的设备
        /// </summary>
        /// <param name="devid">请求的客户端</param>
        /// <param name="ispatrol">是否持续巡检</param>
        private void addDevice(string devid, bool ispatrol)
        {
            //设备已经监控,则不再增加设备信息
            DeviceBase[] devices = this.devlist.ToArray();
            for (int i = 0; i < devices.Length; i++)
            {
                if (devid == devices[i].DevID)
                {
                    return;
                }
            }

            //增加设备监控
            Estar.Common.Tools.NameObjectList ps = new Estar.Common.Tools.NameObjectList();
            ps["设备ID"] = devid;
            DataTable tab = this.query.getTable("设备通讯参数", ps);

            if (null == tab || tab.Rows.Count < 1)
            {
                return;
            }
            DataRow dr     = tab.Rows[0];
            string  dvtype = Convert.ToString(dr["通讯协议"]);

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

            switch (dvtype)
            {
            case "门禁":
                device = new DeviceDoor();
                target.setProtocol(Protocol.PTLDoor);
                break;

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

            default:
                return;
            }
            device.IsPatrol = ispatrol;
            device.SetDevice(commimgr, target, devid, station);
            this.devlist.Add(device);
            device.RecordHandle += new EventHandler <DvRecordEventArgs>(device_RecordHandle);
            device.SignalHandle += new EventHandler <DvSignalEventArgs>(device_SignalHandle);
            device.AlarmHandle  += new EventHandler <DvAlarmEventArgs>(device_AlarmHandle);
            device.StartGather();
        }
Exemplo n.º 6
0
 /// <summary>
 /// 设置通讯设备
 /// </summary>
 /// <param name="devid">设备ID</param>
 /// <param name="target">通讯目标</param>
 /// <param name="station">站址</param>
 public virtual void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
     {
         return;
     }
     this.commimgr = mgr;
     this.target   = target;
     this.devid    = devid;
     this.station  = station;
 }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 添加监控管理的设备
        /// </summary>
        /// <param name="devid">请求的客户端</param>
        /// <param name="ispatrol">是否持续巡检</param>
        private DeviceBase addDevice(string devid, bool ispatrol)
        {
            //增加设备监控
            Estar.Common.Tools.NameObjectList ps = new Estar.Common.Tools.NameObjectList();
            ps["设备ID"] = devid;
            DataTable tab = this.query.getTable("设备通讯参数", ps);

            if (null == tab || tab.Rows.Count < 1)
            {
                return(null);
            }
            DataRow dr     = tab.Rows[0];
            string  dvtype = Convert.ToString(dr["通讯协议"]);

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

            switch (dvtype)
            {
            case "门禁":
                device = new DeviceDoor();
                target.setProtocol(Protocol.PTLDoor);
                break;

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

            default:
                return(null);
            }
            device.IsPatrol = ispatrol;
            device.dtBeat   = DateTime.Now;
            device.SetDevice(commimgr, target, devid, station);
            this.devlist.Add(device);
            device.StartGather();
            return(device);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 设置通讯设备
        /// </summary>
        /// <param name="devid">设备ID</param>
        /// <param name="target">通讯目标</param>
        /// <param name="station">站址</param>
        public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
        {
            if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
            {
                return;
            }
            this.commimgr = mgr;
            this.target   = target;
            this.devid    = devid;
            this.station  = station;
            NameObjectList ps = new NameObjectList();

            ps["分组ID"] = devid;
            DataTable tab = null;

            try
            {
                Monitor.Enter(objquery);
                tab = this.query.getTable("道闸设备", ps);
            }
            finally
            {
                Monitor.PulseAll(objquery);
                Monitor.Exit(objquery);
            }
            if (null == tab || tab.Rows.Count < 1)
            {
                return;
            }
            object val = tab.Rows[0]["控制器类型"];

            this.devtype  = Convert.ToString(val);
            val           = tab.Rows[0]["区域"];
            this.region   = Convert.ToString(val);
            val           = tab.Rows[0]["区域ID"];
            this.regionID = Convert.ToString(val);
            DataRow[] drs = tab.Select("", "读卡器号");
            for (int i = 0; i < 4 && i < drs.Length; i++)
            {
                channels[i] = Convert.ToString(drs[i]["名称"]);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 火警联动
        /// </summary>
        /// <param name="sender">门禁设备</param>
        /// <param name="e">报警事件</param>
        void device_AlarmHandle(object sender, DvAlarmEventArgs e)
        {
            DeviceDoor door = sender as DeviceDoor;

            if (null == door || null == e || string.IsNullOrEmpty(e.TagAlarm))
            {
                return;
            }
            string fire = basefun.valtag(e.TagAlarm, "火警");

            if ("1" != fire)
            {
                return;
            }
            NameObjectList ps = new NameObjectList();

            ps["设备ID"] = door.DevID;
            DataTable    tab      = this.query.getTable("同组设备", ps);
            CommiManager commimgr = CommiManager.GlobalManager;

            for (int i = 0; i < tab.Rows.Count; i++)
            {
                DataRow dr     = tab.Rows[i];
                string  dvid   = Convert.ToString(dr["ID"]);
                string  dvtype = Convert.ToString(dr["通讯协议"]);
                if (string.IsNullOrEmpty(dvtype) || DBNull.Value == dr["站址"])
                {
                    return;
                }
                int         station = Convert.ToInt32(dr["站址"]);
                CommiTarget target  = this.getTarget(dr);
                if (null == target)
                {
                    return;
                }
                target.setProtocol(Protocol.PTLDoor);
                door = new DeviceDoor();
                door.SetDevice(commimgr, target, dvid, station);
                door.FireOpenDoor();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 设置通讯设备
        /// </summary>
        /// <param name="devid">设备ID</param>
        /// <param name="target">通讯目标</param>
        /// <param name="station">站址</param>
        public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
        {
            if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
            {
                return;
            }
            this.commimgr = mgr;
            this.target   = target;
            this.devid    = devid;
            this.station  = station;
            NameObjectList ps = new NameObjectList();

            ps["设备ID"] = devid;
            DataTable tab = this.query.getTable("消费设备", ps);

            if (null == tab || tab.Rows.Count < 1)
            {
                return;
            }
            this.devName = Convert.ToString(tab.Rows[0]["名称"]);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 设置RF通讯端口,波特率,站址,被动只接收数据
        /// </summary>
        /// <param name="port">RF射频串口</param>
        /// <param name="baudRate">波特率</param>
        /// <returns>能够打开端口则成功,端口占用或参数非法则失败</returns>
        public bool setRfTarget(string port, int baudRate)
        {
            CommiManager mgr = CommiManager.GlobalManager;

            if (null != this.rftar && this.rftar.PortName == port)
            {
                mgr.SendCommand(this.rftar, this.cmdRFID);
                return(true);
            }
            if (null != this.rftar)
            {
                mgr.RemoveCommand(this.rftar);
            }
            this.rftar = null;
            try
            {
                CommiTarget tar = new CommiTarget(port, baudRate);
                Protocol    ptl = new Protocol();
                ptl.FrameHeader = new byte[] { 0x02 };
                ptl.FrameFoot   = new byte[] { 0x03, 0x0A, 0x0D };
                ptl.TotalBytes  = 13;
                tar.setProtocol(ptl);
                if (!mgr.TestConnect(tar))
                {
                    return(false);
                }
                this.rftar = tar;
            }
            catch
            {
                return(false);
            }
            //命令只接收数据
            this.cmdRFID.ResetState();
            byte[] request = new byte[] { 0x02, 0x00, 0x00, 0x03, 0x0A, 0x0D };
            this.cmdRFID.setCommand(request);
            mgr.SendCommand(this.rftar, this.cmdRFID);
            return(true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// ����ָ���ȡָ��������ͨѶʧ��ʱ�Զ�����ִ��5��
 /// </summary>
 /// <param name="mgr">ͨѶ������</param>
 /// <param name="target">ͨѶĿ��</param>
 /// <param name="cmd">ִ��ָ��</param>
 /// <param name="timeout">��ʱ���</param>
 /// <returns>����ָ����Ӧ���</returns>
 private static string getResponse(CommiManager mgr, CommiTarget target, CmdProtocol cmd, TimeSpan timeout)
 {
     if (null == mgr || null == target || null == cmd)
         return "";
     if(null==cmd.EventWh)
         cmd.EventWh = new ManualResetEvent(false);
     string msg = "";
     for (int i = 0; i < 5; i++)
     {
         msg = "";
         cmd.ResetState();
         mgr.SendCommand(target, cmd);
         if (cmd.EventWh.WaitOne(timeout, false))
             msg = cmd.ResponseFormat;
         string suc = basefun.valtag(msg, "Success");
         if ("true" == suc)
             break;
         Thread.Sleep(200);
     }
     return msg;
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
 /// <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;
 }
Exemplo n.º 17
0
 /// <summary>
 /// 设置通讯设备
 /// </summary>
 /// <param name="devid">设备ID</param>
 /// <param name="target">通讯目标</param>
 /// <param name="station">站址</param>
 public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
         return;
     this.commimgr = mgr;
     this.target = target;
     this.devid = devid;
     this.station = station;
     NameObjectList ps = new NameObjectList();
     ps["设备ID"] = devid;
     DataTable tab = this.query.getTable("消费设备", ps);
     if (null == tab || tab.Rows.Count < 1)
         return;
     this.devName = Convert.ToString(tab.Rows[0]["名称"]);
 }
Exemplo n.º 18
0
 /// <summary>
 /// 对目标通讯启动心跳,已经有则不会重复
 /// </summary>
 /// <param name="mgr">通讯管理器</param>
 /// <param name="target">通讯目标</param>
 public static CommandBase OpenHeaderBeat(CommiManager mgr, CommiTarget target)
 {
     if (null == mgr || null == target)
         return null;
     target.setProtocol(CmdFileTrans.PTL);
     mgr.SendCommand(target, CmdHeaderBeat);
     return CmdHeaderBeat;
 }
Exemplo n.º 19
0
 /// <summary>
 /// 设置通讯设备
 /// </summary>
 /// <param name="devid">设备ID</param>
 /// <param name="target">通讯目标</param>
 /// <param name="station">站址</param>
 public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
         return;
     this.commimgr = mgr;
     this.target = target;
     this.devid = devid;
     this.station = station;
     NameObjectList ps = new NameObjectList();
     ps["分组ID"] = devid;
     DataTable tab = null;
     try
     {
         Monitor.Enter(objquery);
         tab = this.query.getTable("道闸设备", ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (null == tab || tab.Rows.Count < 1)
         return;
     object val = tab.Rows[0]["控制器类型"];
     this.devtype = Convert.ToString(val);
     val = tab.Rows[0]["区域"];
     this.region = Convert.ToString(val);
     val = tab.Rows[0]["区域ID"];
     this.regionID = Convert.ToString(val);
     DataRow[] drs = tab.Select("", "读卡器号");
     for (int i = 0; i < 4 && i < drs.Length; i++)
         channels[i] = Convert.ToString(drs[i]["名称"]);
 }
Exemplo n.º 20
0
 /// <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;
 }
Exemplo n.º 21
0
 /// <summary>
 /// ����ͨѶ�豸
 /// </summary>
 /// <param name="devid">�豸ID</param>
 /// <param name="target">ͨѶĿ��</param>
 /// <param name="station">վַ</param>
 public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
         return;
     this.commimgr = mgr;
     this.target = target;
     this.devid = devid;
     this.station = station;
     NameObjectList ps = new NameObjectList();
     ps["����ID"] = devid;
     DataTable tab = this.query.getTable("�Ž��豸", ps);
     if (null == tab || tab.Rows.Count < 1)
         return;
     object val = tab.Rows[0]["��¼λ��"];
     if (null == val || DBNull.Value == val)
         val = 0;
     this.posRecord = Convert.ToInt32(val);
     val = tab.Rows[0]["����������"];
     this.devtype = Convert.ToString(val);
     if (string.IsNullOrEmpty(this.devtype))
         this.devtype = "���ڻ�";
 }
Exemplo n.º 22
0
 /// <summary>
 /// 对目标通讯关闭心跳
 /// </summary>
 /// <param name="mgr">通讯管理器</param>
 /// <param name="target">通讯目标</param>
 public static void CloseHeaderBeat(CommiManager mgr, CommiTarget target)
 {
     if (null == mgr || null == target)
         return;
     mgr.RemoveCommand(target, CmdHeaderBeat);
 }
Exemplo n.º 23
0
 /// <summary>
 /// 设置通讯设备
 /// </summary>
 /// <param name="devid">设备ID</param>
 /// <param name="target">通讯目标</param>
 /// <param name="station">站址</param>
 public override void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
         return;
     this.commimgr = mgr;
     this.target = target;
     this.devid = devid;
     this.station = station;
     NameObjectList ps = new NameObjectList();
     ps["分组ID"] = devid;
     DataTable tab = null;
     try
     {
         Monitor.Enter(objquery);
         tab = this.query.getTable("门禁设备", ps);
     }
     finally
     {
         Monitor.PulseAll(objquery);
         Monitor.Exit(objquery);
     }
     if (null == tab || tab.Rows.Count < 1)
         return;
     object val = tab.Rows[0]["记录位置"];
     if (null == val || DBNull.Value == val || string.IsNullOrEmpty(Convert.ToString(val)))
         val = tab.Rows[0]["记录位置"] = 1;
     this.posRecord = Convert.ToInt32(val);
     val = tab.Rows[0]["控制器类型"];
     this.devtype = Convert.ToString(val);
     if (string.IsNullOrEmpty(this.devtype))
         this.devtype = "考勤机";
 }
Exemplo n.º 24
0
 /// <summary>
 /// ����ͨѶ�豸
 /// </summary>
 /// <param name="devid">�豸ID</param>
 /// <param name="target">ͨѶĿ��</param>
 /// <param name="station">վַ</param>
 public virtual void SetDevice(CommiManager mgr, CommiTarget target, string devid, int station)
 {
     if (null == mgr || string.IsNullOrEmpty(devid) || null == target || station < 1)
         return;
     this.commimgr = mgr;
     this.target = target;
     this.devid = devid;
     this.station = station;
 }