Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPC UA How to read a datatype from the server

Tags:

opc

opc-ua

I can't seem to figure this one out:

Before writing to a tag I need to know what data type it is expecting(the value that mywrite function receives is always a string).

I realise you have to read the datatype from the server and here's my code to do so, but I'm at a loss as to how to use the information returned:

var nodesToRead = BuildReadValueIdCollection(node.DisplayName, Attributes.DataType);

                    DataValueCollection readResults;
                    DiagnosticInfoCollection diag;
                    _session.Read(
                        requestHeader: null,
                        maxAge: 0,
                        timestampsToReturn: TimestampsToReturn.Neither,
                        nodesToRead: nodesToRead,
                        results: out readResults,
                        diagnosticInfos: out diag);
                    var val = readResults[0];

What do I do with val to determine what the datatype is?

Do I use Val.Value or Val.WrappedValue or Val.WrappedValue.Value (whatever the difference is ?)

The tag I've been using to test has returned Val = "i=6".....

What is this referring to?

What datatype is "6" and

how do I convert val to something I can use.

Any help would be greatly appreciated.

Thanks

like image 750
Muckers Mate Avatar asked Oct 29 '25 14:10

Muckers Mate


1 Answers

Reading from the DataType attribute returns a NodeID of the OPC UA type. It can be one of the "standard" types defined in the OPC UA spec, or something specific to the server. The standard types reside in namespace 0, which is your case (as there is no "ns=..." part in the displayed Node ID), and "i=6" stands for Int32.

There are many types with pre-defined Node IDs, and you need to consult the OPC UA specs, or the nodeset files that come with the stacks/SDKs (e.g. Opc.Ua.NodeSet.xml), to figure out what they mean.

like image 110
ZbynekZ Avatar answered Nov 01 '25 13:11

ZbynekZ