Код: Выделить всё
org.eclipse.milo.opcua.stack.core.UaSerializationException: no codec registered for encodingId=ns=4;i=29
at org.eclipse.milo.opcua.stack.core.encoding.binary.OpcUaDefaultBinaryEncoding.decode(OpcUaDefaultBinaryEncoding.java:89)
at org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject.lambda$decode$0(ExtensionObject.java:116)
at org.eclipse.milo.opcua.stack.core.util.Lazy.get(Lazy.java:39)
at org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject.decode(ExtensionObject.java:116)
at org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject.decode(ExtensionObject.java:75)
Вот моя реализация:
Код: Выделить всё
public static class Codec extends GenericDataTypeCodec {
@Override
public Class getType() {
return LoadColli.class;
}
@Override
public LoadColli decodeType(EncodingContext context, UaDecoder decoder) throws UaSerializationException {
String id = decoder.decodeString("ID");
boolean finished = decoder.decodeBoolean("Finished");
boolean inProgress = decoder.decodeBoolean("InProgress");
return new LoadColli(finished, inProgress, id);
}
public void encodeType(EncodingContext context, UaEncoder encoder, LoadColli value)
throws UaSerializationException {
encoder.encodeString("ID", value.id);
encoder.encodeBoolean("Finished", value.isFinished());
encoder.encodeBoolean("InProgress", value.isInProgress());
}
}
Код: Выделить всё
private void registerCustomCodec(OpcUaClient client) {
NodeId dataTypeId = LoadColli.TYPE_ID
.toNodeId(client.getNamespaceTable())
.orElseThrow(() -> new IllegalStateException("namespace not found"));
NamespaceTable ns = client.getNamespaceTable();
NodeId binaryEncodingId = LoadColli.BINARY_ENCODING_ID
.toNodeId(client.getNamespaceTable())
.orElseThrow(() -> new IllegalStateException("namespace not found"));
// Register codec with the client's DataTypeManager instance.
// We need to register it by both its encodingId and its dataTypeId because it
// may be
// looked up by either depending on the context.
client
.getStaticDataTypeManager()
.registerType(dataTypeId, new LoadColli.Codec(), binaryEncodingId, null, null);
}
Код: Выделить всё
try {
NodeId nodeLoadColliId = NodeId.parse("ns=4;i=30");
UaVariableNode node = client.getAddressSpace().getVariableNode(nodeLoadColliId);
DataValue value = node.readValue();
Variant variant = value.value();
ExtensionObject xo = (ExtensionObject) variant.value();
LoadColli decoded = (LoadColli) xo.decode(client.getStaticEncodingContext());
ExtensionObject modifiedXo = ExtensionObject
.encode(client.getStaticEncodingContext(), loadColli);
Variant loadColliVariant = new Variant(modifiedXo);
NodeReaderWriter.writeNodeValue(client, NodeId.parse("ns=4;i=30"),
loadColliVariant);
} catch (UaException e) {
log.error(" opc error when writing {}", e);
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ilo-opc-ua
Мобильная версия