Exemplo n.º 1
0
        private BLModal _ServerItem                    = null;                 //服务端所有条目

        /// <summary>
        /// 连接服务器
        /// </summary>
        /// <param name="server"></param>
        /// <returns></returns>
        public bool Connect(OpcServer server)
        {
            if (server == null)
            {
                throw (new ArgumentNullException());
            }
            OpcDaServer daServer = server as OpcDaServer;

            _DaClient = new OPCDAAUTO.OpcDAClientHelper(daServer.Ip, daServer.EndpointDesCription.Description);
            _DaClient.Connect();

            GetServerItem();                    //获取服务端变量

            _OpcDaGroup = _DaClient.AddGroup(new Group()
            {
                Channel = "C",
                Device  = "D",
            });
            _OpcDaGroup.DataChangeEvent          += _OpcDaGroup_DataChangeEvent;
            _OpcDaGroup.AsyncReadCompleteEvent   += _OpcDaGroup_AsyncReadCompleteEvent;
            _OpcDaGroup.AsyncWriteCompleteEvent  += _OpcDaGroup_AsyncWriteCompleteEvent;
            _OpcDaGroup.AsyncCancelCompleteEvent += _OpcDaGroup_AsyncCancelCompleteEvent;
            IsConnected = true;
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发现服务器
        /// </summary>
        /// <param name="serverUrl"></param>
        /// <returns></returns>
        public List <EndpointDes> FindServer(string serverUrl)
        {
            List <EndpointDes> endpointDes = new List <EndpointDes>();

            foreach (var s in OpcDAClientHelper.GetOpcServer(serverUrl))
            {
                endpointDes.Add(new EndpointDes()
                {
                    ID          = Guid.NewGuid().ToString(),
                    Description = s
                });
            }

            return(endpointDes);
        }
Exemplo n.º 3
0
        public void GetBranch()
        {
            List <string>     leafs  = new List <string>();
            OpcDAClientHelper client = new OpcDAClientHelper();

            client.Connect();
            client.GetUserNodeTags();
            List <string> branch = client.GetBranch("");

            for (int i = 0; i < branch.Count; i++)
            {
                if (!branch[i].StartsWith("_"))
                {
                    leafs = client.GetBranch(branch[i]);
                }
            }
            client.DisConnect();
        }
Exemplo n.º 4
0
        //枚举本地OPC服务器
        private void GetLocalServer()
        {
            //获取本地计算机IP,计算机名称
            IPHostEntry IPHost = Dns.GetHostEntry(Environment.MachineName);

            if (IPHost.AddressList.Length > 0)
            {
                strHostIP = IPHost.AddressList[2].ToString();
                //txtRemoteServerIP.Text = IPHost.AddressList[2].ToString();
                Server_IP.Text = IPHost.AddressList[2].ToString();
            }
            else
            {
                return;
            }
                        //通过IP来获取计算机名称,可用在局域网内
                        IPHostEntry ipHostEntry = Dns.GetHostEntry(strHostIP);

            strHostName = ipHostEntry.HostName.ToString();
            //获取本地计算机上的OPCServerName
                        try
            {
                //创建OPC服务器对象,获得OPC服务器列表

                object serverList = OpcDAClientHelper.GetOpcServer(strHostIP);

                //显示服务器列表
                foreach (string turn in (Array)serverList)
                {
                    cmbServerName.Items.Add(turn);
                    list_INFO.Items.Add("发现服务器 " + strHostIP.ToString() + ":  " + turn.ToString());
                    if (list_INFO.Items.Count == 40)
                    {
                        list_INFO.Items.Clear();
                    }
                }
                cmbServerName.SelectedIndex = 0;
                connect_server.Enabled      = true;
            }
            catch (Exception err)
            {
                MessageBox.Show("枚举本地OPC服务器出错:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public bool Connect(OpcServer server)
        {
            if (server == null)
            {
                throw (new ArgumentNullException());
            }
            OpcDaServer daServer = server as OpcDaServer;

            _DaClient = new OPCDAAUTO.OpcDAClientHelper(daServer.Ip, daServer.ProgId);
            _DaClient.Connect();
            _OpcDaGroup = _DaClient.AddGroup(new Group()
            {
                Channel = "C",
                Device  = "D",
            });
            _OpcDaGroup.DataChangeEvent          += _OpcDaGroup_DataChangeEvent;
            _OpcDaGroup.AsyncReadCompleteEvent   += _OpcDaGroup_AsyncReadCompleteEvent;
            _OpcDaGroup.AsyncWriteCompleteEvent  += _OpcDaGroup_AsyncWriteCompleteEvent;
            _OpcDaGroup.AsyncCancelCompleteEvent += _OpcDaGroup_AsyncCancelCompleteEvent;
            return(true);
        }
Exemplo n.º 6
0
        //连接OPC服务器
        private bool ConnectServer(string ServerIP, string ServerName)
        {
            try
            {
                opcClient = new OpcDAClientHelper(ServerIP, ServerName);

                if (opcClient.Connect())
                {
                    label3.Text = "OPC 已连接";
                }
                else
                {
                    MessageBox.Show("women");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("连接远程服务器出现错误:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        //连接OPC服务器
        private bool ConnectServer(string ServerIP, string ServerName)
        {
            try
            {
                opcClient = new OpcDAClientHelper(ServerIP, ServerName);

                if (opcClient.Connect())
                {
                    connect_server.BackColor = Color.Green;
                    connect_server.Enabled   = false;
                }
                else
                {
                    MessageBox.Show("women");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("连接远程服务器出现错误:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }