Esempio n. 1
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4840/", manager)) {
                var users = server.Security.UserNameAcl;

                // 1. Add the users to the UserName-ACL.
                var admin = users.AddEntry(new SystemIdentity("Admin", "admin"));
                var user  = users.AddEntry(new SystemIdentity("User", "user"));

                var support = users.AddEntry(new SystemIdentity("Support", "support")
                                             .Deny("Machine/Shutdown")
                                             .Deny("Machine/Speed")
                                             .Deny("Machine/Tooling"));

                // 2. Setup the global user privileges accordingly.
                user.Deny(OpcRequestType.Write);

                // 3. Activate the UserName-ACL (this inline disables anonymous access).
                users.IsEnabled = true;

                // 4. Publish ACL to node manager.
                manager.AccessControl = users;

                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4840/", manager)) {
                server.Start();

                Console.WriteLine("Press enter to exit or ...");
                Console.WriteLine("... enter a node path like '/a/b/c' to create a folder node.");
                Console.WriteLine("... enter a path like '/a/b/.d' to create a numeric variable node.");
                Console.WriteLine();

                while (true)
                {
                    var path = Console.ReadLine().Trim().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                    if (path.Length == 0)
                    {
                        break;
                    }

                    var node = manager.AddNode(path);
                    Console.WriteLine("Created: '{0}'", node.Id.ToString(OpcNodeIdFormat.Foundation));
                }
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            var server = new OpcServer(
                "opc.tcp://localhost:4840/SampleServer",
                new SampleNodeManager());

            // By default an OPC UA server uses the ACL for anonymous authentication. To
            // support user name and password based authentication the UserName ACL needs
            // to be enabled.
            server.Security.UserNameAcl.IsEnabled = true;

            // To register a specific user name and password pair add that entry to the
            // UserName ACL of the OPC UA server.
            var entry = server.Security.UserNameAcl.AddEntry("username", "password");

            // Additionally it is possible to allow and deny specific operations on the entry.
            // By default all operations are enabled on the entry.
            entry.Deny(OpcRequestType.Write);

            server.Start();
            Console.ReadKey(true);
            server.Stop();
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var node = new OpcFolderNode("MyFolder");

            node.DisplayName = new OpcText("MyFolder", "en-US", "MyFolder.DisplayName");
            node.Description = new OpcText("MyFolder Description", "en-US", "MyFolder.Description");

            using (var server = new OpcServer("opc.tcp://localhost:4840", node)) {
                server.Globalization.AddResources(
                    "en-US",
                    new KeyValuePair <string, string>("MyFolder.DisplayName", "MyFolder (en)"),
                    new KeyValuePair <string, string>("MyFolder.Description", "MyFolder Description (en)"));
                server.Globalization.AddResources(
                    "de-DE",
                    new KeyValuePair <string, string>("MyFolder.DisplayName", "Mein Ordner (de)"),
                    new KeyValuePair <string, string>("MyFolder.Description", "Meine Ordner Beschreibung (de)"));
                server.Globalization.AddResources(
                    "fr-FR",
                    new KeyValuePair <string, string>("MyFolder.DisplayName", "Mon dossier (fr)"),
                    new KeyValuePair <string, string>("MyFolder.Description", "Description de mon dossier (fr)"));

                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            var nodeManager = new SampleNodeManager();

            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            OpcServer server = new OpcServer(
                "opc.tcp://localhost:4840/SampleServer",
                nodeManager);

            server.Start();
            //// NOTE: All AE specific code will be found in the SampleNodeManager.cs.

            using (var semaphore = new SemaphoreSlim(0)) {
                var thread = new Thread(() => nodeManager.Simulate(semaphore));
                thread.Start();

                Console.WriteLine("OPC UA Server is running...");
                Console.ReadKey(true);

                semaphore.Release();
                thread.Join();

                server.Stop();
            }
        }
