この方法で OPC UA サーバーを起動しようとしました: http://documentation.unified-automation.com/uasdkdotnet/2.1.0/html/L3ServerTutGSLess01.html
ApplicationLicenseManager.AddProcessLicenses(Assembly.GetExecutingAssembly(), "License.lic");
MyServerManager server = new MyServerManager();
ApplicationInstance.Default.Start(server, null, server); //Start the server
次のエラーが表示され
ApplicationInstance.Default.Start(server, null, server)"
ます: System.NullReferenceException: オブジェクト参照がオブジェクト インスタンスに設定されていません。UnifiedAutomation.UaServer.ServerSettings..ctor (ApplicationInstance アプリケーション) で UnifiedAutomation.UaServer.ServerManager.OnServerStarting (ApplicationInstance アプリケーション) で UnifiedAutomation.UaBase.ServerBase.Start (ApplicationInstance アプリケーション) で UnifiedAutomation.UaServer.ServerManager.Start (ApplicationInstance アプリケーション) でUnifiedAutomation.UaBase.ApplicationInstance.Start (ServerBase サーバー、WaitCallback コールバック、オブジェクト userData) は、TapakoServerStarter.cs: 行の VeitsServer.TapakoServerStarter.StartAkomiServer (IDevice testDeviceToLink) にあります。39 at Implementationstests.OpcUaServerTest.ServerShouldRun() in OpcUaServerTest.cs: 行 44
から内部的に開始された場合、同じコードは正常に機能しMain()
ます。しかし、同じプロジェクト マップ (テスト プロジェクトなど) 内の外部プロジェクトで OpcUaServerStarter を呼び出そうとするとすぐに、NullReferenceException が表示されます。
プロジェクトを .dll としてコンパイルする必要があるか、参照を追加する必要がありますか? または、何らかの理由で、の可視性がMyServerManager
OPC internal
-UA Web サイトにあるためです。
MyServerManager
クラス (作業に対する唯一の重要な違いはカプセル化MyServerManager
である可能性があります):public
public class MyServerManager : ServerManager
{
private NodeManager _nodeManager;
private ObjectModel _objectModel;
/// <summary>
/// Method is called (from SDK) when NodeManager starts up.
/// </summary>
/// <param name="rootNodeManager"></param>
protected override void OnRootNodeManagerStarted(RootNodeManager rootNodeManager)
{
Console.WriteLine("Creating Node Manager.");
_nodeManager = new NodeManager(this);
_nodeManager.Startup();
_objectModel = new ObjectModel(_nodeManager);
}
/// <summary>
/// Creates an internal model of the given device and automatically creates nodes and callbacks
/// </summary>
/// <param name="device">AKOMI Device that will be shown on the Server</param>
public void LinkObjectToModel(IDevice device)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Device: " + device.GetType().Name);
_objectModel.RegisterAkomiDevice(device, 0, 4);
}
/// <summary>
/// Creates an internal model of the given entity and automatically creates nodes and callbacks
/// </summary>
public void LinkObjectToModel(object entity, string name, int curLvl, int maxLvl)
{
if (_objectModel == null)
{
throw new NullReferenceException("hv: objectModel is not initilized, try starting the server first.");
}
Console.WriteLine("Register Entity: " + name);
_objectModel.RegisterEntity(entity, name, curLvl, maxLvl);
}
}
ありがとう!