Milo과 예제 서버 및 클라이언트를 사용하고 있습니다. 서버에 노드를 추가하고 있지만 EuInformation
(단위 및 설명)을 추가하는 방법을 알 수 없습니다. 나는 ExtensionObject
을 사용하려고 생각했지만 EuInformation
은 Serializable
을 구현하지 않았기 때문에 ExtensionObject
에 전달하는 방법을 모르겠습니다. 또한 클라이언트 측에서 네임 스페이스 ID와 URI를 얻을 수있는 방법을 알고 싶습니다. 지금까지 나는 클래스에 액세스 할 수있게 정적으로 설정했습니다.Java Milo OPC-UA 노드 추가
서버 측에서 AddNodes를 구현했습니다. 노드를 추가하고 노드를 읽고 노드에 쓸 수 있습니다. 는 여기에 내가 클라이언트 측에서 뭘하는지입니다 : 내가 뭔가를 일 케빈 헤론의 대답의 도움으로
// Should somehow get the namespace ID and namespace dynamically.
// Maybe by iterating through all nodes??
ExpandedNodeId parentNodeId = new ExpandedNodeId(
new nodeId(2,DatatypeNamespace.NODE_IDENTIFIER),
datatypeNamespace.NAMESPACE_URI, 0);
NodeId referenceTypeId = Identifiers.String;
// Define the new node.
ExpandedNodeId requestedNewNodeId = new ExpandedNodeId(new NodeId(2, "NewNode"),
DatatypeNamespace.NAMESPACE_URI, 0);
QualifiedName browseName = new QualifiedName(2, "NewNode");
// How to get this to the server??
EUInformation euinfo = new EUInformation(null,-1,LocalizedText.english("MyUnit"),
LocalizedText.english("My Description"));
ExpandedNodeId typeDef = new ExpandedNodeId(Identifiers.BaseVariableType,
DatatypeNamespace.NAMESPACE_URI, 0);
AddNodesItem newItem = new AddNodesItem(parentNodeId, referenceTypeId,
requestedNewNodeId,rowseName,NodeClass.VariableType, null, typeDef);
List<AddNodesItem> items = new ArrayList<AddNodesItem>();
items.add(newItem);
client.addNodes(items).get();
편집
: 내 네임 스페이스 클래스의 write()
을 수정합니다. 이제 EUInformation 값을 사용하여 노드의 표시 이름과 설명을 수정할 수 있습니다. 여기 내 write()
방법입니다 :
@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
for (WriteValue writeValue : writeValues) {
ServerNode node = server.getNodeMap().get(writeValue.getNodeId());
if (node != null) {
// Get the type of the variant thats about to be written to the node
NodeId variantType = writeValue.getValue().getValue().getDataType().get();
if (variantType.equals(Identifiers.Structure)) {
ExtensionObject o = (ExtensionObject) writeValue.getValue().getValue().getValue();
if (o.getEncodingTypeId().equals(Identifiers.EUInformation_Encoding_DefaultBinary)) {
EUInformation euInformation = (EUInformation) o.decode();
node.setDescription(euInformation.getDescription());
node.setDisplayName(euInformation.getDisplayName());
System.out.println("Wrote EUInformation " + euInformation);
results.add(StatusCode.GOOD);
context.complete(results);
return;
}
}
try {
node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(),
writeValue.getValue(), writeValue.getIndexRange());
results.add(StatusCode.GOOD);
System.out.println(String.format("Wrote value %s to %s attribute of %s",
writeValue.getValue().getValue(),
AttributeId.from(writeValue.getAttributeId()).map(Object::toString).orElse("unknown"),
node.getNodeId()));
} catch (UaException e) {
System.out.println(String.format("Unable to write %s", writeValue.getValue()));
results.add(e.getStatusCode());
}
} else {
results.add(new StatusCode(StatusCodes.Bad_NodeIdUnknown));
}
}
context.complete(results);
}
먼저 물건을 것 같아요 : 당신은 당신의 서버에 AddNodes 서비스를 구현? 그렇지 않으면 클라이언트에서이 노드를 추가 할 수 없습니다. –
이미 완료했습니다. 노드 추가가 제대로 작동합니다. 나는 또한 그들에게 읽고 쓸 수있다. – Ricky