convertersystems / opc-ua-client

Visualize and control your enterprise using OPC Unified Architecture (OPC UA) and Visual Studio.
MIT License
403 stars 119 forks source link

Empty Value from a node from Siemens PLC #262

Closed ShiddhamSharma closed 1 year ago

ShiddhamSharma commented 1 year ago

Hi, I am trying to read and write a value from a tag in my PLC. Now I have tried opcua in python and am able to read and write the node but when I try opc-ua-client i am receivng empty values. I don't understand the issue but it might be because I am giving wrong Node ID. The C# code:

var channel = new ClientSessionChannel(
                clientDescription,
                null, // no x509 certificates
                new AnonymousIdentity(), // no user identity
                "opc.tcp://192.168.0.1:4840", // the public endpoint of a server at opcua.rocks.
                SecurityPolicyUris.None); // no encryption

            await channel.OpenAsync();
            // build a ReadRequest. See 'OPC UA Spec Part 4' paragraph 5.10.2
            var readRequest = new ReadRequest {
                // set the NodesToRead to an array of ReadValueIds.
                NodesToRead = new[] {
                    // construct a ReadValueId from a NodeId and AttributeId.
                    new ReadValueId {
                        // you can parse the nodeId from a string.
                        // e.g. NodeId.Parse("ns=2;s=Demo.Static.Scalar.Double")
                        NodeId = NodeId.Parse("ns=3;s=Alarms.Data[2].Message"),
                        // variable class nodes have a Value attribute.
                        AttributeId = AttributeIds.Value
                    }
                }
            };
            try
            {
                // send the ReadRequest to the server.
                var readResult = await channel.ReadAsync(readRequest);
                string val = readResult.Results[0].GetValueOrDefault<string>();
                MessageBox.Show(val, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

My Python Code: node = client.get_node('''ns=3;s="Alarms"."Data"[2]."Message"''')

ShiddhamSharma commented 1 year ago

So Parsing it as: NodeId.Parse("ns=3;s=\"Alarms\".\"Data\"[2].\"Message\"") solved it

awcullen commented 12 months ago

Great! I am glad it’s working.


From: ShiddhamSharma @.> Sent: Friday, November 17, 2023 3:35:49 AM To: convertersystems/opc-ua-client @.> Cc: Subscribed @.***> Subject: Re: [convertersystems/opc-ua-client] Empty Value from a node from Siemens PLC (Issue #262)

So Parsing it as: NodeId.Parse("ns=3;s=\"Alarms\".\"Data\"[2].\"Message\"") solved it

— Reply to this email directly, view it on GitHubhttps://github.com/convertersystems/opc-ua-client/issues/262#issuecomment-1815939652, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC2ZNGWYVCNXQMBKI4K3G4DYE4OWLAVCNFSM6AAAAAA7PNLZGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJVHEZTSNRVGI. You are receiving this because you are subscribed to this thread.Message ID: @.***>