Exemplo n.º 1
0
        /// <summary>
        /// 连接Rmtp服务
        /// </summary>
        /// <param name="pIp">Rmtp目标IP</param>
        /// <param name="pPort">端口号</param>
        public void ConnectRmtpService(RmtpCommand pCmd)
        {
            string pIp   = ConfigurationManager.AppSettings["IP"];
            int    pPort = int.Parse(ConfigurationManager.AppSettings["Port"]);

            if (_rmtpControler != null && _rmtpControler.IsConnected)
            {
                return;
            }

            if (_rmtpDataFrameCache != null)
            {
                _rmtpDataFrameCache.ReceiveDataFrame -= OnReceiveDataFrame;
                _rmtpDataFrameCache = null;
            }

            _rmtpDataFrameCache = new RmtpDataFrameCache(pCmd);
            _rmtpDataFrameCache.ReceiveDataFrame += OnReceiveDataFrame;

            if (_rmtpControler != null)
            {
                _rmtpControler.Close();
                _rmtpControler.SocketConnected -= OnRmtpConnected;
                _rmtpControler.SocketError     -= OnRmtpError;
                _rmtpControler = null;
            }

            _rmtpControler = new SocketController(pIp, pPort, _rmtpDataFrameCache);
            _rmtpControler.SocketConnected += OnRmtpConnected;
            _rmtpControler.SocketError     += OnRmtpError;

            _rmtpControler.Connect();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cache的构造函数
        /// </summary>
        /// <param name="pCmd">Rmtp指令</param>
        public RmtpDataFrameCache(RmtpCommand pCmd)
        {
            _rmtpcmd = pCmd;

            _dataFrameCaches = new RmtpDataFrameCacheValue();

            ThreadPool.QueueUserWorkItem(TryDequeueFromCache);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行RMTP监测相关指令(监测指令和非监测指令)
        /// </summary>
        /// <param name="pCommand">命令类型</param>
        /// <param name="pParameter">命令携带参数</param>
        /// <param name="pPricode">是正在进行的控制的优先级代码,默认值:1</param>
        /// <param name="pChannelid">执行任务的设备通道号,默认值:0</param>
        /// <param name="pIsNewMeasureNumber">true - 生成新测量序号,false - 保持原测量序号</param>
        public void ExecuteCommand(RmtpCommand pCommand,
                                   object pParameter        = null,
                                   int pPricode             = 1,
                                   int pChannelid           = 0,
                                   bool pIsNewMeasureNumber = false)
        {
            if (_rmtpControler == null || !_rmtpControler.IsConnected)
            {
                AssistTool.WriteOutput(string.Format("Rmtp服务连接已断开,指令“{0}”无效", pCommand));
                return;
            }

            if (!_executeRmtpFun.ContainsKey(pCommand))
            {
                return;
            }

            var cmdMessageFrame = new CommandMessageFrame(pCommand);

            _executeRmtpFun[pCommand].CommandHandler(cmdMessageFrame, new[] { pParameter, pPricode, pChannelid });
            cmdMessageFrame.Header.ChannelId = pChannelid;

            _rmtpControler.Send(cmdMessageFrame);
        }
 /// <summary>
 /// Rmtp命令属性构造函数
 /// </summary>
 /// <param name="pCmd">Rmtp命令</param>
 public RmtpCommandAttribute(RmtpCommand pCmd)
 {
     _rmtpCmd = pCmd;
 }
 public CommandMessageFrame(RmtpCommand pCommand)
 {
     _command = pCommand;
 }