Eclipse Milo: How to call method which takes a customDataType as argument?












1















The CustomDataType the method requires:



<UADataType NodeId="ns=1;i=3010" BrowseName="1:ScanSettings">
<DisplayName>ScanSettings</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5015</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5016</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:ScanSettings">
<Field DataType="Duration" Name="Duration"/>
<Field DataType="Int32" Name="Cycles"/>
<Field DataType="Boolean" Name="DataAvailable"/>
<Field IsOptional="true" DataType="LocationTypeEnumeration" Name="LocationType"/>
</Definition>
</UADataType>


MethodCall:



CallMethodRequest tCallMethodRequest = new CallMethodRequest(tObjectId, tMethodId, new Variant{});
CallMethodResult tCallMethodResult = pOpcUaClient.call(tCallMethodRequest).get();
System.out.println(tCallMethodResult.getStatusCode());


How to call a method which requires ScanSettings?
Do I need to pass the Variant-array with three Variants containing Duration, Cycles and DataAvailable?



Or



do i need to do something like this ?



EDIT:



Tried it with a ScanSettings-class and got the error:



10:08:52.655 [ua-shared-pool-2] WARN org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder - Not a built-in type: class ScanSettings


My ScanSettings-class:



public class ScanSettings {

private final double duration;
private final int cycles;
private final boolean dataAvailable;

public ScanSettings() {
this(1000.0, 1, true);
}

public ScanSettings(double pDuration, int pCycles, boolean pDataAvailable) {
duration = pDuration;
cycles = pCycles;
dataAvailable = pDataAvailable;
}

public double getDuration() {
return duration;
}

public int getCycles() {
return cycles;
}

public boolean isDataAvailable() {
return dataAvailable;
}

@Override
public int hashCode() {
return Objects.hashCode(duration);
}

@Override
public boolean equals(final Object obj) {
return super.equals(obj);
}

@Override
public String toString() {
return duration + " " + cycles + " " + dataAvailable;
}

public static class Codec extends GenericDataTypeCodec<ScanSettings> {

@Override
public Class<ScanSettings> getType() {
return ScanSettings.class;
}

@Override
public ScanSettings decode(final SerializationContext context, final UaDecoder reader) throws UaSerializationException {
double tDuration = reader.readDouble("Duration");
int tCycle = reader.readInt32("Cycle");
boolean tDataAvalible = reader.readBoolean("DataAvailable");

return new ScanSettings(tDuration, tCycle, tDataAvalible);
}

@Override
public void encode(final SerializationContext context, final ScanSettings pScanSettings, final UaEncoder writer) throws UaSerializationException {
writer.writeDouble("Duration", pScanSettings.duration);
writer.writeInt32("Cycle", pScanSettings.cycles);
writer.writeBoolean("DataAvailable", pScanSettings.dataAvailable);
}
}


}



Registrating it with:



OpcUaBinaryDataTypeDictionary tOpcUaBinaryDataTypeDictionary = new OpcUaBinaryDataTypeDictionary("urn:ScanSettings");

NodeId binaryEncodingId = new NodeId(2, "DataType.ScanSettings.BinaryEncoding");

tOpcUaBinaryDataTypeDictionary.registerStructCodec(new ScanSettings.Codec().asBinaryCodec(), "ScanSettings", binaryEncodingId);

OpcUaDataTypeManager.getInstance().registerTypeDictionary(tOpcUaBinaryDataTypeDictionary);









share|improve this question

























  • UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

    – Bashdi
    Dec 11 '18 at 7:32











  • *How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

    – Bashdi
    Dec 11 '18 at 7:40


















1















The CustomDataType the method requires:



<UADataType NodeId="ns=1;i=3010" BrowseName="1:ScanSettings">
<DisplayName>ScanSettings</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5015</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5016</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:ScanSettings">
<Field DataType="Duration" Name="Duration"/>
<Field DataType="Int32" Name="Cycles"/>
<Field DataType="Boolean" Name="DataAvailable"/>
<Field IsOptional="true" DataType="LocationTypeEnumeration" Name="LocationType"/>
</Definition>
</UADataType>


