Пример #1
0
        static void Main(string[] args)
        {
            DTSSDK.DTSClient client = new DTSSDK.DTSClient("192.168.0.50");
            client.CallConnected(Connected);
            //client.DisableConnected();
            client.CallDisconnected(Disconnected);
            //client.DisableDisconnected();
            client.CallErrorAction(ErrorCallBack);
            client.CallDeviceEventNotify(DeviceEventNotify);
            client.CallTempSignalNotify(TempSignalNotify);
            client.CallTempSignalNotify(TempSignalNotify);
            client.CallZoneTempNotify(ZoneTempNotify);

            client.Start();

            System.Threading.Thread.Sleep(2000);
            GetDefenceZoneReply reply;
            ErrorDef            error = client.GetDefenceZone(1, "", out reply);

            Console.WriteLine("GetDefenceZone" + error);

            GetDeviceIDReply reply2;

            error = client.GetDeviceID(out reply2);
            Console.WriteLine("GetDeviceIDReply" + error);


            Console.ReadKey();
            client.Close();
        }
Пример #2
0
        /// <summary>
        /// 获得设备id
        /// </summary>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef GetDeviceID(out GetDeviceIDReply reply)
        {
            GetDeviceIDRequest req = new GetDeviceIDRequest();

            ErrorDef result_err = req_wait_reply(req, MsgID.GetDeviceIdreplyId, out reply);

            return(result_err);
        }
Пример #3
0
        /// <summary>
        /// 消音
        /// </summary>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef CloseAlarmSound(out CloseAlarmSoundReply reply)
        {
            CloseAlarmSoundRequest req = new CloseAlarmSoundRequest();

            ErrorDef result_err = req_wait_reply(req, MsgID.CloseAlarmSoundReplyID, out reply);

            return(result_err);
        }
Пример #4
0
        /// <summary>
        /// 重置警报
        /// </summary>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef ResetAlarm(out ResetAlarmReply reply)
        {
            ResetAlarmRequest req = new ResetAlarmRequest();

            ErrorDef result_err = req_wait_reply(req, MsgID.ResetAlarmReplyID, out reply);

            return(result_err);
        }
Пример #5
0
        /// <summary>
        /// 获得所有防区
        /// </summary>
        /// <param name="ch_id">通道</param>
        /// <param name="search">分区名搜索</param>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef GetDefenceZone(int ch_id, string search, out GetDefenceZoneReply reply)
        {
            GetDefenceZoneRequest req = new GetDefenceZoneRequest();

            req.Channel = ch_id;
            req.Search  = search;
            ErrorDef result_err = req_wait_reply(req, MsgID.GetDefenceZoneReplyId, out reply);

            return(result_err);
        }
Пример #6
0
        /// <summary>
        /// 撤防
        /// </summary>
        /// <param name="zid">防区id</param>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef Withdrawal(int zid, out WithdrawalReply reply)
        {
            WithdrawalRequest req = new WithdrawalRequest();

            req.ID = zid;

            ErrorDef result_err = req_wait_reply(req, MsgID.WithdrawalReplyID, out reply);

            return(result_err);
        }
Пример #7
0
        /// <summary>
        /// 布防
        /// </summary>
        /// <param name="zid">防区id</param>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef Deployment(int zid, out DeploymentReply reply)
        {
            DeploymentRequest req = new DeploymentRequest();

            req.ID = zid;

            ErrorDef result_err = req_wait_reply(req, MsgID.DeploymentReplyID, out reply);

            return(result_err);
        }
Пример #8
0
        /// <summary>
        /// 查询并获得回执
        /// </summary>
        /// <typeparam name="T1">请求类</typeparam>
        /// <typeparam name="T2">返回类</typeparam>
        /// <param name="req">请求参数</param>
        /// <param name="wait_id">等待这个包回传</param>
        /// <param name="reply">回传</param>
        /// <returns></returns>
        private ErrorDef req_wait_reply <T1, T2>(T1 req, MsgID wait_id, out T2 reply) where T1 : IMessage <T1> where T2 : IMessage <T2>, new()
        {
            reply = default(T2);
            ErrorDef result_err = ErrorDef.Ok;

            byte[] req_bytes = Codec.Encode(req);
            result_err = write(req_bytes);
            if (result_err != ErrorDef.Ok)
            {
                return(result_err);
            }

            //超过这个时间
            int timeout = 10000;

            result_err = ErrorDef.TimeoutErr;
            T2 _reply = default(T2);
            Action <MsgID, byte[]> action = (msg_id, data) =>
            {
                MessageParser <T2> parser = new MessageParser <T2>(() => new T2());
                _reply     = parser.ParseFrom(data);
                timeout    = 0;
                result_err = ErrorDef.Ok;
            };

            WaitPack pack = new WaitPack();

            pack.action = action;
            pack.msg_id = wait_id;

            lock (wait_pack_look)
            {
                wait_pack.AddLast(pack);
            }

            Thread wait_th = new Thread((o) =>
            {
                while (timeout > 0)
                {
                    Thread.Sleep(50);
                    timeout -= 50;
                }
            });

            wait_th.Start();
            wait_th.Join();

            lock (wait_pack_look)
            {
                wait_pack.Remove(pack);
            }
            reply = _reply;

            return(result_err);
        }
Пример #9
0
        /// <summary>
        /// 查询并获得回执
        /// </summary>
        /// <typeparam name="T1">请求类</typeparam>
        /// <typeparam name="T2">返回类</typeparam>
        /// <param name="req">请求参数</param>
        /// <param name="wait_id">等待这个包回传</param>
        /// <param name="reply">回传</param>
        /// <returns></returns>
        private ErrorDef req_wait_reply <T1, T2>(T1 req, MsgID wait_id, out T2 reply)
        {
            reply = default(T2);
            ErrorDef result_err = ErrorDef.Ok;

            byte[] req_bytes = Codec.Encode(req);
            result_err = write(req_bytes);
            if (result_err != ErrorDef.Ok)
            {
                return(result_err);
            }

            //超过这个时间
            int timeout = 3000;

            result_err = ErrorDef.TimeoutErr;
            T2 _reply = default(T2);
            Action <MsgID, string> action = (msg_id, content) =>
            {
                _reply     = JsonConvert.DeserializeObject <T2>(content);
                timeout    = 0;
                result_err = ErrorDef.Ok;
            };

            WaitPack pack = new WaitPack();

            pack.action = action;
            pack.msg_id = wait_id;

            lock (wait_pack_look)
            {
                wait_pack.AddLast(pack);
            }

            Thread wait_th = new Thread((o) =>
            {
                while (timeout > 0)
                {
                    Thread.Sleep(50);
                    timeout -= 50;
                }
            });

            wait_th.Start();
            wait_th.Join();

            lock (wait_pack_look)
            {
                wait_pack.Remove(pack);
            }
            reply = _reply;

            return(result_err);
        }
Пример #10
0
        static void Main(string[] args)
        {
            RSMSServiceClient clinet = new RSMSServiceClient("127.0.0.1");



            clinet.ConnectedAction               += Connected;
            clinet.DisconnectedAction            += Disconnected;
            clinet.ErrorAction                   += ErrorCallBack;
            clinet.CreateDefenceZoneAction       += CreateDefenceZoneAction;
            clinet.UpdateDefenceZoneAction       += UpdateDefenceZoneAction;
            clinet.UpdateDFStateAction           += UpdateDFStateAction;
            clinet.UpdateDFDeploymentStateAction += UpdateDFDeploymentStateAction;
            clinet.DeleteDFAction                += DeleteDFAction;
            clinet.Start();


            GetDefenceZoneReply reply;
            ErrorDef            error = clinet.GetDefenceZone(0, 10, DateTime.Now.AddDays(-100), DateTime.Now, out reply);

            Console.WriteLine("GetDefenceZone" + error);

            GetHistoryReply reply2;

            error = clinet.GetHistory(0, 10, DateTime.Now.AddDays(-100), DateTime.Now, out reply2);
            Console.WriteLine("GetHistory" + error);

            DeploymentReply reply3;

            error = clinet.Deployment(39, out reply3);
            Console.WriteLine("Deployment" + error);

            WithdrawalReply reply4;

            error = clinet.Withdrawal(39, out reply4);
            Console.WriteLine("Withdrawal" + error);

            ResetAlarmReply reply5;

            error = clinet.ResetAlarm(out reply5);
            Console.WriteLine("ResetAlarm" + error);

            CloseAlarmSoundReply reply6;

            error = clinet.CloseAlarmSound(out reply6);
            Console.WriteLine("CloseAlarmSound" + error);



            Console.ReadKey();
            clinet.Close();
        }
