Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[milo-dev] Write to a complex dataType's Node

Hi,

I would like to know if it is possible to write to a Node of complex dataType (Structur). Has someone already tried it? I am talking about client side.

I am testing now with UaCppServer where I found a Test Strucur from DaType Person, f.e I try to chnage some of the value of ns=2;s=Person3 using UAExpect and it works. But whene I try with Milo client I get some Bad_WriteNotSupported error code

  @Description("The server not does support writing the combination of value.")
    public static final long Bad_WriteNotSupported = 0x80730000L;



Here is my code:


 private void readWriteCustomDataType(OpcUaClient client) throws InterruptedException, ExecutionException
    {
        LOG.info("readWriteCustomDataType ...");
        LOG.info("------------------------------------------//-------------------------------------------");

        // synchronous read request via VariableNode
        VariableNode node = client.getAddressSpace().createVariableNode(
            new NodeId(2, "Person3"));

        LOG.info("DataType={}", node.getDataType().get());

        // Read the current value
        DataValue value = node.readValue().get();
        LOG.info("Value={}", value);

        Variant variant = value.getValue();
        ExtensionObject xo = (ExtensionObject) variant.getValue();

        org.eclipse.milo.opcua.binaryschema.Struct decoded = (Struct)xo.decode(client.getSerializationContext());

        LOG.info("Decoded={}", decoded);
  //      CustomStructurePerson decoded = (CustomStructurePerson)xo.decode(
  //          client.getSerializationContext()
  //      );
        org.eclipse.milo.opcua.binaryschema.Struct modified = Struct.builder(decoded.getName()).
                        addMember("Name", "Master steen").
                        addMember("Height", UShort.valueOf(123)).
                        addMember("Weight", Float.valueOf((float)2.2)).
                        addMember("Gender", UShort.valueOf(2))
                        .build();
        LOG.info("Modified={}", modified);
        // Write a modified value
//        CustomStructurePerson modified = new CustomStructurePerson(
  //          decoded.getName() + " has changed",
   //         uint(decoded.getHeight().intValue() + 1),
   //         uint(decoded.getWeight().intValue() + 1),
   //         "male"
   //     );

        ExtensionObject modifiedXo = ExtensionObject.encode(
            client.getSerializationContext(),
            decoded,
            xo.getEncodingId(),
            OpcUaDefaultBinaryEncoding.getInstance()
        );

        StatusCode writeStatus = node.writeValue(new DataValue(new Variant(modifiedXo))).get();

        LOG.info("writeStatus={}", writeStatus);

        // Read the modified value back
        value = node.readValue().get();
        LOG.info("Modified Value={}", value);

        variant = value.getValue();
        xo = (ExtensionObject)variant.getValue();

        decoded = (Struct)xo.decode(client.getSerializationContext());
        LOG.info("Decoded={}", decoded);
    }

@Kevin could you please that this is possible? The spec says that client should be able to deal with reading/writing the Structur. Or am I miss something?


Best Regards,
Stoyan Nikolov
Mobile Tel#: +49 172 134 49 49  * E-Mail: mastersteen@xxxxxxxxx URL: http://www.seeburger.de

Back to the top