MethodCall:



CallMethodRequest tCallMethodRequest = new CallMethodRequest(tObjectId, tMethodId, new Variant{});
CallMethodResult tCallMethodResult = pOpcUaClient.call(tCallMethodRequest).get();
System.out.println(tCallMethodResult.getStatusCode());


How to call a method which requires ScanSettings?
Do I need to pass the Variant-array with three Variants containing Duration, Cycles and DataAvailable?



Or



do i need to do something like this ?



EDIT:



Tried it with a ScanSettings-class and got the error:



10:08:52.655 [ua-shared-pool-2] WARN org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder - Not a built-in type: class ScanSettings


My ScanSettings-class:



public class ScanSettings {

private final double duration;
private final int cycles;
private final boolean dataAvailable;

public ScanSettings() {
this(1000.0, 1, true);
}

public ScanSettings(double pDuration, int pCycles, boolean pDataAvailable) {
duration = pDuration;
cycles = pCycles;
dataAvailable = pDataAvailable;
}

public double getDuration() {
return duration;
}

public int getCycles() {
return cycles;
}

public boolean isDataAvailable() {
return dataAvailable;
}

@Override
public int hashCode() {
return Objects.hashCode(duration);
}

@Override
public boolean equals(final Object obj) {
return super.equals(obj);
}

@Override
public String toString() {
return duration + " " + cycles + " " + dataAvailable;
}

public static class Codec extends GenericDataTypeCodec<ScanSettings> {

@Override
public Class<ScanSettings> getType() {
return ScanSettings.class;
}

@Override
public ScanSettings decode(final SerializationContext context, final UaDecoder reader) throws UaSerializationException {
double tDuration = reader.readDouble("Duration");
int tCycle = reader.readInt32("Cycle");
boolean tDataAvalible = reader.readBoolean("DataAvailable");

return new ScanSettings(tDuration, tCycle, tDataAvalible);
}

@Override
public void encode(final SerializationContext context, final ScanSettings pScanSettings, final UaEncoder writer) throws UaSerializationException {
writer.writeDouble("Duration", pScanSettings.duration);
writer.writeInt32("Cycle", pScanSettings.cycles);
writer.writeBoolean("DataAvailable", pScanSettings.dataAvailable);
}
}


}



Registrating it with:



OpcUaBinaryDataTypeDictionary tOpcUaBinaryDataTypeDictionary = new OpcUaBinaryDataTypeDictionary("urn:ScanSettings");

NodeId binaryEncodingId = new NodeId(2, "DataType.ScanSettings.BinaryEncoding");

tOpcUaBinaryDataTypeDictionary.registerStructCodec(new ScanSettings.Codec().asBinaryCodec(), "ScanSettings", binaryEncodingId);

OpcUaDataTypeManager.getInstance().registerTypeDictionary(tOpcUaBinaryDataTypeDictionary);









share|improve this question

























  • UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

    – Bashdi
    Dec 11 '18 at 7:32











  • *How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

    – Bashdi
    Dec 11 '18 at 7:40
















1












1








1








The CustomDataType the method requires:



<UADataType NodeId="ns=1;i=3010" BrowseName="1:ScanSettings">
<DisplayName>ScanSettings</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5015</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5016</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:ScanSettings">
<Field DataType="Duration" Name="Duration"/>
<Field DataType="Int32" Name="Cycles"/>
<Field DataType="Boolean" Name="DataAvailable"/>
<Field IsOptional="true" DataType="LocationTypeEnumeration" Name="LocationType"/>
</Definition>
</UADataType>


MethodCall:



