예제 #1
1
        static void UaRxxWriter(XElement tag, object value)
        {
            using (var uaClient = new EasyUAClient())
            {
                uaClient.WriteValue(
                    new UAWriteValueArguments(
                       GetElementAttribute(tag, "ua", "endpoint"),
                       $"ns=2;s={tag.Parent.Attribute("name").Value}.{ tag.Attribute("node").Value}",
                       value
                    )
                );
            }

        }
            public static void Overload1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain data nodes under "Objects" node
                UANodeElementCollection nodeElementCollection = easyUAClient.BrowseDataNodes(
                    "http://opcua.demo-this.com:51211/UA/SampleServer"); // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"

                // Display results
                foreach (UANodeElement nodeElement in nodeElementCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId);
                    Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName);
                }

                // Example output:
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2253
                //nodeElement.DisplayName: Server
                //
                //nodeElement.NodeId: nsu=http://test.org/UA/Data/;i=10157
                //nodeElement.DisplayName: Data
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/Boiler/;i=1240
                //nodeElement.DisplayName: Boilers
                //
                //nodeElement.NodeId: nsu=http://samples.org/UA/memorybuffer;i=1025
                //nodeElement.DisplayName: MemoryBuffers
            }
예제 #3
0
            public static void TestSuccess()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Modify data of nodes' attributes
                OperationResult[] operationResultArray = easyUAClient.WriteMultiple(new[]
                {
                    new UAWriteArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10221",
                                         new UAAttributeData(23456, UASeverity.GoodOrSuccess, DateTime.UtcNow)),
                    new UAWriteArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10226",
                                         new UAAttributeData(2.34567890, UASeverity.GoodOrSuccess, DateTime.UtcNow)),
                    new UAWriteArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10227",
                                         new UAAttributeData("ABC", UASeverity.GoodOrSuccess, DateTime.UtcNow))
                    // Writing server timestamp is not supported by the sample server.
                });

                // The UA Test Server does not support this, and therefore failures will occur.

                for (int i = 0; i < operationResultArray.Length; i++)
                {
                    if (operationResultArray[i].Succeeded)
                    {
                        Console.WriteLine("Result {0}: success", i);
                    }
                    else
                    {
                        Console.WriteLine("Result {0}: {1}", i, operationResultArray[i].Exception.GetBaseException().Message);
                    }
                }
            }
예제 #4
0
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain values. By default, the Value attributes of the nodes will be read.
                ValueResult[] valueResultArray = easyUAClient.ReadMultipleValues(new[]
                {
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10845"),
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853"),
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10855")
                });

                // Display results
                foreach (ValueResult valueResult in valueResultArray)
                {
                    Console.WriteLine("Value: {0}", valueResult.Value);
                }

                // Example output:
                //
                //Value: 8
                //Value: -8.06803E+21
                //Value: Strawberry Pig Banana Snake Mango Purple Grape Monkey Purple? Blueberry Lemon^
            }
예제 #5
0
파일: Program.cs 프로젝트: fr830/OpcClient
        // ua simulator hard coded + hard coded config
        static void UaRxSim()
        {
            Clear();
            using (new ConsoleColourer(Yellow, Black))
                WriteLine("reactive UA simulation! Press a key to quit.");


            var uaClient = new EasyUAClient();

            var rxUaSubscription = UAMonitoredItemChangedObservable.Create <int>(new EasyUAMonitoredItemArguments(
                                                                                     "uaState",
                                                                                     "opc.tcp://127.0.0.1:49320/",
                                                                                     "ns=2;s=Channel1.Device1.Tag2",
                                                                                     0)
                                                                                 )
                                   .Subscribe(val =>
            {
                WriteLine(string.Format("wrote {0} to {1} on {2} being {3}", val.AttributeData.Value, "ns=2;s=Channel1.Device1.Tag1", "ns=2;s=Channel1.Device1.Tag2", val.AttributeData.Value));
                uaClient.WriteValue(
                    new UAWriteValueArguments(
                        "opc.tcp://127.0.0.1:49320/",
                        "ns=2;s=Channel1.Device1.Tag1",
                        val.AttributeData.Value
                        )
                    );
            }
                                              );

            var key = ReadKey();

            rxUaSubscription.Dispose();
            uaClient.Dispose();
        }
