[英]Browsing with OPC Foundation Java Stack
i hope someone can help me. 我希望有一个人可以帮助我。
I'm writing a OPC-UA client in java and I can browse only the first node. 我正在用Java编写OPC-UA客户端,并且只能浏览第一个节点。
ResponseHeader=ResponseHeader
Timestamp=05/11/18 09:38:42.3063457 GMT
RequestHandle=0
ServiceResult=GOOD (0x00000000) ""
ServiceDiagnostics=Diagnostic Info:
StringTable=class java.lang.String[0]
AdditionalHeader=null
Results=class org.opcfoundation.ua.core.BrowseResult[1]
[0]=BrowseResult
StatusCode=GOOD (0x00000000) ""
ContinuationPoint=null
References=class org.opcfoundation.ua.core.ReferenceDescription[2]
[0]=ReferenceDescription
ReferenceTypeId=i=35
IsForward=true
NodeId=nsu=http%3A%2F%2Fopcfoundation.org%2FUA%2F;i=2253
BrowseName=Server
DisplayName=Server
NodeClass=NodeClass
value=1
name=Object
ordinal=1
TypeDefinition=nsu=http%3A%2F%2Fopcfoundation.org%2FUA%2F;i=2004
[1]=ReferenceDescription
ReferenceTypeId=i=35
IsForward=true
NodeId=ns=2;s=WRT
BrowseName=2:WRT
DisplayName=WRT
NodeClass=NodeClass
value=1
name=Object
ordinal=1
TypeDefinition=nsu=http%3A%2F%2Fopcfoundation.org%2FUA%2F;i=58
DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0]
I would see the others arms of the tree. 我会看到其他人的手臂。 But the second browsing return null.
但是第二次浏览返回null。
2018-05-11 11:22:56,190 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - i = 0 x= 0
2018-05-11 11:22:56,191 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - BrowseName Server
2018-05-11 11:22:56,191 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - NodeId nsu=http%3A%2F%2Fopcfoundation.org%2FUA%2F;i=2253
2018-05-11 11:22:56,191 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - DisplayName Server
2018-05-11 11:22:56,192 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - BrowseResponse
ResponseHeader=ResponseHeader
Timestamp=05/11/18 09:22:56.1916234 GMT
RequestHandle=0
ServiceResult=GOOD (0x00000000) ""
ServiceDiagnostics=Diagnostic Info:
StringTable=class java.lang.String[0]
AdditionalHeader=null
Results=class org.opcfoundation.ua.core.BrowseResult[1]
[0]=BrowseResult
StatusCode=GOOD (0x00000000) ""
ContinuationPoint=null
References=class org.opcfoundation.ua.core.ReferenceDescription[0]
DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0]
2018-05-11 11:22:56,192 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - i = 0 x= 1
2018-05-11 11:22:56,192 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - BrowseName 2:WRT
2018-05-11 11:22:56,192 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - NodeId ns=2;s=WRT
2018-05-11 11:22:56,192 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - DisplayName WRT
2018-05-11 11:22:56,193 [Component Resolve Thread (Bundle 6)] DEBUG c.a.o.u.ClientService - BrowseResponse
ResponseHeader=ResponseHeader
Timestamp=05/11/18 09:22:56.1931274 GMT
RequestHandle=0
ServiceResult=GOOD (0x00000000) ""
ServiceDiagnostics=Diagnostic Info:
StringTable=class java.lang.String[0]
AdditionalHeader=null
Results=class org.opcfoundation.ua.core.BrowseResult[1]
[0]=BrowseResult
StatusCode=GOOD (0x00000000) ""
ContinuationPoint=null
References=class org.opcfoundation.ua.core.ReferenceDescription[0]
DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0]
here my code to browse for 2 levels: 在这里,我的代码可以浏览2个级别:
public void browse(NodeId nodeId) throws ServiceFaultException, ServiceResultException {
BrowseDescription browse = new BrowseDescription();
browse.setNodeId(nodeId);
browse.setBrowseDirection(BrowseDirection.Forward);
browse.setIncludeSubtypes(true);
browse.setNodeClassMask(NodeClass.Object, NodeClass.Variable, NodeClass.View);
browse.setResultMask(BrowseResultMask.All);
BrowseResponse browseResponse = null;
int k = 1;
try {
browseResponse = mySession.Browse(null, null, null, browse);
logger.debug(browseResponse.toString());
} catch (ServiceResultException e) {
logger.error("Exception", e);
}
BrowseResult[] browseResult = browseResponse.getResults();
for (int i = 0; i < browseResult.length; i++) {
ReferenceDescription[] referenceDescription = browseResult[i].getReferences();
for (int x = 0; x < referenceDescription.length; x++) {
logger.debug("i = " + i + " x= " + x);
logger.debug("BrowseName " + referenceDescription[x].getBrowseName());
logger.debug("NodeId " + referenceDescription[x].getNodeId());
logger.debug("DisplayName " + referenceDescription[x].getDisplayName());
BrowseDescription browse1 = new BrowseDescription();
browse1.setNodeId(referenceDescription[x].getReferenceTypeId().ID);
browse1.setBrowseDirection(BrowseDirection.Forward);
browse1.setIncludeSubtypes(true);
browse1.setReferenceTypeId(referenceDescription[x].getReferenceTypeId().ID);
browse1.setNodeClassMask(NodeClass.Object, NodeClass.Variable, NodeClass.View, NodeClass.Method, NodeClass.ObjectType, NodeClass.VariableType, NodeClass.ReferenceType, NodeClass.DataType);
browse1.setResultMask(BrowseResultMask.All);
BrowseResponse browseResponse1 = null;
try {
browseResponse1 = mySession.Browse(null, null, null, browse1);
if (browseResponse1 != null) {
logger.debug(browseResponse1.toString());
}
} catch (ServiceResultException e) {
logger.error("Exception", e);
}
}
}
}
Another client has shown others folders after WRT forlder. WRT fordder之后,另一个客户显示了其他文件夹。
browse1.setNodeId(referenceDescription[x].getReferenceTypeId().ID);
This is certainly not what you want. 这当然不是您想要的。 You should be browsing
referenceDescription[x].getNodeId()
in your subsequent browses. 您应该在随后的浏览中浏览
referenceDescription[x].getNodeId()
。
You need a NamespaceTable to do the conversion properly. 您需要一个NamespaceTable才能正确进行转换。 Use
采用
NamespaceTable table = NamespaceTable.getDefaultInstance();
browse1.setNodeId(table.toNodeId(referenceDescription[x].getNodeId()));
as reported here https://github.com/OPCFoundation/UA-Java/issues/140 如此处报告https://github.com/OPCFoundation/UA-Java/issues/140
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.