CallMethodRequest tCallMethodRequest = new CallMethodRequest(tObjectId, tMethodId, new Variant{});
CallMethodResult tCallMethodResult = pOpcUaClient.call(tCallMethodRequest).get();
System.out.println(tCallMethodResult.getStatusCode());


How to call a method which requires ScanSettings?
Do I need to pass the Variant-array with three Variants containing Duration, Cycles and DataAvailable?



Or



do i need to do something like this ?



EDIT:



Tried it with a ScanSettings-class and got the error:



10:08:52.655 [ua-shared-pool-2] WARN org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder - Not a built-in type: class ScanSettings


My ScanSettings-class:



public class ScanSettings {

private final double duration;
private final int cycles;
private final boolean dataAvailable;

public ScanSettings() {
this(1000.0, 1, true);
}

public ScanSettings(double pDuration, int pCycles, boolean pDataAvailable) {
duration = pDuration;
cycles = pCycles;
dataAvailable = pDataAvailable;
}

public double getDuration() {
return duration;
}

public int getCycles() {
return cycles;
}

public boolean isDataAvailable() {
return dataAvailable;
}

@Override
public int hashCode() {
return Objects.hashCode(duration);
}

@Override
public boolean equals(final Object obj) {
return super.equals(obj);
}

@Override
public String toString() {
return duration + " " + cycles + " " + dataAvailable;
}

public static class Codec extends GenericDataTypeCodec<ScanSettings> {

@Override
public Class<ScanSettings> getType() {
return ScanSettings.class;
}

@Override
public ScanSettings decode(final SerializationContext context, final UaDecoder reader) throws UaSerializationException {
double tDuration = reader.readDouble("Duration");
int tCycle = reader.readInt32("Cycle");
boolean tDataAvalible = reader.readBoolean("DataAvailable");

return new ScanSettings(tDuration, tCycle, tDataAvalible);
}

@Override
public void encode(final SerializationContext context, final ScanSettings pScanSettings, final UaEncoder writer) throws UaSerializationException {
writer.writeDouble("Duration", pScanSettings.duration);
writer.writeInt32("Cycle", pScanSettings.cycles);
writer.writeBoolean("DataAvailable", pScanSettings.dataAvailable);
}
}


}



Registrating it with:



OpcUaBinaryDataTypeDictionary tOpcUaBinaryDataTypeDictionary = new OpcUaBinaryDataTypeDictionary("urn:ScanSettings");

NodeId binaryEncodingId = new NodeId(2, "DataType.ScanSettings.BinaryEncoding");

tOpcUaBinaryDataTypeDictionary.registerStructCodec(new ScanSettings.Codec().asBinaryCodec(), "ScanSettings", binaryEncodingId);

OpcUaDataTypeManager.getInstance().registerTypeDictionary(tOpcUaBinaryDataTypeDictionary);









share|improve this question
















The CustomDataType the method requires:



<UADataType NodeId="ns=1;i=3010" BrowseName="1:ScanSettings">
<DisplayName>ScanSettings</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5015</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5016</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:ScanSettings">
<Field DataType="Duration" Name="Duration"/>
<Field DataType="Int32" Name="Cycles"/>
<Field DataType="Boolean" Name="DataAvailable"/>
<Field IsOptional="true" DataType="LocationTypeEnumeration" Name="LocationType"/>
</Definition>
</UADataType>


MethodCall:



CallMethodRequest tCallMethodRequest = new CallMethodRequest(tObjectId, tMethodId, new Variant{});
CallMethodResult tCallMethodResult = pOpcUaClient.call(tCallMethodRequest).get();
System.out.println(tCallMethodResult.getStatusCode());


How to call a method which requires ScanSettings?
Do I need to pass the Variant-array with three Variants containing Duration, Cycles and DataAvailable?



Or



do i need to do something like this ?



EDIT:



Tried it with a ScanSettings-class and got the error:



10:08:52.655 [ua-shared-pool-2] WARN org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder - Not a built-in type: class ScanSettings


