Error Writing OPC-UA Node

I am trying to write a tag that references a ManagedDevice implementation using the Milo OPC-UA driver.

The following is the error that the designer throws at me:

Error writing to InterMessageDelay.value: Bad("Bad_InternalError: An internal error occurred as a result of a programming or configuration error.")

The following is the snipped of my code that implements the write AttributeFilter:

UaVariableNode interMessageDelaysNode = UaVariableNode.builder(getNodeContext())
                .setNodeId(deviceContext.nodeId(String.format("%s/InterMessageDelay",folderName)))
                .setBrowseName(deviceContext.qualifiedName("InterMessageDelay"))
                .setDisplayName(new LocalizedText("InterMessageDelay"))
                .setDataType(BuiltinDataType.UInt32.getNodeId())
                .setTypeDefinition(Identifiers.BaseDataVariableType)
                .setAccessLevel(AccessLevel.READ_WRITE)
                .setUserAccessLevel(AccessLevel.READ_WRITE)
                .build();
        interMessageDelaysNode.setValue(new DataValue((new Variant(0))));
        interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.getValue(
                getAttributeContext ->
                        new DataValue(new Variant(snmpDevice.getInterMessageDelay()))
                )
        );
        interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.setValue((ctx, value) -> {
            snmpDevice.setInterMessageDelay((Integer) value.getValue().getValue());
            ctx.setAttribute(AttributeId.Value, value);
        }));
        getNodeManager().addNode(interMessageDelaysNode);
        folderNode.addOrganizes(interMessageDelaysNode);

Thanks,
Brandon

This line is probably causing a ClassCastException to be thrown and not caught by your code. You set the DataType to UInt32, so you should expect a org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger value.

Thank you for the quick response!

Here is the method signature inside my SNMPDevice class:

public void setInterMessageDelay(int interMessageDelay){ this.interMessageDelay = interMessageDelay; }

What is the correct way to pass only the value that is contained in DataType to this method?

Easiest thing to do would be just change the DataType of your “InterMessageDelay” VariableNode to BuiltinDataType.Int32.

That would work except I’m using that variable to call sleep which takes a long as it’s input. So ultimately I will need this value to be a basic Java type.

Thanks again Kevin.

I found that UInteger has a intValue method and I changed my setValue filter to the following:

interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.setValue((ctx, value) -> {
            UInteger uInteger = (UInteger) value.getValue().getValue();
            snmpDevice.setInterMessageDelay(uInteger.intValue());

            ctx.setAttribute(AttributeId.Value, value);
        }));

For anyone happening across this, I was seeing the same error message on a bulk write in one of my gateway scripts.

It was occurring because one of the tag values I was reading and then trying to write to another tag was of value 'null'.