Exemplo n.º 1
0
        //附加组到服务器执行的操作
        internal void AttachToServer(SHHOPCServer server)
        {
            try
            {
                this.Server = server;

                OPCServerState serverState = (OPCServerState)(server.OPCServer.ServerState);

                if (serverState != OPCServerState.OPCDisconnected)
                {
                    //OPC服务对象
                    _opcGroup                      = server.OPCServer.OPCGroups.Add(this.Name);
                    _opcGroup.TimeBias             = TimeBias;
                    _opcGroup.UpdateRate           = UpdateRate;
                    _opcGroup.IsActive             = IsActive;
                    _opcGroup.IsSubscribed         = IsSubscribed;
                    _opcGroup.DeadBand             = DeadBend;
                    _opcGroup.DataChange          += OPCGroup_DataChange;          //测点值改变(一般是事件订阅触发)
                    _opcGroup.AsyncReadComplete   += OPCGroup_AsyncReadComplete;   //异步读成功
                    _opcGroup.AsyncWriteComplete  += OPCGroup_AsyncWriteComplete;  //异步写成功
                    _opcGroup.AsyncCancelComplete += OPCGroup_AsyncCancelComplete; //异步取消成功

                    //重新注册子项
                    for (int i = 0; i < ItemList.Count; i++)
                    {
                        ItemList[i].DetachFromGroup(this);
                        ItemList[i].AttachToGroup(this);
                    }
                }

                //Server = null;
            }
            catch
            { }
        }
Exemplo n.º 2
0
        //从服务器分离执行的操作
        internal void DetachFromServer(SHHOPCServer server)
        {
            try
            {
                if (server.OPCServer.OPCGroups != null && _opcGroup != null)
                {
                    //取消事件
                    _opcGroup.DataChange          -= OPCGroup_DataChange;          //测点值改变(一般是事件订阅触发)
                    _opcGroup.AsyncReadComplete   -= OPCGroup_AsyncReadComplete;   //异步读成功
                    _opcGroup.AsyncWriteComplete  -= OPCGroup_AsyncWriteComplete;  //异步写成功
                    _opcGroup.AsyncCancelComplete -= OPCGroup_AsyncCancelComplete; //异步取消成功

                    server.OPCServer.OPCGroups.Remove(this.Name);                  //从OPC通讯中移除
                }
                _opcGroup = null;
            }
            catch
            { }
        }