My ScanSettings-class:



public class ScanSettings {

private final double duration;
private final int cycles;
private final boolean dataAvailable;

public ScanSettings() {
this(1000.0, 1, true);
}

public ScanSettings(double pDuration, int pCycles, boolean pDataAvailable) {
duration = pDuration;
cycles = pCycles;
dataAvailable = pDataAvailable;
}

public double getDuration() {
return duration;
}

public int getCycles() {
return cycles;
}

public boolean isDataAvailable() {
return dataAvailable;
}

@Override
public int hashCode() {
return Objects.hashCode(duration);
}

@Override
public boolean equals(final Object obj) {
return super.equals(obj);
}

@Override
public String toString() {
return duration + " " + cycles + " " + dataAvailable;
}

public static class Codec extends GenericDataTypeCodec<ScanSettings> {

@Override
public Class<ScanSettings> getType() {
return ScanSettings.class;
}

@Override
public ScanSettings decode(final SerializationContext context, final UaDecoder reader) throws UaSerializationException {
double tDuration = reader.readDouble("Duration");
int tCycle = reader.readInt32("Cycle");
boolean tDataAvalible = reader.readBoolean("DataAvailable");

return new ScanSettings(tDuration, tCycle, tDataAvalible);
}

@Override
public void encode(final SerializationContext context, final ScanSettings pScanSettings, final UaEncoder writer) throws UaSerializationException {
writer.writeDouble("Duration", pScanSettings.duration);
writer.writeInt32("Cycle", pScanSettings.cycles);
writer.writeBoolean("DataAvailable", pScanSettings.dataAvailable);
}
}


}



Registrating it with:



OpcUaBinaryDataTypeDictionary tOpcUaBinaryDataTypeDictionary = new OpcUaBinaryDataTypeDictionary("urn:ScanSettings");

NodeId binaryEncodingId = new NodeId(2, "DataType.ScanSettings.BinaryEncoding");

tOpcUaBinaryDataTypeDictionary.registerStructCodec(new ScanSettings.Codec().asBinaryCodec(), "ScanSettings", binaryEncodingId);

OpcUaDataTypeManager.getInstance().registerTypeDictionary(tOpcUaBinaryDataTypeDictionary);






java opc-ua milo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '18 at 12:41







Bashdi

















asked Nov 20 '18 at 8:38









BashdiBashdi

205




205













  • UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

    – Bashdi
    Dec 11 '18 at 7:32











  • *How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

    – Bashdi
    Dec 11 '18 at 7:40





















  • UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

    – Bashdi
    Dec 11 '18 at 7:32











  • *How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

    – Bashdi
    Dec 11 '18 at 7:40



















UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

– Bashdi
Dec 11 '18 at 7:32





UPDATE: After a little bit of work I just get a TimeOut when I call the methode with a ScanSettings Object as Argument. Is there any way to identify the problem? How to know if my ScanSettings-Class is right or the NodeId I use is wrong?

– Bashdi
Dec 11 '18 at 7:32













*How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

– Bashdi
Dec 11 '18 at 7:40







*How to know if my ScanSettings-Class is right or the NodeId I use for encoding is wrong?

– Bashdi
Dec 11 '18 at 7:40














1 Answer
1






active

oldest

votes


















0














I think because there is no code generation support right now the best thing to do is take advantage of the fact the client already knows how to read data type dictionaries and turn them into generic Struct objects, as well as receive those Struct objects and encode them when necessary.



Your method call would look something like this:



Struct scanSettings = Struct.builder("ScanSettings")
.addMember("LocationTypeSpecified", 0)
.addMember("Reserved1", 0)
.addMember("Duration", 3.14)
.addMember("Cycles", 1)
.addMember("DataAvailable", false)
.build();

ExtensionObject xo = ExtensionObject.encodeAsByteString(
scanSettings,
new NodeId(1, 3010),
client.getDataTypeManager()
);