Esempio n. 6
0
    public static void Main()
    {
        connectedClients = 0;
        List <OpcDataVariableNode> nodeList = new List <OpcDataVariableNode>();
        var temperatureNode    = new OpcDataVariableNode <double>("Temperature", 100.0);
        var messageNode        = new OpcDataVariableNode <string>("Message", string.Empty);
        var levelDetectionNode = new OpcDataVariableNode <bool>("Level", false);

        bool avslutt = false;

        nodeList.Add(levelDetectionNode);
        nodeList.Add(temperatureNode);
        nodeList.Add(messageNode);

        using (var server = new OpcServer("opc.tcp://localhost:4840/", nodeList))
        {
            server.Started += new EventHandler((sender, e) => ServerStarted(sender, e, nodeList, server));
            // server.RequestProcessing += new OpcRequestProcessingEventHandler((a, b) => reqProcessing(a,b));
            //server.RequestProcessed += new OpcRequestProcessedEventHandler((sender, e) => RequestProcessed(sender, e));
            server.SessionActivated += new OpcSessionEventHandler((sender, e) => SessionMethod(sender, e));
            server.SessionCreated   += new OpcSessionEventHandler((serr, rerrr) => sessionCreatedMethod(serr, rerrr));
            server.SessionClosing   += new OpcSessionEventHandler((sender, e) => SessionClosingMethod(sender, e));

            server.Start();

            while (true)
            {
                if (temperatureNode.Value == 110)
                {
                    temperatureNode.Value = 100;
                }
                else
                {
                    temperatureNode.Value++;
                }

                if (messageNode.Value.Length > 5)
                {
                    messageNode.Value = "e";
                }
                else
                {
                    messageNode.Value += 'a';
                }
                if (levelDetectionNode.Value == true)
                {
                    levelDetectionNode.Value = false;
                }
                else
                {
                    levelDetectionNode.Value = true;
                }


                Thread.Sleep(1000);
            }
        }
    }
Esempio n. 7
0
        public UAServer(string host)
        {
            //_nodeManager = new NodeManager();
            _temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

            _server = new OpcServer(host, _temperatureNode);
            _server.Start();

            Task task = Task.Factory.StartNew(TemperatureMaker);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4840/", manager)) {
                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4840/", manager)) {
                server.ApplicationUri = new Uri("http://sampleserver/samplenodetypes");
                server.Start();

                Console.WriteLine("Server started - now browse the resulting nodes.");
                Console.ReadLine();
            }
        }
Esempio n. 10
0
        public static void Main(string[] args)
        {
            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            OpcServer server = new OpcServer(
                "opc.tcp://localhost:4840/SampleServer",
                new SampleNodeManager());

            //// NOTE: All HDA specific code will be found in the SampleNodeManager.cs.

            server.Start();
            Console.ReadKey(true);
            server.Stop();
        }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            var fileInfo = new FtpFileInfo(
                path: "ftp://test.rebex.net/readme.txt",
                credentials: new NetworkCredential("demo", "password"));

            using (var server = new OpcServer(
                       "opc.tcp://localhost:4840/",
                       new OpcFileNode("readme.txt", fileInfo))) {
                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4840/", manager)) {
                server.Start();

                Console.WriteLine("Server started - press enter to report an event.");
                var line = Console.ReadLine();

                while (line.Length == 0)
                {
                    manager.ReportEvent();
                    line = Console.ReadLine();
                }
            }
        }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            //// To simple use the configuration stored within the XML configuration file
            //// beside the server application you just need to load the configuration file as the
            //// following code does demonstrate.
            //// By default it is not necessary to explicitly configure an OPC UA server. But in case
            //// of advanced and productive scenarios you will have to.

            // There are different ways to load the server configuration.
            OpcApplicationConfiguration configuration = null;

            // 1st Way: Load server config using a file path.
            configuration = OpcApplicationConfiguration.LoadServerConfigFile(
                Path.Combine(Environment.CurrentDirectory, "ServerConfig.xml"));

            // 2nd Way: Load server config specified in a specific section of your App.config.
            configuration = OpcApplicationConfiguration.LoadServerConfig("Opc.UaFx.Server");

            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            var server = new OpcServer(
                "opc.tcp://localhost:4840/SampleServer",
                new SampleNodeManager());

            // To take use of the loaded server configuration, just set it on the server instance.
            server.Configuration = configuration;

            server.Start();
            server.Stop();

            // In case you are using the OPC UA server (Service) Application class, you can explicitly
            // trigger loading a configuration file using the App.config as the following code does
            // demonstrate.
            var app = new OpcServerApplication(
                "opc.tcp://localhost:4840/SampleServer",
                new SampleNodeManager());

            app.LoadConfiguration();

            // Alternatively you can assign the manually loaded server configuration on the server
            // instance used by the application instance, as the following code does demonstrate.
            app.Server.Configuration = configuration;

            app.Run();
        }
Esempio n. 14
0
        public static void Main(string[] args)
        {
            var manager = new SampleNodeManager();

            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            OpcServer server = new OpcServer("opc.tcp://localhost:4840/SampleServer", manager);

            //// NOTE: All HDA specific code will be found in the SampleNodeManager.cs.

            server.Start();
            CreateHistoryEntries(manager);

            Console.Write("Server started - press any key to exit.");
            Console.ReadKey(true);

            server.Stop();
        }
