Использование OPC UA .NET для чтения значения Channel1.Device1.Tag1 с Kepserver

введите здесь описание изображения  введите описание изображения здесь Я использую образец NetCoreConsoleClient отсюда: https://github.com/OPCFoundation/UA-.NETStandardLibrary

Я настроил код и смог просмотреть весь сервер и получить такие значения, как временная метка, описание, тип данных и т. Д., Для каждого узла на сервере.

Для узла «Channel1.Device1.Tag1» я могу получить все свойства / vlaues (например, DataType, Address, Description), но я не получаю свойство, которое содержит фактическое значение «Tag1»

На Kepserver я заметил, что для «Channel1.Device.Tag1» нет никакого свойства с именем «Value», которое содержит фактическое значение тега.

Значение «Tag1» появляется, когда я использую «Быстрый клиент», предоставляемый KepServer.

Мне нужно каким-то образом получить значение «тега» с помощью моего собственного клиента.

Измененный фрагмент кода:

`Console.WriteLine("4 - Browse the OPC UA server namespace.");
        ReferenceDescriptionCollection references;
        Byte[] continuationPoint;

        references = session.FetchReferences(ObjectIds.ObjectsFolder);

        session.Browse(
            null,
            null,
           ObjectIds.ObjectsFolder,
            //ObjectIds.RootFolder,
            0u,
            BrowseDirection.Forward,
            ReferenceTypeIds.HierarchicalReferences,
            true,
            (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
            out continuationPoint,
            out references);

        Console.WriteLine(" DisplayName, BrowseName, NodeClass");
        foreach (var rd in references)
        {
            Console.WriteLine(" {0}, {1}, {2}", rd.DisplayName, rd.BrowseName, rd.NodeClass);
            ReferenceDescriptionCollection nextRefs;
            byte[] nextCp;
            session.Browse(
                null,
                null,
                ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris),
                0u,
                BrowseDirection.Forward,
                ReferenceTypeIds.HierarchicalReferences,
                true,
                (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
                out nextCp,
                out nextRefs);
            foreach (var nextRd in nextRefs)
            {
                Console.WriteLine("   + {0}, {1}, {2}", nextRd.DisplayName, nextRd.BrowseName, nextRd.NodeClass);
                ReferenceDescriptionCollection nextRefs1;
                byte[] nextCp1;
                session.Browse(
                   null,
                   null,
                   ExpandedNodeId.ToNodeId(nextRd.NodeId, session.NamespaceUris),
                   0u,
                   BrowseDirection.Forward,
                   ReferenceTypeIds.HierarchicalReferences,
                   true,
                   (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
                   out nextCp1,
                   out nextRefs1);
                foreach (var nextRd1 in nextRefs1)
                {
                    Console.WriteLine("   + {0}, {1}, {2}", nextRd1.DisplayName, nextRd1.BrowseName, nextRd1.NodeClass);
                    ReferenceDescriptionCollection nextRefs2;
                    byte[] nextCp2;
                   var res =  session.Browse(
                        null, null,
                        ExpandedNodeId.ToNodeId(nextRd1.NodeId, session.NamespaceUris), 0u, BrowseDirection.Forward,
                        ReferenceTypeIds.HierarchicalReferences, true,
                        (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method, out nextCp2, out nextRefs2);
                    double maxAge = 0; //Pick 0 millisecond old value directly from device not from the cache.
                    DataValueCollection results;
                    DiagnosticInfoCollection diagInfos;
                    ReadValueIdCollection readValueIds;
                    foreach (var nextRd2 in nextRefs2)
                    {
                        try
                        {
                            if (!nextRd2.NodeId.IsNull)
                            {
                                var node = ExpandedNodeId.ToNodeId(nextRd2.NodeId, session.NamespaceUris);
                                if (node != null)
                                {
                                    DataValue dv = session.ReadValue(node);
                                    ReferenceDescriptionCollection nextRefs3;
                                    byte[] nextCp3;
                                    var res1 = session.Browse(null, null,
                                           ExpandedNodeId.ToNodeId(nextRd2.NodeId, session.NamespaceUris), 0u, BrowseDirection.Forward,
                                           ReferenceTypeIds.HierarchicalReferences, true,
                                           (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method, out nextCp3, out nextRefs3);
                                    foreach (var nextRd3 in nextRefs3)
                                    {
                                        if (!nextRd3.NodeId.IsNull)
                                        {
                                            var node1 = ExpandedNodeId.ToNodeId(nextRd3.NodeId, session.NamespaceUris);
                                            if (node1 != null)
                                            {
                                                DataValue dv2 = session.ReadValue(node1);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (ServiceResultException srex)
                        {
                            //eat exception yum yum yum!
                        }
                        catch (Exception ex)
                        {

                            //eat exception yum yum yum!
                        }`

person Ashish Kumar Jaryal    schedule 24.04.2017    source источник
comment
Пожалуйста, объясните, что вы имеете в виду, я не могу получить значение ..... Какое поведение наблюдается?   -  person ZbynekZ    schedule 24.04.2017
comment
Я могу получить все свойства / значения всех узлов на сервере, а также для узла Channel1.Device1.Tag1 Я могу получить все свойства / vlaues (например, DataType, Address, Description), но я не получаю свойство, которое содержит фактическое значение Tag1   -  person Ashish Kumar Jaryal    schedule 24.04.2017


Ответы (2)


Попробовав образец кода, я нашел ответ.

Магическое заявление, которое дает значения:

DataValue dv1 = session.ReadValue ("ns = 2; s = Channel1.Device1.Tag1");

                foreach (var nextRd1 in nextRefs1)
                {
                    Console.WriteLine("   + {0}, {1}, {2}", nextRd1.DisplayName, nextRd1.BrowseName, nextRd1.NodeClass);
                    try
                    {
                        var _node = ExpandedNodeId.ToNodeId(nextRd1.NodeId, session.NamespaceUris);
                        DataValue dv2 = session.ReadValue(_node);
                    }
person Ashish Kumar Jaryal    schedule 24.04.2017
comment
Было там сделано это. Знай это чувство: D - person Anttu; 13.01.2021

В этом примере используется: https://github.com/hylasoft-usa/h-opc#documentation

Вероятно, вам просто нужно выяснить тип значения, которое вам нужно получить.

public void ReadValueFromOPC(string host, string userName, string password)
    {
        var options = new UaClientOptions
        {
            UserIdentity = new Opc.Ua.UserIdentity(
                userName,
                password)
        };

        using (var client = new UaClient(new Uri("opc.tcp://" +
            host), options))
        {

            client.Connect();
            var node = client.FindNode("SomeTag.SomeChildTag");

            // Find out what the type is before you try to get the value
            Type type = client.GetDataType(node.Tag);
            // If you find out it's a UInt32 then you use it.
            var value = client.Read<UInt32>(node.Tag).Value;

        }
    }
person dangalg    schedule 30.05.2018