HoloLens无法连接到OpcUa服务器

时间:2019-05-13 12:12:14

标签: c# unity3d hololens opc-ua

我想通过HoloLens上的APP连接到OpcUa服务器,并读取节点的数据。它可以在Unity上运行并且工作正常,但无法连接到HoloLens中的OpcUa服务器。我使用OpcUaHelper插件,该插件具有一个简单的OpcUa客户端,并支持.Net Core和.Net Standard 2.0。

Unity的设置为:

脚本运行时版本:.Net 4.X等效

脚本后端:IL2CPP

Api兼容性级别:.Net 4.X

我的代码如下所示。 有人知道原因是什么吗? 还是有人试图在HoloLens中连接Opc Ua服务器?

我正在使用的软件版本为:

1.Unity 2018 3.11f

2。混合现实工具包v2.0.0 RC1

3.Visual Studio 2017

using System;
using UnityEngine;
using UnityEngine.UI;
using Microsoft.MixedReality.Toolkit.Input;
using OpcUaHelper;
using Opc.Ua;
using System.Collections;
using System.Collections.Generic;

public void OpcUaConnector()
    {
        OpcUaClient m_OpcUaClient = new OpcUaClient();
        //m_OpcUaClient.UserIdentity = new UserIdentity("user", "password");
        string OpcUa_Test = "opc.tcp://118.24.36.220:62547/DataAccessServer";
        m_OpcUaClient.ConnectServer(string.Format("{0}", OpcUa_Test));
        try
        {
            //Read the same type of data from multiple nodes

            List<NodeId> nodeIds = new List<NodeId>();
            nodeIds.Add(new NodeId("ns=2;s=Machines/Machine A/Name"));
            nodeIds.Add(new NodeId("ns=2;s=Machines/Machine B/Name"));
            nodeIds.Add(new NodeId("ns=2;s=Machines/Machine C/Name"));
            List<DataValue> dataValues = m_OpcUaClient.ReadNodes(nodeIds.ToArray());
            AnlagenName_A.text = string.Format("{0}", dataValues[0]);
            AnlagenName_B.text = string.Format("{0}", dataValues[1]);
            AnlagenName_C.text = string.Format("{0}", dataValues[2]);

            //foreach (string tag in Tags)
            //{
            //    string value = m_OpcUaClient.ReadNode<string>(tag);
            //}
        }

        //    //Read data from a single node
        //    //string value = m_OpcUaClient.ReadNode<string>("ns=2;s=Machines/Machine B/Name");
        //    //Console.WriteLine("{0}", value);
        //    //Console.ReadKey();
        //}
        catch
        {
            Debug.Log("Connected Failed");
        }
    }

我希望成功连接到OpcUa服务器并读取节点数据。

0 个答案:

没有答案