CallMethodRequest request = new CallMethodRequest(
objectId,
methodId,
new Variant{new Variant(xo)}
);





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389075%2feclipse-milo-how-to-call-method-which-takes-a-customdatatype-as-argument%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I think because there is no code generation support right now the best thing to do is take advantage of the fact the client already knows how to read data type dictionaries and turn them into generic Struct objects, as well as receive those Struct objects and encode them when necessary.



    Your method call would look something like this:



    Struct scanSettings = Struct.builder("ScanSettings")
    .addMember("LocationTypeSpecified", 0)
    .addMember("Reserved1", 0)
    .addMember("Duration", 3.14)
    .addMember("Cycles", 1)
    .addMember("DataAvailable", false)
    .build();

    ExtensionObject xo = ExtensionObject.encodeAsByteString(
    scanSettings,
    new NodeId(1, 3010),
    client.getDataTypeManager()
    );

    CallMethodRequest request = new CallMethodRequest(
    objectId,
    methodId,
    new Variant{new Variant(xo)}
    );





    share|improve this answer






























      0














      I think because there is no code generation support right now the best thing to do is take advantage of the fact the client already knows how to read data type dictionaries and turn them into generic Struct objects, as well as receive those Struct objects and encode them when necessary.



      Your method call would look something like this:



      Struct scanSettings = Struct.builder("ScanSettings")
      .addMember("LocationTypeSpecified", 0)
      .addMember("Reserved1", 0)
      .addMember("Duration", 3.14)
      .addMember("Cycles", 1)
      .addMember("DataAvailable", false)
      .build();

      ExtensionObject xo = ExtensionObject.encodeAsByteString(
      scanSettings,
      new NodeId(1, 3010),
      client.getDataTypeManager()
      );

      CallMethodRequest request = new CallMethodRequest(
      objectId,
      methodId,
      new Variant{new Variant(xo)}
      );





      share|improve this answer




























        0












        0








        0







        I think because there is no code generation support right now the best thing to do is take advantage of the fact the client already knows how to read data type dictionaries and turn them into generic Struct objects, as well as receive those Struct objects and encode them when necessary.



        Your method call would look something like this:



        Struct scanSettings = Struct.builder("ScanSettings")
        .addMember("LocationTypeSpecified", 0)
        .addMember("Reserved1", 0)
        .addMember("Duration", 3.14)
        .addMember("Cycles", 1)
        .addMember("DataAvailable", false)
        .build();

        ExtensionObject xo = ExtensionObject.encodeAsByteString(
        scanSettings,
        new NodeId(1, 3010),
        client.getDataTypeManager()
        );

        CallMethodRequest request = new CallMethodRequest(
        objectId,
        methodId,
        new Variant{new Variant(xo)}
        );





        share|improve this answer















        I think because there is no code generation support right now the best thing to do is take advantage of the fact the client already knows how to read data type dictionaries and turn them into generic Struct objects, as well as receive those Struct objects and encode them when necessary.



        Your method call would look something like this:



        Struct scanSettings = Struct.builder("ScanSettings")
        .addMember("LocationTypeSpecified", 0)
        .addMember("Reserved1", 0)
        .addMember("Duration", 3.14)
        .addMember("Cycles", 1)
        .addMember("DataAvailable", false)
        .build();

        ExtensionObject xo = ExtensionObject.encodeAsByteString(
        scanSettings,
        new NodeId(1, 3010),
        client.getDataTypeManager()
        );

        CallMethodRequest request = new CallMethodRequest(
        objectId,
        methodId,
        new Variant{new Variant(xo)}
        );






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 18 '18 at 14:24

























        answered Dec 13 '18 at 13:57









        Kevin HerronKevin Herron

        2,81821723




        2,81821723






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389075%2feclipse-milo-how-to-call-method-which-takes-a-customdatatype-as-argument%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$