예제 #6
0
            private static void BrowseFrom(UANodeDescriptor nodeDescriptor)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Parent node: {0}", nodeDescriptor);

                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain notifiers
                UANodeElementCollection notifierNodeElementCollection = easyUAClient.BrowseNotifiers(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    nodeDescriptor);

                // Display notifiers
                Console.WriteLine();
                Console.WriteLine("Notifiers:");
                foreach (UANodeElement notifierNodeElement in notifierNodeElementCollection)
                {
                    Console.WriteLine(notifierNodeElement);
                }

                // Obtain objects
                UANodeElementCollection objectNodeElementCollection = easyUAClient.BrowseObjects(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    nodeDescriptor);

                // Recurse
                foreach (UANodeElement objectNodeElement in objectNodeElementCollection)
                {
                    BrowseFrom(objectNodeElement);
                }
            }
            public static void Main1()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.EventNotification += easyUAClient_EventNotification;

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeEvent(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    UAObjectIds.Server,
                    1000,
                    new UAAttributeFieldCollection
                {
                    // Select specific fields using standard operand symbols
                    UABaseEventObject.Operands.NodeId,
                    UABaseEventObject.Operands.SourceNode,
                    UABaseEventObject.Operands.SourceName,
                    UABaseEventObject.Operands.Time,

                    // Select specific fields using an event type ID and a simple relative path
                    UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Message"),
                    UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Severity"),
                });

                Console.WriteLine("Processing event notifications for 30 seconds...");
                System.Threading.Thread.Sleep(30 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
            public static void TestSuccess()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Modify value of a node
                OperationResult[] operationResultArray = easyUAClient.WriteMultipleValues(new[]
                {
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;i=10221", 23456),
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;i=10226", "This string cannot be converted to Double"),
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;s=UnknownNode", "ABC")
                });

                for (int i = 0; i < operationResultArray.Length; i++)
                {
                    if (operationResultArray[i].Succeeded)
                    {
                        Console.WriteLine("Result {0}: success", i);
                    }
                    else
                    {
                        Console.WriteLine("Result {0}: {1}", i, operationResultArray[i].Exception.GetBaseException().Message);
                    }
                }
            }
예제 #9
0
            public static void Main1()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.EventNotification += easyUAClient_EventNotification;

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeEvent(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    UAObjectIds.Server,
                    1000,
                    new UAEventFilterBuilder(
                        // Either the severity is >= 500, or the event comes from a specified source node
                        UAFilterElements.Or(
                            UAFilterElements.GreaterThanOrEqual(UABaseEventObject.Operands.Severity, 500),
                            UAFilterElements.Equals(
                                UABaseEventObject.Operands.SourceNode,
                                new UANodeId("nsu=http://opcfoundation.org/Quickstarts/AlarmCondition;ns=2;s=1:Metals/SouthMotor"))),
                        UABaseEventObject.AllFields));

                Console.WriteLine("Processing event notifications for 30 seconds...");
                System.Threading.Thread.Sleep(30 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
            public static void Overload1()
            {
                var easyUAClient = new EasyUAClient();

                easyUAClient.DataChangeNotification += easyUAClient_DataChangeNotification;

                Console.WriteLine("Subscribing...");
                int handle = easyUAClient.SubscribeDataChange(
                    "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    "nsu=http://test.org/UA/Data/;i=10853",
                    1000);

                Console.WriteLine("Processing monitored item changed events for 10 seconds...");
                System.Threading.Thread.Sleep(10 * 1000);

                Console.WriteLine("Changing subscription...");
                easyUAClient.ChangeMonitoredItemSubscription(handle, 100);

                Console.WriteLine("Processing monitored item changed events for 10 seconds...");
                System.Threading.Thread.Sleep(10 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
예제 #11
0
            public static void Main1()
            {
                // Instantiate the client object
                // In order to use event pull, you must set a non-zero queue capacity upfront.
                var easyUAClient = new EasyUAClient {
                    PullDataChangeNotificationQueueCapacity = 1000
                };

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeDataChange(
                    "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    "nsu=http://test.org/UA/Data/;i=10853",
                    1000);

                Console.WriteLine("Processing data change events for 1 minute...");
                int endTick = Environment.TickCount + 60 * 1000;

                do
                {
                    EasyUADataChangeNotificationEventArgs eventArgs = easyUAClient.PullDataChangeNotification(2 * 1000);
                    if (eventArgs != null)
                    {
                        // Handle the notification event
                        Console.WriteLine(eventArgs);
                    }
                } while (Environment.TickCount < endTick);
            }
예제 #12
0
        public void SubscribeToUA(String[] args)
        {
            resultFile = new System.IO.StreamWriter(args[1], true);



            //getting the nodeids and loading them
            List <EasyUAMonitoredItemArguments> nodeList = readConf(args);



            EasyUAClient easyUAClient = new EasyUAClient();

            try
            {
                UAEndpointDescriptor ud = new UAEndpointDescriptor("opc.tcp://test-opc-ua.powerhub.dk:32402");
                EasyUAClient.EngineParameters.CertificateAcceptancePolicy.AcceptAnyCertificate = true;
                easyUAClient.MonitoredItemChanged += easyUAClient_MonitoredItemChanged;
                easyUAClient.SubscribeMultipleMonitoredItems(nodeList.ToArray <EasyUAMonitoredItemArguments>());
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.ToString());
            }

            while (true)
            {
                Thread.Sleep(100);
            }
        }
예제 #13
0
            public static void Main1()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.DataChangeNotification += easyUAClient_DataChangeNotification;

                Console.WriteLine("Subscribing...");
                int[] handleArray = easyUAClient.SubscribeMultipleMonitoredItems(new[]
                {
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10845", 1000),
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10853", 1000),
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10855", 1000)
                });

                Console.WriteLine("Getting monitored item arguments...");
                EasyUAMonitoredItemArguments monitoredItemArguments =
                    easyUAClient.GetMonitoredItemArguments(handleArray[2]);

                Console.WriteLine("NodeDescriptor: {0}", monitoredItemArguments.NodeDescriptor);
                Console.WriteLine("SamplingInterval: {0}", monitoredItemArguments.MonitoringParameters.SamplingInterval);
                Console.WriteLine("PublishingInterval: {0}", monitoredItemArguments.SubscriptionParameters.PublishingInterval);

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
예제 #14
0
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain attribute data. By default, the Value attributes of the nodes will be read.
                UAAttributeDataResult[] attributeDataResultArray = easyUAClient.ReadMultiple(new[]
                {
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10845"),
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853"),
                    new UAReadArguments("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10855")
                });

                // Display results
                foreach (UAAttributeDataResult attributeDataResult in attributeDataResultArray)
                {
                    Console.WriteLine("AttributeData: {0}", attributeDataResult.AttributeData);
                }

                // Example output:
                //
                //AttributeData: 51 {System.Int16} @11/6/2011 1:49:19 PM @11/6/2011 1:49:19 PM; Good
                //AttributeData: -1993984 {System.Single} @11/6/2011 1:49:19 PM @11/6/2011 1:49:19 PM; Good
                //AttributeData: Yellow% Dragon Cat) White Blue Dog# Green Banana- {System.String} @11/6/2011 1:49:19 PM @11/6/2011 1:49:19 PM; Good
            }
예제 #15
0
파일: opc.cs 프로젝트: fr830/KepView
        // GET api/<controller>
        // GET api/<controller>/5
        public object Get([FromUri] string[] path, string query = null)
        {
            var server = ConfigurationManager.AppSettings["opc-server"];

            using (var client = new EasyUAClient())
            {
                UANodeElementCollection nodes = new UANodeElementCollection();
                path = path.Where(p => p != null).ToArray();             //.FirstOrDefault()?.Split('/');

                var nodePath = new List <UANodeElement>();
                if (!path.Any())
                {
                    nodes = client.BrowseObjects(server);
                }
                else
                {
                    nodePath = GetNode(server, client, path, null).ToList();
                    if (!nodePath.Any())
                    {
                        return(null);
                    }
                    nodes = client.BrowseVariables(server, nodePath.Last());
                }


                return(new { path = path.Select((p, i) => new {
                        browseName = p,
                        node = NodeReturn(nodePath.ElementAtOrDefault(i))
                    }),
                             children = nodes.Select(NodeReturn) });
            }
        }
            public static void Overload2()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain objects under "Server" node
                UANodeElementCollection nodeElementCollection = easyUAClient.BrowseObjects(
                    "http://opcua.demo-this.com:51211/UA/SampleServer", // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    UAObjectIds.Server);

                // Display results
                foreach (UANodeElement nodeElement in nodeElementCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId);
                    Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName);
                }

                // Example output:
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2268
                //nodeElement.DisplayName: ServerCapabilities
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2274
                //nodeElement.DisplayName: ServerDiagnostics
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2295
                //nodeElement.DisplayName: VendorServerInfo
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2296
                //nodeElement.DisplayName: ServerRedundancy
            }
            public static void Main1()
            {
                // Instantiate the client object
                // In order to use event pull, you must set a non-zero queue capacity upfront.
                var easyUAClient = new EasyUAClient {
                    PullEventNotificationQueueCapacity = 1000
                };

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeEvent(
                    "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                    UAObjectIds.Server,
                    1000);

                Console.WriteLine("Processing event notifications for 30 seconds...");
                int endTick = Environment.TickCount + 30 * 1000;

                do
                {
                    EasyUAEventNotificationEventArgs eventArgs = easyUAClient.PullEventNotification(2 * 1000);
                    if (eventArgs != null)
                    {
                        // Handle the notification event
                        Console.WriteLine(eventArgs);
                    }
                } while (Environment.TickCount < endTick);
            }