Esempio n. 15
0
        public static void Main(string[] args)
        {
            var manager = new NodeManager();

            using (var server = new OpcServer("opc.tcp://localhost:4841/", manager)) {
                server.Start();

                using (var semaphore = new SemaphoreSlim(0)) {
                    var thread = new Thread(() => manager.Schedule(semaphore));
                    thread.Start();

                    Console.WriteLine("Server started - press any key to exit.");
                    Console.ReadKey(true);

                    semaphore.Release();
                    thread.Join();
                }
            }
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            producerControl = new CancellationTokenSource();

            dataNodes = new List <OpcDataVariableNode <int> >();
            dataNode  = CreateDataNode();

            var producer = new Thread(ProduceDataChanges);

            using (var server = new OpcServer("opc.tcp://localhost:4840/", dataNode)) {
                server.Start();
                producer.Start(server);

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);

                producerControl.Cancel();
                producer.Join();
            }
        }
Esempio n. 17
0
        public static void Main(string[] args)
        {
            var someNode = new OpcDataVariableNode <string>("Hello", value: "Hello World!");

            using (var server = new OpcServer("opc.tcp://localhost:4840/", someNode)) {
                var users = server.Security.UserNameAcl;

                // 1. Add the generic users to the UserName-ACL.
                users.AddEntry(OpcWindowsIdentity.Generic);
                users.AddEntry(OpcSubSystemIdentity.Generic);

                // 2. Activate the UserName-ACL (this inline disables anonymous access).
                users.IsEnabled = true;

                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 18
0
        public static void Main(string[] args)
        {
            var address       = GetAddress(args);
            var hostAddresses = GetHostAddresses(address);

            var manager = new NodeManager();

            using (var server = new OpcServer(address, manager)) {
                Console.Write("Starting server...");
                server.Start();
                Console.WriteLine("started!");

                Console.WriteLine();
                Console.WriteLine("Server listening to:");
                Console.WriteLine($"\t{address}");

                foreach (var hostAddress in hostAddresses)
                {
                    Console.WriteLine($"\t{hostAddress}");
                }

                Console.WriteLine();

                var semaphore = new SemaphoreSlim(0);
                var thread    = new Thread(() => manager.Simulate(semaphore));

                thread.Start();

                Console.WriteLine("Press any key to stop the server.");
                Console.ReadKey(true);

                semaphore.Release();
                thread.Join();

                Console.WriteLine();
                Console.Write("Stopping server...");
            }

            Console.Write("stopped!");
        }
Esempio n. 19
0
        public static void Main(string[] args)
        {
            while (true)
            {
                Console.Clear();
                var managers = QueryNodeManagers();

                using (var server = new OpcServer("opc.tcp://localhost:4840/", managers)) {
                    Console.WriteLine("Starting...");
                    server.Start();

                    foreach (var nodeManager in server.NodeManagers.OfType <NodeManager>())
                    {
                        Console.Write(" - {0}...", nodeManager.Name);
                        nodeManager.Start();
                        Console.WriteLine("done.");
                    }

                    Console.WriteLine("Started.");

                    Console.Write("Press any key to use different node managers.");
                    Console.ReadLine();

                    Console.WriteLine("Stopping...");

                    foreach (var nodeManager in server.NodeManagers.OfType <NodeManager>())
                    {
                        Console.Write(" - {0}...", nodeManager.Name);
                        nodeManager.Stop();
                        Console.WriteLine("done.");
                    }
                }

                Console.WriteLine("Stopped.");

                Console.Write("Press any key to setup a new server.");
                Console.ReadLine();
            }
        }
Esempio n. 20
0
        public static void Main(string[] args)
        {
            temperatureNode = new OpcDataVariableNode <double>("Temperature");
            speedNode       = new OpcDataVariableNode <int>("Speed");

            var machineNode = new OpcObjectNode(
                "Machine",
                temperatureNode,
                speedNode,
                new OpcActionMethodNode("StartMachine", StartMachine),
                new OpcActionMethodNode("StopMachine", StopMachine));

            using (var server = new OpcServer("opc.tcp://localhost:4840/", machineNode)) {
                server.Start();

                machineNode.AddNotifier(server.SystemContext, temperatureNode);
                machineNode.AddNotifier(server.SystemContext, speedNode);

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 21
0
        public static void Main()
        {
            var temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

            using (var server = new OpcServer("opc.tcp://localhost:4840/", temperatureNode)) {
                server.Start();

                while (true)
                {
                    if (temperatureNode.Value == 110)
                    {
                        temperatureNode.Value = 100;
                    }
                    else
                    {
                        temperatureNode.Value++;
                    }

                    temperatureNode.ApplyChanges(server.SystemContext);
                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 22
0
        public static void Main(string[] args)
        {
            OpcNodeId.Factory = new SimaticNodeIdFactory();

            var db1 = new OpcFolderNode(
                "DataBlock1",
                new OpcDataVariableNode <byte>("MaxByte", value: byte.MaxValue),
                new OpcDataVariableNode <short>("MaxInt", value: short.MaxValue),
                new OpcDataVariableNode <int>("MaxDInt", value: int.MaxValue));

            var db2 = new OpcFolderNode(
                "DataBlock2",
                new OpcObjectNode("MyStruct",
                                  new OpcDataVariableNode <int>("FieldA", value: 10),
                                  new OpcDataVariableNode <int>("FieldB", value: 20)));

            using (var server = new OpcServer("opc.tcp://localhost:4840/", db1, db2)) {
                server.Start();

                Console.WriteLine("Server started - press any key to exit.");
                Console.ReadKey(true);
            }
        }
Esempio n. 23
0
        public static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("Enter a valid ip address for the server (or localhost)");
                return;
            }
            string serverIP = args[0];

            #region 1st Way: Use the OpcServer class.
            {
                //// The OpcServer class interacts with one or more OPC UA clients using one of
                //// the registered base addresses of the server. While this class provides the
                //// different OPC UA services defined by OPC UA, it does not implement a main loop.

                //string serverURL = "https://localhost:4840/SampleServer";
                //string serverURL = "opc.tcp://localhost:4840/SampleServer";
                string serverURL       = $"opc.tcp://{serverIP}:4840/SampleServer";
                var    temperatureNode = new OpcDataVariableNode <double>("Temperature", 100.0);

                //using var server = new OpcServer(serverURL, temperatureNode);
                using var server = new OpcServer(serverURL, temperatureNode);
                server.Start();

                Console.WriteLine("Started the server at {0}", serverURL);

                while (true)
                {
                    if (temperatureNode.Value == 110)
                    {
                        temperatureNode.Value = 100;
                    }
                    else
                    {
                        temperatureNode.Value++;
                    }

                    temperatureNode.ApplyChanges(server.SystemContext);
                    Thread.Sleep(1000);
                }
            }
            #endregion

            #region 2nd Way: Use the OpcServerApplication class.
            {
                // The OpcServerApplication class uses a single OpcServer instance which is
                // wrapped within a main loop.
                //
                // Remarks
                // - The app instance does start a main loop when the server has been started.
                // - Custom startup code have to be implemented within the event handler of the
                //   Started event of the app instance.
                // new OpcServerApplication("opc.tcp://localhost:4840/SampleServer", new SampleNodeManager()).Run();
            }
            #endregion

            #region 3rd Way: Use the OpcServerServiceApplication class.
            {
                //// The OpcServerServiceApplication class uses a single OpcServer instance which is
                //// wrapped within a main loop when it is started with an interactive user or in
                //// debug mode. Otherwise it will start the process as a windows service which
                //// allows the application can be registered as a service process.
                ////
                //// Remarks
                //// - The app instance does start a main loop when the server has been started.
                //// - Custom startup code have to be implemented within the event handler of the
                ////   Started event of the app instance.
                //new OpcServerServiceApplication("opc.tcp://localhost:4840/SampleServer", new SampleNodeManager()).Run();
            }
            #endregion
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            //// To simple use the in code configuration you just need to configure your server
            //// instance using the Configuration property of it.
            //// By default it is not necessary to explicitly configure an OPC UA server. But in case
            //// of advanced and productive scenarios you will have to.

            // If the server domain name does not match localhost just replace it
            // e.g. with the IP address or name of the server machine.
            var server = new OpcServer(
                "opc.tcp://*****:*****@"%LocalApplicationData%\My Application\App Certificates";
            securityConfiguration.RejectedCertificateStore.StorePath
                = @"%LocalApplicationData%\My Application\Rejected Certificates";
            securityConfiguration.TrustedIssuerCertificates.StorePath
                = @"%LocalApplicationData%\My Application\Trusted Issuer Certificates";
            securityConfiguration.TrustedPeerCertificates.StorePath
                = @"%LocalApplicationData%\My Application\Trusted Peer Certificates";

            //// It is not necessary that all certificate stores have to point to the same root
            //// directory as above. Each store can also point to a totally different directory.

            server.Configuration = configuration;

            // 3rd Way: Directly change the default configuration of the server instance using the
            //         Configuration property.
            server.Configuration.ServerConfiguration.MaxSessionCount = 10;

            server.Start();
            server.Stop();

            // In case you are using the OPC UA server (Service) Application class, you can directly
            // configure your server/application using the Configuration property of the
            // application instance as the following code does demonstrate.
            var app = new OpcServerApplication(
                "opc.tcp://localhost:4840/SampleServer",
                new SampleNodeManager());

            app.Configuration.ServerConfiguration.MaxSessionCount = 10;
            app.Run();
        }