Replies: 3 comments 4 replies
-
This will be a little complicated because you have to actually build and encode a COORD struct to pass as the argument value. To start, you'll need to configure your client to read the DataType Dictionary so that you can encode/decode structures defined by the server, if you haven't already. It will look something like this: https://github.com/eclipse/milo/blob/17a8fc8d14893e3e4532a9237789363b8cc50891/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/UnifiedAutomationReadCustomDataTypeExample.java#L43-L48 You'll also need a
Then you'll have to build a generic Struct and encode it:
Make sure you use the correct datatypes for the structure member values; I don't know what they actually are and just put doubles in as placeholders. The finally you can use |
Beta Was this translation helpful? Give feedback.
-
@kevinherron thanks for your answer, I have implemented all the necessary bits you mentioned but now I get an null pointer exception on here is the COORD node from UAExpert the Code is as follows Code added in the initialization of the client tempOpcUaClient = OpcUaClient.create(opcUaClientconfig);
tempOpcUaClient.addSessionInitializer(new DataTypeDictionarySessionInitializer(new GenericBsdParser()));
tempOpcUaClient.addSessionInitializer(new DataTypeTreeSessionInitializer()); Code for constructing the struct public ExtensionObject buildStructCoords(short[] coords, String node) throws UaRuntimeException, UaException, InterruptedException, ExecutionException {
OpcUaSession session = client.getSession().get();
DataTypeTree dataTypeTree = (DataTypeTree) session.getAttribute(DataTypeTreeSessionInitializer.SESSION_ATTRIBUTE_KEY);
NodeId dataTypeId = NodeId.parse(node);
Struct struct = Struct.builder("COORD")
.addMember("L", coords[0])
.addMember("S", coords[1])
.addMember("X", coords[2])
.addMember("Y", coords[3])
.addMember("Z", coords[4])
.build();
ExtensionObject structEncoded = ExtensionObject.encodeDefaultBinary(client.getDynamicSerializationContext()
, struct,
dataTypeTree.getDataType(dataTypeId).getBinaryEncodingId());
return structEncoded;
} |
Beta Was this translation helpful? Give feedback.
-
@kevinherron Thanks!
was turned off indeed. It's enabled now but we still have the same problem. We receive a DataTypeTree as follows:
Our current idea is to construct or add the DataType manually. Or do you have some suggestions? Could it still be an PLC issue? EDIT: Solution from this guy named Kevin Herron ;) worked fine, thank you! node = "ns=3;s=\"OPCUA_methodTaskBring_IDB\".\"UAMethod_InParameters\".\"COORD\"";
NodeId dataTypeId = NodeId.parse(node);
UaVariableNode coordsNode = client.getAddressSpace().getVariableNode(dataTypeId);
NodeId dataType = coordsNode.getDataType();
DataType dT = dataTypeTree.getDataType(dataType);
ExtensionObject structEncoded = ExtensionObject.encodeDefaultBinary(client.getDynamicSerializationContext(), struct,
dT.getBinaryEncodingId()); |
Beta Was this translation helpful? Give feedback.
-
Hi,
we use Milo 0.6.3 for calling OPC-UA methods. (this is a followup to the previous #879 discussion and thanks for the workaround it worked)
But now we have a new problem I want to call a method but the last argument is what I think a node (its like an struct) and now I have the problem that I dont know how to compose the arguments. To correctly call the method, it always throws an exception "status=Bad_InvalidArgument, message=One or more arguments are invalid."
The method that is the problem is the OPCUA_methodTaskBring_IDB.Method and its 4 argument (COORD). The values that have to be handed over are all integers (L, S, X, Y, Z).
The code for calling the Method is as follows.
So the question for me now what I have to hand over at the 4 parameter I currently thought I have to hand over the nodeID but this doesn't work. I also tried an array of shorts as all the individual values are int16, but this also didn't work.
Also I am fairly new to Milo and OPC-UA maybe you could explain a little how this works with these parameters that the identifier of the 4 parameter is a referencing a node. (This is at least what I think so)
Beta Was this translation helpful? Give feedback.
All reactions