예제 #18
0
파일: opc.cs 프로젝트: fr830/KepView
        static IEnumerable <UANodeElement> GetNode(string server, EasyUAClient client, IEnumerable <string> path, IEnumerable <UANodeElement> currentNodes)
        {
            var _currentNodes = currentNodes ?? new List <UANodeElement>();

            if (!path.Any())
            {
                return(currentNodes);
            }
            UANodeElementCollection nodes = new UANodeElementCollection();

            if (!_currentNodes.Any())
            {
                nodes = client.BrowseObjects(server);
            }
            else
            {
                nodes = client.BrowseVariables(server, currentNodes.Last());
            }
            var node = nodes.SingleOrDefault(n => n.BrowseName.Name == path.First());

            if (node != null)
            {
                return(GetNode(server, client, path.Skip(1), _currentNodes.Concat(new List <UANodeElement> {
                    node
                })));
            }
            return(new List <UANodeElement>());
        }
예제 #19
0
        public void SubscribeToUA(String[] args)
        {
            resultFile = new System.IO.StreamWriter(args[1], true);

            //getting the nodeids and loading them
            List<EasyUAMonitoredItemArguments> nodeList = readConf(args);

            EasyUAClient easyUAClient = new EasyUAClient();
            try
            {

                UAEndpointDescriptor ud = new UAEndpointDescriptor("opc.tcp://test-opc-ua.powerhub.dk:32402");
                EasyUAClient.EngineParameters.CertificateAcceptancePolicy.AcceptAnyCertificate = true;
                easyUAClient.MonitoredItemChanged += easyUAClient_MonitoredItemChanged;
                easyUAClient.SubscribeMultipleMonitoredItems(nodeList.ToArray <EasyUAMonitoredItemArguments>());
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.ToString());
            }

            while (true)
            {
                Thread.Sleep(100);
            }
        }
            public static void Main1()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.DataChangeNotification += easyUAClient_DataChangeNotification;

                Console.WriteLine("Subscribing...");
                int[] handleArray = easyUAClient.SubscribeMultipleMonitoredItems(new[]
                {
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10845", 1000),
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10853", 1000),
                    new EasyUAMonitoredItemArguments(null, "http://opcua.demo-this.com:51211/UA/SampleServer",
                                                     "nsu=http://test.org/UA/Data/;i=10855", 1000)
                });

                Console.WriteLine("Processing monitored item changed events for 10 seconds...");
                System.Threading.Thread.Sleep(10 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeMultipleMonitoredItems(handleArray);

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
            public static void Overload2()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain properties under "Server" node
                UANodeElementCollection nodeElementCollection = easyUAClient.BrowseProperties(
                    "http://opcua.demo-this.com:51211/UA/SampleServer", // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    UAObjectIds.Server);

                // Display results
                foreach (UANodeElement nodeElement in nodeElementCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId);
                    Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName);
                }

                // Example output:
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2254
                //nodeElement.DisplayName: ServerArray
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2255
                //nodeElement.DisplayName: NamespaceArray
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2267
                //nodeElement.DisplayName: ServiceLevel
                //
                //nodeElement.NodeId: nsu=http://opcfoundation.org/UA/;i=2994
                //nodeElement.DisplayName: Auditing            }
            }
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Modify value of a node
                easyUAClient.WriteValue(
                    "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    "nsu=http://test.org/UA/Data/;i=10221",
                    12345);
            }
