Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Datatype return NodeId intead of Datatype #122

Closed
name024 opened this issue Jun 28, 2023 · 1 comment
Closed

Read Datatype return NodeId intead of Datatype #122

name024 opened this issue Jun 28, 2023 · 1 comment

Comments

@name024
Copy link

name024 commented Jun 28, 2023

First of all thanks for this great lib!
I have try to read the Datatype from a OPC UA-Variable using the Nuget Package and the OPC UA Client. My expectation is a datatype string like "Bool", "Int32", "String", etc. but instead of a datatype string i´ve get the nodeId.
I could not find my mistake. Can someone help?

` public (bool Sucess, string Datatype) ReadDatatype(string nodeId)
{
if (client is null)
return (false, "Not Connected");

    try
    {
        string Error = GetIdFromString(nodeId, out NodeId readNodeId);
        if (Error != "")
            return (false, Error);

        var readRes = client.Read(new ReadValueId[]
            {
                new ReadValueId(readNodeId, NodeAttribute.DataType, null, new QualifiedName(0, null))
            }, out DataValue[] dvs);

        if (readRes != StatusCode.Good)
            return (false, readRes.ToString());

        if (dvs[0].Value is null && dvs[0].ServerTimestamp is null && dvs[0].SourceTimestamp is null && dvs[0].StatusCode is null)
            return (false, "Read Error - exist NodeId?");

        return (true, dvs[0].Value.ToString() ?? "");
    }
    catch (Exception ex)
    {
        return (false, $"Error. {ex}");
    }
}`

image

@name024
Copy link
Author

name024 commented Jun 28, 2023

Found my bug.
If you read the Datatype you get the OPC UA "NodeId" which hold the Datatype information - not directly the Datatype.

@name024 name024 closed this as completed Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant