예제 #1
0
        /// <summary>
        /// Server connection procedure
        /// </summary>
        /// <param name="urlString">OPC server URL in string format</param>
        /// <returns>isConnected</returns>
        public bool ConnectServer(string urlString)
        {
            isConnected = false;

            this.url = new Opc.URL(urlString);
            factory  = new OpcCom.Factory();
            server   = new Opc.Da.Server(factory, url);

            try
            {
                selectedServer = selectedServer ?? new mServerItem(true);
                server.Connect();
                if (isConnected = server.IsConnected)
                {
                    OnReportMessage(0, "Server is connected");

                    server.ServerShutdown -= server_ServerShutdown;
                    server.ServerShutdown += server_ServerShutdown;
                    RefreshServerStatus();
                }
                else
                {
                    OnReportMessage("Server connection fail, unknown error");
                }
            }
            catch (Exception ex)
            {
                OnReportMessage(ex.Message.ToString());
            }

            return(isConnected);
        }
예제 #2
0
        public exOPCserver()
        {
            listServers     = new ObservableCollection <mServerItem>();
            monitoredTags   = new ObservableCollection <mTag>();
            restoredTagList = new List <mTag>();
            messageLog      = new List <string>();
            logMessage("Message log started");

            isConnected     = false;
            opcSubscription = null;

            selectedServer = new mServerItem(true);
            selectedServer.ReconnectInterval = 5000;

            configureWatchDog();

            error = new gErrorEntity(0, "Initialized");
        }
예제 #3
0
        public ObservableCollection <mServerItem> GetServers(string hostname)
        {
            try {
                OpcCom.ServerEnumerator discovery = new OpcCom.ServerEnumerator();

                if (hostname == "")
                {
                    hostname = "localhost";
                }

                selectedServer.Host = hostname;

                //Get all local OPC DA servers of version 3.0
                Opc.Server[] localservers = discovery.GetAvailableServers(Opc.Specification.COM_DA_20, hostname, null);

                listServers.Clear();

                foreach (Opc.Server srv in localservers)
                {
                    mServerItem si = new mServerItem(true);

                    si.Name        = srv.Name;
                    si.Description = srv.Locale;
                    si.UrlString   = srv.Url.ToString();

                    listServers.Add(si);
                }
            }
            catch (Exception ex)
            {
                OnReportMessage("Opc server enumerator failed");
                OnReportMessage(ex.Message);
            }



            //Get all OPC DA servers of version 2.0 of machine "MyMachine"
            //Opc.Server[] hostservers = discovery.GetAvailableServers(Opc.Specification.COM_DA_20, "MNS1-179N", null);

            return(listServers);
        }