예제 #23
0
 static void UaRxxWriter(XElement tag, object value)
 {
     using (var uaClient = new EasyUAClient())
     {
         uaClient.WriteValue(
             new UAWriteValueArguments(
                 GetElementAttribute(tag, "ua", "endpoint"),
                 $"ns=2;s={tag.Parent.Attribute("name").Value}.{ tag.Attribute("node").Value}",
                 value
                 )
             );
     }
 }
예제 #24
0
            public static void Overload1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain value of a node
                object value = easyUAClient.ReadValue(
                    "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    "nsu=http://test.org/UA/Data/;i=10853");

                // Display results
                Console.WriteLine("value: {0}", value);
            }
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Modify value of a node
                easyUAClient.WriteMultipleValues(new[]
                {
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;i=10221", 23456),
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;i=10226", 2.34567890),
                    new UAWriteValueArguments("http://opcua.demo-this.com:51211/UA/SampleServer",
                                              "nsu=http://test.org/UA/Data/;i=10227", "ABC")
                });
            }
예제 #26
0
 //writes a value to a tag as defined by an XElement
 static Func <object, object> WriteValue(XElement xElement)
 {
     return(value =>
     {
         using (var uaClient = new EasyUAClient())
         {
             uaClient.WriteValue(
                 new UAWriteValueArguments(
                     GetElementAttribute(xElement, "ua", "endpoint"),
                     $"ns=2;s={xElement.Attribute("node").Value}",
                     value
                     )
                 );
             return value;
         };
     });
 }
예제 #27
0
 //writes a value to a tag as defined by an XElement
 static Func<object, object> WriteValue(XElement xElement)
 {
     return value =>
     {
         using (var uaClient = new EasyUAClient())
         {
             uaClient.WriteValue(
                 new UAWriteValueArguments(
                    GetElementAttribute(xElement, "ua", "endpoint"),
                    $"ns=2;s={xElement.Attribute("node").Value}",
                    value
                 )
             );
             return value;
         };
     };
 }
예제 #28
0
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain collection of application elements
                UAApplicationElementCollection applicationElementCollection =
                    easyUAClient.DiscoverServersOnNetwork("opcua.demo-this.com");

                // Display results
                foreach (UAApplicationElement applicationElement in applicationElementCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("Server name: {0}", applicationElement.ServerName);
                    Console.WriteLine("Discovery URI string: {0}", applicationElement.DiscoveryUriString);
                    Console.WriteLine("Server capabilities: {0}", applicationElement.ServerCapabilities);
                }
            }
            public static void Overload1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain collection of server elements
                UAApplicationElementCollection applicationElementCollection = easyUAClient.DiscoverServers("opcua.demo-this.com");

                // Display results
                foreach (UAApplicationElement applicationElement in applicationElementCollection)
                {
                    Console.WriteLine("applicationElementCollection[\"{0}\"].ApplicationUriString: {1}",
                                      applicationElement.DiscoveryUriString, applicationElement.ApplicationUriString);
                }

                // Example output:
                // applicationElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server
                // applicationElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server
            }
예제 #30
0
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain nodes under "Server" node
                UANodeElementCollection nodeElementCollection = easyUAClient.BrowseNodes(
                    "http://opcua.demo-this.com:51211/UA/SampleServer", // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                    UAObjectIds.Server,
                    new UABrowseParameters(UANodeClass.All, new [] { UAReferenceTypeIds.References }));

                // Display results
                foreach (UANodeElement nodeElement in nodeElementCollection)
                {
                    Debug.Assert(nodeElement != null);
                    Console.WriteLine();
                    Console.WriteLine("nodeElement.NodeId: {0}", nodeElement.NodeId);
                    Console.WriteLine("nodeElement.DisplayName: {0}", nodeElement.DisplayName);
                }
            }
