Closed fsodano1 closed 1 year ago
@fsodano1 Try if it works by slightly changing the following method to this:
private void ImportXml(IDictionary<NodeId, IList<IReference>> externalReferences, string resourcepath)
{
try
{
NodeStateCollection predefinedNodes = new NodeStateCollection();
using (Stream stream = new FileStream(resourcepath, FileMode.Open))
{
Opc.Ua.Export.UANodeSet nodeSet = Opc.Ua.Export.UANodeSet.Read(stream);
nodeSet.Import(SystemContext, predefinedNodes);
// Detect new namespace uris imported from file
List<string> newNamespaceUris = new List<string>();
if (nodeSet.NamespaceUris != null && SystemContext.NamespaceUris != null)
{
for (int ii = 0; ii < nodeSet.NamespaceUris.Length; ii++)
{
SystemContext.NamespaceUris.GetIndexOrAppend(nodeSet.NamespaceUris[ii]);
newNamespaceUris.Add(nodeSet.NamespaceUris[ii]);
}
}
// Add new namespace uris to current node manager
if (newNamespaceUris.Count > 0)
{
List<string> allNamespaceUris = new List<string>();
allNamespaceUris.AddRange(NamespaceUris);
allNamespaceUris.AddRange(newNamespaceUris);
SetNamespaces(allNamespaceUris.ToArray());
foreach (var namespaceUri in newNamespaceUris)
{
Server.NodeManager.RegisterNamespaceManager(namespaceUri, this);
}
}
// Add new imported nodes to the predefined nodes collection
for (int ii = 0; ii < predefinedNodes.Count; ii++)
{
AddPredefinedNode(SystemContext, predefinedNodes[ii]);
}
// Ensure the reverse refernces exist.
AddReverseReferences(externalReferences);
}
}
}
Maybe we can support loading of Nodeset2 files with the next wave of complex type improvements.
@fsodano1 ModelCompiler has now support to generate code from Nodeset2. Here is a sample so you get the idea:
@echo off
setlocal
REM if docker is not available, ensure the Opc.Ua.ModelCompiler.exe is in the PATH
set MODELCOMPILER=Opc.Ua.ModelCompiler.exe
set MODELCOMPILERIMAGE=ghcr.io/opcfoundation/ua-modelcompiler:latest
set MODELROOT=.
echo pull latest modelcompiler from github container registry
docker pull %MODELCOMPILERIMAGE%
IF ERRORLEVEL 1 (
:nodocker
Echo The docker command to download ModelCompiler failed. Using local PATH instead to execute ModelCompiler.
) ELSE (
Echo Successfulled pulled the latest docker container for ModelCompiler.
set MODELROOT=/model
set MODELCOMPILER=docker run -v "%CD%:/model" -it --rm --name ua-modelcompiler %MODELCOMPILERIMAGE%
)
echo Building DI from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -o2 "%MODELROOT%/DI"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building IA from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.IA.NodeSet2.xml,Opc.Ua.IA,OpcUaIA" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -o2 "%MODELROOT%/IA"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building Machinery from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.Machinery.NodeSet2.xml,Opc.Ua.Machinery,OpcUaMachinery" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -o2 "%MODELROOT%/Machinery"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building Machinery.Examples from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.Machinery.Examples.NodeSet2.xml,Opc.Ua.Machinery.Examples,OpcUaMachineryExamples" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -d2 "%MODELROOT%/Opc.Ua.Machinery.NodeSet2.xml,Opc.Ua.Machinery,OpcUaMachinery" -o2 "%MODELROOT%/Machinery.Examples"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building Robotics from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.Robotics.NodeSet2.xml,Opc.Ua.Robotics,OpcUaRobotics" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -o2 "%MODELROOT%/Robotics"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building MachineTool from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.MachineTool.NodeSet2.xml,Opc.Ua.MachineTool,OpcUaMachineTool" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -d2 "%MODELROOT%/Opc.Ua.IA.NodeSet2.xml,Opc.Ua.IA,OpcUaIA" -d2 "%MODELROOT%/Opc.Ua.Machinery.NodeSet2.xml,Opc.Ua.Machinery,OpcUaMachinery" -o2 "%MODELROOT%/MachineTool"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building Woodworking from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.Woodworking.NodeSet2.xml,Opc.Ua.Woodworking,OpcUaWoodworking" -d2 "%MODELROOT%/Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,OpcUaDI" -d2 "%MODELROOT%/Opc.Ua.Machinery.NodeSet2.xml,Opc.Ua.Machinery,OpcUaMachinery" -o2 "%MODELROOT%/Woodworking"
IF %ERRORLEVEL% EQU 0 echo Success!
echo Building MachineVision from Nodeset2
%MODELCOMPILER% compile -version v104 -d2 "%MODELROOT%/Opc.Ua.MachineVision.NodeSet2.xml,Opc.Ua.MachineVision,OpcUaMachineVision" -o2 "%MODELROOT%/MachineVision"
IF %ERRORLEVEL% EQU 0 echo Success!
Closing this issue. Feel free to file a new one in Discussion-Q&A if there is more question.
Type of Issue
Describe the Issue
How to create an address space using 4 xml nodeset2 files
To Reproduce
Hello everyone, I need to create an address spaceusing 4 xml nodeset2 files:
"Opc.Ua.Woodworking.NodeSet2.xml",
I tried to create a derived CustomNodeManager2 class and import listed nodesets in the order shown respecting all dependencies. This is my code:
I'm not able to see my machines when I try to connect to the server. What am I doing wrong? I am attaching the 4 files. Thanks for the help.
Screenshots Please note client cannot see my machines:
Expected behaviour: