Esempio 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
            { }
        }
Esempio n. 2
0
        //链接OPC服务器
        public void Connnect()
        {
            try
            {
                OPCServerState state = (OPCServerState)(_OPCServer.ServerState);

                if (state != OPCServerState.OPCRunning)
                {
                    _OPCServer.Connect(_OPCServerName, _IPAddress.ToString());

                    for (int i = 0; i < Groups.Count; i++)
                    {
                        Groups[i].DetachFromServer(this);//重新注册一下各个组
                        Groups[i].AttachToServer(this);
                    }
                }
            }
            catch
            { }
        }
Esempio n. 3
0
        //断开OPC链接
        public void Disconnect()
        {
            try
            {
                OPCServerState state = (OPCServerState)(_OPCServer.ServerState);
                if (state != OPCServerState.OPCDisconnected)
                {
                    for (int i = 0; i < Groups.Count; i++)
                    {
                        Groups[i].DetachFromServer(this);//解除各个组的注册
                    }

                    _OPCServer.ServerShutDown -= OPCServer_ServerShutDown;

                    OPCServer_ServerShutDown(string.Empty);//关闭链接
                }
            }
            catch
            { }
        }