예제 #31
0
            public static void Events()
            {
                // Instantiate the client object and hook events
                var easyUAClient = new EasyUAClient();

                easyUAClient.EventNotification += easyUAClient_EventNotification;

                Console.WriteLine("Subscribing...");
                easyUAClient.SubscribeMultipleMonitoredItems(new[]
                {
                    new EasyUAMonitoredItemArguments("firstState",
                                                     "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                                                     UAObjectIds.Server,
                                                     new UAMonitoringParameters(1000, new UAEventFilterBuilder(
                                                                                    UAFilterElements.GreaterThanOrEqual(UABaseEventObject.Operands.Severity, 500),
                                                                                    UABaseEventObject.AllFields)))
                    {
                        AttributeId = UAAttributeId.EventNotifier
                    },
                    new EasyUAMonitoredItemArguments("secondState",
                                                     "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer",
                                                     UAObjectIds.Server,
                                                     new UAMonitoringParameters(2000, new UAEventFilterBuilder(
                                                                                    UAFilterElements.Equals(
                                                                                        UABaseEventObject.Operands.SourceNode,
                                                                                        new UANodeId("nsu=http://opcfoundation.org/Quickstarts/AlarmCondition;ns=2;s=1:Metals/SouthMotor")),
                                                                                    UABaseEventObject.AllFields)))
                    {
                        AttributeId = UAAttributeId.EventNotifier
                    },
                });

                Console.WriteLine("Processing event notifications for 30 seconds...");
                System.Threading.Thread.Sleep(30 * 1000);

                Console.WriteLine("Unsubscribing...");
                easyUAClient.UnsubscribeAllMonitoredItems();

                Console.WriteLine("Waiting for 5 seconds...");
                System.Threading.Thread.Sleep(5 * 1000);
            }
            public static void Main1()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                try
                {
                    // Modify data of a node's attribute
                    easyUAClient.Write(
                        "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                        "nsu=http://test.org/UA/Data/;i=10221",
                        new UAAttributeData(12345, UASeverity.GoodOrSuccess, DateTime.UtcNow));
                    // Writing server timestamp is not supported by the sample server.

                    // The UA Test Server does not support this, and therefore a failure will occur.
                }
                catch (UAException uaException)
                {
                    Console.WriteLine("Failure: {0}", uaException.GetBaseException().Message);
                }
            }
            public static void ReadValue()
            {
                // Instantiate the client object
                var easyUAClient = new EasyUAClient();

                // Obtain the value, indicating that just the elements 2 to 4 should be returned
                object value = easyUAClient.ReadValue(
                    new UAReadArguments(
                        "http://opcua.demo-this.com:51211/UA/SampleServer",   // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
                        "nsu=http://test.org/UA/Data/;ns=2;i=10305",
                        UAIndexRangeList.OneDimension(2, 4)));

                // Cast to typed array
                var arrayValue = (Int32[])value;

                // Display results
                for (int i = 0; i < 3; i++)
                {
                    Console.WriteLine("arrayValue[{0}]: {1}", i, arrayValue[i]);
                }
            }
예제 #34
0
        // ua simulator hard coded + hard coded config
        static void UaRxSim()
        {

            Clear();
            using (new ConsoleColourer(Yellow, Black))
                WriteLine("reactive UA simulation! Press a key to quit.");
            

            var uaClient = new EasyUAClient();

            var rxUaSubscription = UAMonitoredItemChangedObservable.Create<int>(new EasyUAMonitoredItemArguments(
               "uaState",
               "opc.tcp://127.0.0.1:49320/",
               "ns=2;s=Channel1.Device1.Tag2",
               0)
             )
             .Subscribe(val =>
             {
                 WriteLine(string.Format("wrote {0} to {1} on {2} being {3}", val.AttributeData.Value, "ns=2;s=Channel1.Device1.Tag1", "ns=2;s=Channel1.Device1.Tag2", val.AttributeData.Value));
                 uaClient.WriteValue(
                     new UAWriteValueArguments(
                         "opc.tcp://127.0.0.1:49320/",
                         "ns=2;s=Channel1.Device1.Tag1",
                         val.AttributeData.Value
                     )
                 );

             }
         );

            var key = ReadKey();

            rxUaSubscription.Dispose();
            uaClient.Dispose();
        }