Ejemplo n.º 1
0
        void  InitServers()
        {
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName); // TheThingRegistry.GetThingsByProperty("*", Guid.Empty, "DeviceType", eOPCDeviceTypes.OPCServer);

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    if (!tDev.HasLiveObject)
                    {
                        switch (tDev.DeviceType)
                        {
                        case eOPCDeviceTypes.OPCRemoteServer:
                            TheOPCUARemoteServer tS = new TheOPCUARemoteServer(tDev, this, null);
                            TheThingRegistry.RegisterThing(tS);
                            break;

                        case eOPCDeviceTypes.OPCLiveTag:
                            TheOPCUATagThing tag = new TheOPCUATagThing(tDev, null);
                            TheThingRegistry.RegisterThing(tag);
                            break;

                        case eOPCDeviceTypes.OPCMethod:
                            TheOPCUAMethodThing tMeth = new TheOPCUAMethodThing(tDev, MyBaseEngine.GetEngineName());
                            TheThingRegistry.RegisterThing(tMeth);
                            break;
                        }
                    }
                }
            }
            MyBaseEngine.SetStatusLevel(-1);
        }
Ejemplo n.º 2
0
        //private ApplicationConfiguration m_configuration;
        private void GetEndpoints()
        {
            try
            {
                // set a short timeout because this is happening in the drop down event.
                EndpointConfiguration configuration = EndpointConfiguration.Create();
                configuration.OperationTimeout = 20000;

                // Connect to the local discovery server and find the available servers.
                using (DiscoveryClient client = DiscoveryClient.Create(new Uri(Utils.Format("opc.tcp://{0}:4840", MyBaseThing.Address)), configuration))
                {
                    ApplicationDescriptionCollection servers = client.FindServers(null);

                    // populate the drop down list with the discovery URLs for the available servers.
                    for (int ii = 0; ii < servers.Count; ii++)
                    {
                        // don't show discovery servers.
                        if (servers[ii].ApplicationType == ApplicationType.DiscoveryServer)
                        {
                            continue;
                        }

                        for (int jj = 0; jj < servers[ii].DiscoveryUrls.Count; jj++)
                        {
                            string discoveryUrl = servers[ii].DiscoveryUrls[jj];

                            // Many servers will use the '/discovery' suffix for the discovery endpoint.
                            // The URL without this prefix should be the base URL for the server.
                            if (discoveryUrl.EndsWith("/discovery"))
                            {
                                discoveryUrl = discoveryUrl.Substring(0, discoveryUrl.Length - "/discovery".Length);
                            }

                            TheThing tDev = TheThingRegistry.GetThingByFunc(MyBaseEngine.GetEngineName(), s => s.GetProperty("Address", false).ToString() == discoveryUrl);
                            if (tDev == null)
                            {
                                TheOPCUARemoteServer tS = new TheOPCUARemoteServer(null, this, discoveryUrl);
                                TheThingRegistry.RegisterThing(tS);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
            }
        }