Пример #11
0
        /// <summary>
        /// 设置设备消息回调
        /// </summary>
        /// <param name="reply">返回查询结果</param>
        private ErrorDef SetDeviceRequest(out SetDeviceReply reply)
        {
            SetDeviceRequest req = new SetDeviceRequest();

            req.ZoneTempNotifyEnable    = zone_temp_notify != null;
            req.ZoneAlarmNotifyEnable   = zone_alarm_notify != null;
            req.FiberStatusNotifyEnable = device_event_notify != null;
            req.TempSignalNotifyEnable  = temp_signal_notify != null;

            ErrorDef result_err = req_wait_reply(req, MsgID.SetDeviceReplyId, out reply);

            return(result_err);
        }
Пример #12
0
        /// <summary>
        /// 禁用回调温度信号更新的通知
        /// </summary>
        /// <returns>返回错误代码</returns>
        public ErrorDef DisableTempSignalNotify()
        {
            temp_signal_notify = null;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #13
0
        /// <summary>
        /// 回调温度信号更新的通知
        /// </summary>
        /// <param name="action">回调委托</param>
        /// <returns>返回错误代码</returns>
        public ErrorDef CallTempSignalNotify(Action <TempSignalNotify> action)
        {
            temp_signal_notify = action;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #14
0
        /// <summary>
        /// 禁用回调分区警报更新的通知
        /// </summary>
        /// <returns>返回错误代码</returns>
        public ErrorDef DisableDeviceEventNotify()
        {
            device_event_notify = null;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #15
0
        /// <summary>
        /// 回调光纤状态更新的通知
        /// </summary>
        /// <param name="action">回调委托</param>
        /// <returns>返回错误代码</returns>
        public ErrorDef CallDeviceEventNotify(Action <DeviceEventNotify> action)
        {
            device_event_notify = action;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #16
0
        /// <summary>
        /// 禁用回调分区警报更新的通知
        /// </summary>
        /// <returns>返回错误代码</returns>
        public ErrorDef DisableZoneAlarmNotify()
        {
            zone_alarm_notify = null;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #17
0
        /// <summary>
        /// 回调分区警报更新的通知
        /// </summary>
        /// <param name="action">回调委托</param>
        /// <returns>返回错误代码</returns>
        public ErrorDef CallZoneAlarmNotify(Action <ZoneAlarmNotify> action)
        {
            zone_alarm_notify = action;
            SetDeviceReply reply;
            ErrorDef       err = SetDeviceRequest(out reply);

            if (err != ErrorDef.Ok)
            {
                return(err);
            }
            if (!reply.Success)
            {
                return(ErrorDef.UnknownErr);
            }
            return(ErrorDef.Ok);
        }
Пример #18
0
        /// <summary>
        /// 获得历史记录
        /// </summary>
        /// <param name="offset">偏移</param>
        /// <param name="limit">范围</param>
        /// <param name="start_time">创建时间起始</param>
        /// <param name="finish_time">创建时间终止</param>
        /// <param name="reply">返回查询结果</param>
        public ErrorDef GetHistory(int offset, int limit, DateTime start_time, DateTime finish_time, out GetHistoryReply reply)
        {
            GetHistoryRequest req = new GetHistoryRequest();

            if (start_time != null)
            {
                req.StartTime = start_time.ToString("yyyy-MM-dd HH:mm:ss");
            }
            if (finish_time != null)
            {
                req.FinishTime = finish_time.ToString("yyyy-MM-dd HH:mm:ss");
            }
            req.Offset = offset;
            req.Limit  = limit;
            ErrorDef result_err = req_wait_reply(req, MsgID.GetHistoryReplyID, out reply);

            return(result_err);
        }