13:09, EEST
June 28, 2016
Hello,
i’ve a structured parameter to give as input to an OPC UA method. It’s composed as follows:
public class FiberPulserConfigData {
private long voltSet, repRate, width, shots, tempOff;
private byte trgMode;
…
public getters and setters
}
Therefore i defined an OPC UA method with one input parameter and i configured it in the following way:
inputs[0] = new Argument();
inputs[0].setName(“Config data”);
inputs[0].setDataType(Identifiers.Structure);
inputs[0].setValueRank(ValueRanks.Scalar);
inputs[0].setArrayDimensions(null);
inputs[0].setDescription(new LocalizedText(“The response to the command from device”, Locale.ENGLISH));
I invoke this OPC UA method by means of an OPC UA client through the method “call(nodeId, methodId, inputs)”, where in “inputs” there’s a Variant array containing the FiberPulserConfigData instance.
Unfortunately i obtain the following errors:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
… 49 more
Caused by: java.lang.IllegalArgumentException: Variant cannot be it.inaf.iasfpa.astri.camera.ancillary.fiberpulser.FiberPulserConfigData
at org.opcfoundation.ua.builtintypes.Variant.assertValidClass(Unknown Source)
at org.opcfoundation.ua.builtintypes.Variant.(Unknown Source)
at it.inaf.iasfpa.astri.camera.gui.controller.FiberPulserConfigGuiController.writeConfig(FiberPulserConfigGuiController.java:68)
… 58 more
Maybe because the FiberPulserConfigData doesn’t match the OPC UA DataType Structure?
If yes, do you have any suggestions to avoid this mismatching?
If not, what could be the problem?
Thanks in advance.
13:57, EEST
April 17, 2013
Hello,
Thanks for your question. You’re already on the right path when you say “Maybe because the FiberPulserConfigData doesn’t match the OPC UA DataType Structure?”
You have to define your own structures as subtypes of OPC UA structure. Also, to actually use your own custom structures, both the client and server application must be able to encode and decode the structure which means that you must implement a serializer for your custom structure. Fortunately, the Prosys OPC UA Java SDK contains a code generator which takes care of this manual work.
The workflow to define a custom structure is following:
– create information model XML. This can be done manually or using software such as UaModeler https://prosysopc.com/products/opc-ua-modeler/
– generate Java classes based on information model XML. Look into the codegen folder and files Readme.md and ReadmeSample.md for instructions.
– register the model into your application, instructions can be found in the tutorials in doc-folder.
– use the classes in your application in the same manner as above.
One detail to note is that you are setting the data type to be an abstract data type Identifiers.Structure. This can be done but it’s not the usual way. Usually you should use the actual data type that will be used.
Other detail to note is that you can also model the type that contains the method in UaModeler and save some manual labor by generating the method stub with FiberPulserConfigData argument.
Hopefully your project will continue successfully!
15:06, EEST
June 28, 2016
Hi Heikki, many thanks for your answer.
I followed the instructions in the “codegen” folder and created the information model XML named FibPulserConfigData. Then I generated the Java classes based on the XML model, and finally I registered the model both in the client and the server. So everything is right. Both in client and server there’s a FibPulserConfigData variable.
At this point I need that the client sends a variable of FibPulserConfigData type to the server through an OPC UA method.
So I defined an OPC UA method called “write_config_data”, that takes a FibPulserConfigData parameter as input and returns a boolean argument (true for success, false for failure) as output.
So I defined the OPC UA method parameters as follows:
…
FibPulserConfigData fibPulserConfigData = (FibPulserConfigData) client.getAddressSpace().getNode(myNodeId);
…
inputs[0] = new Argument();
inputs[0].setName(“Config data”);
inputs[0].setDataType(fiberPulserConfigData.getNodeId());
inputs[0].setValueRank(ValueRanks.Scalar);
inputs[0].setArrayDimensions(null);
inputs[0].setDescription(new LocalizedText(“The config data entity”, Locale.ENGLISH));
outputs[0] = new Argument();
outputs[0].setName(“Response”);
outputs[0].setDataType(Identifiers.Boolean);
outputs[0].setValueRank(ValueRanks.Scalar);
outputs[0].setArrayDimensions(null);
outputs[0].setDescription(new LocalizedText(“The response to the command from device”, Locale.ENGLISH));
When I invoke this method I obtain the following error message:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
… 49 more
Caused by: java.lang.IllegalArgumentException: Variant cannot be it.inaf.oact.astri.camera.opcua.entity.FibPulserConfigDataImpl
at org.opcfoundation.ua.builtintypes.Variant.assertValidClass(Unknown Source)
at org.opcfoundation.ua.builtintypes.Variant.(Unknown Source)
at it.inaf.iasfpa.astri.camera.gui.controller.FiberPulserConfigGuiController.writeConfig(FiberPulserConfigGuiController.java:92)
… 58 more
This error is similar to the previous, it seems to be a mismatch of data types.
What am I doing wrong?
Cheers
Alessandro
16:39, EEST
December 21, 2011
I am not sure if I follow completely. Looks like you are mixing the client side and server side in your description (fibPulserConfigData and fiberPulserConfigData) – or then I misunderstood.
Anyway, make sure that you define the DataType as a sub type of Structure. Not as a VariableType or ObjectType.
You must define the method in the server side only. And there it is also easier to model the method in your object type with UaModeler and let the code generator generate the method for you as well (in which case you don’t need to define the inputs and outputs).
12:05, EEST
June 28, 2016
Hi Jouni,
sorry if I generated a little bit of confusion. I’ll try to explain better my problem.
I’ve an electronic device to manage, let’s call FiberPulser, connected to a server by means of a serial port.
This device must be configured, so I wrote a Java class with some primitives that read and write some parameters to the device.
So I realized on the server side an OPC UA node called FiberPulserNode, that contains all the parameters to manage.
Some parameters are of common type, such as double, integer, boolean, etc. But there are also some custom structured parameters to manage, for example the already mentioned “configData”, that is composed as follows:
public class FiberPulserConfigData {
private long voltSet, repRate, width, shots, tempOff;
private byte trgMode;
…
}
The writing of common types isn’t a problem for me, I just write them directly from the client.
The problem exists when I have to write the structured parameter, so my question is: how do I pass a structured data from client to server? In this case I’ve to pass a variable of FiberPulserConfigData type from client to server.
To do this I created an OPC UA method on the server. I called it “writeConfigData”. This method should take as input a FiberPulserConfigData variable.
But perhaps this is not the best way, isn’t it?
As I understood I should create a “FiberPulserConfigData” model with the UaModeler and then generate the object with codegen, but I didn’t understand how to create the method. Have I to do it within the data model? Or it’s better to create the entire FiberPulserNode data model with the structured type (FiberPulserConfigData) and the writeConfigData metod inside?
I hope I was clear this time, if not so I apologize in advance.
Best regards.
Alessandro
12:56, EEST
April 3, 2012
You need to create an ObjectType that has the Method as subnode (because a method is always called for an Object instance created from ObjectType).
You must add the Structure type you want to create under the ‘Structure’ type (which is in the Types/DataTypes/Structure)
Lets say I add a ‘BasicTestStructure’, it would be in Types/DataTypes/Structure/BasicTestStructure. There you can define which Fields should be part of the structure, and in which order they are. In this test (I had one model I was using to test things, so easy to use it as an example) I defined 2 fields, in order: DoubleField, I32Field (with said datatypes, note that the name ‘Field’ is not needed, just used it for my tests..). That should look like the following in the XML:
<DisplayName>BasicTestStructure</DisplayName>
<References>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5001</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5002</Reference>
</References>
<Definition Name="1:BasicTestStructure">
<Field DataType="Double" Name="DoubleField"/>
<Field DataType="Int32" Name="Int32Field"/>
</Definition>
</UADataType>
When code is generated from the model it does look like:
@TypeDefinitionId("nsu=http://www.prosysopc.com/codegentest/;i=3001")
public class BasicTestStructure implements Structure, Cloneable {
public static ExpandedNodeId BINARY = ExpandedNodeId.parseExpandedNodeId("nsu=http://www.prosysopc.com/codegentest/;i=5001");
public static ExpandedNodeId ID = ExpandedNodeId.parseExpandedNodeId("nsu=http://www.prosysopc.com/codegentest/;i=3001");
public static ExpandedNodeId XML = ExpandedNodeId.parseExpandedNodeId("nsu=http://www.prosysopc.com/codegentest/;i=5002");
protected Double DoubleField;
protected Integer Int32Field;
public BasicTestStructure() {}
public BasicTestStructure(Double DoubleField, Integer Int32Field)
{
this.DoubleField = DoubleField;
this.Int32Field = Int32Field;
}
public Double getDoubleField() {
return DoubleField;
}
public void setDoubleField(Double DoubleField) {
this.DoubleField = DoubleField;
}
public Integer getInt32Field() {
return Int32Field;
}
public void setInt32Field(Integer Int32Field) {
this.Int32Field = Int32Field;
}
/**
* Deep clone
*
* @return cloned BasicTestStructure
*/
public BasicTestStructure clone()
{
BasicTestStructure result = new BasicTestStructure();
result.DoubleField = DoubleField;
result.Int32Field = Int32Field;
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
BasicTestStructure other = (BasicTestStructure) obj;
if (DoubleField==null) {
if (other.DoubleField != null)
return false;
}
else if (!DoubleField.equals(other.DoubleField))
return false;
if (Int32Field==null) {
if (other.Int32Field != null)
return false;
}
else if (!Int32Field.equals(other.Int32Field))
return false;
return true;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result
+ ((DoubleField == null) ? 0 : DoubleField.hashCode())
+ ((Int32Field == null) ? 0 : Int32Field.hashCode())
;
return result;
}
public String toString() {
return "BasicTestStructure: "+ObjectUtils.printFieldsDeep(this);
}
public ExpandedNodeId getTypeId() {
return ID;
}
public ExpandedNodeId getXmlEncodeId() {
return XML;
}
public ExpandedNodeId getBinaryEncodeId() {
return BINARY;
}
}
Note that in addition, a Serializer is generated for the Structure type (in the generated Serilizers class). This is used by the client/server when sending/receiving data that has the type of ‘BasicTestStructure’. Since it is at some point transfered in a binary stream (i.e. TCP), both sides must know how to convert the data to and back from binary. How this is done is defined by the UA specification, see Part 6. The codegen generates all the required “boilerplate” code used do the transformation. IF you have done all this you can just create new java instances of the BasicTestStructure and Variant should accept them (since they are Structure implementations) and can be used. Note that you do need to call UaClient/Server.registerModel with the InformationModel.MODEL generated for client and server side (note that both sides have different InformationModel class) and load the xml in the server e.g. via NodeManagerTable.loadModel or using UaServer.registerAndLoadModel so that the server address space contains the datatype.
Read the Readme.md that is in the ‘codegen’ folder of the SDK for more information.
– Bjarne
12:58, EEST
December 21, 2011
Hi Alessandro,
Thanks for the clarification.
In order to use structured data through OPC UA, you must define the structure using OPC UA structures (they must extend the Structure class). Normal Java structures won’t work, since we need to be able to marshal (encode/decode) the custom data through the communication protocol.
What you need to do is:
1. Create your own information model, preferably using UaModeler, since it makes it easier. In the model,
1a. create your Structure (FiberPulserConfigDataType) type as a subtype of Structure (in Types/DataTypes), and
1b. create your custom ObjectType (FiberPulserType), which defines the method (WriteConfigData) that takes your structure as an argument.
2. Export the model in XML and use Java Codegen to generate FiberPulserConfigDataType as a Java Structure and FiberPulserType as a server side Java class (FiberPulserTypeNode) that has a stub for the method implementation and a client side Java class (FiberPulserTypeImpl extends FiberPulserTypeImplBase) that has a Java method that you can call from your client application.
3. Implement the method in the server side class (FiberPulserTypeNode.onWriteConfigData)
Please refer to UaModeler documentation on how to create the new types and also to codegen documentation (in SDK tutorials and read files in codegen folder) for the details.
(You can define the method in the server as described in the createMethodNode() example in SampleConsoleServer, but you still need to define the Structure type – and then it is easier to use the modeller and codegen to do it all)
I hope this clarifies the issue a bit better. I do understand that the examples are not always as clear as they could be.
13:06, EEST
April 3, 2012
If you do create an ObjectType e.g. TestObjectType, that has a method e.g. taking one argument of the BasicTestStructure and outputs a string you would a class TestObjectTypeNode in the implementation folder specified in the codegen.properties that has the following method stub:
protected String onTestMethod(ServiceContext serviceContext, BasicTestStructure testData) throws StatusException {
String output = null;
//TODO: Implement the generated method
throw new StatusException(StatusCodes.Bad_NotImplemented);
// TODO: Uncomment the return statement, when you have implemented the method
// return output;
}
If the method has more than one output, then the following:
protected Object[] onTestMethod(ServiceContext serviceContext, BasicTestStructure testData) throws StatusException {
String output = null;
UnsignedInteger output2 = null;
//TODO: Implement the generated method
throw new StatusException(StatusCodes.Bad_NotImplemented);
// TODO: Uncomment the return statement, when you have implemented the method
/*
return new Object[] {
output,
output2
};
*/
}
Assuming you do create the ObjectType instace using NodeManagerUaNode.createInstance(…) methods, then client calls to that method will call the method described above and return values will be returned to the client. So I strongly suggest to model everything in UaModeler, it makes it much simpler.
10:45, EEST
June 28, 2016
Hi,
first of all I thank you all for the help you are giving me.Now the situation is more clear.
I requested a copy of the UA Modeler evaluation version and, while I am waiting to receive it, I’m trying to practice with the Java code generator by writing manually the information model XML of the basic test structure taken from a previous post.
So, I modified the SampleTypes.xml file into the “codegen” folder in the following way:
http://ua.prosysopc.com/SampleTypes
i=45
i=38
BasicTestStructure
i=22
ns=1;i=5001
ns=1;i=5002
When I run the “ant” command for Java classes generation I obtain the following error messages:
…
[java] ERROR occured during generation.
[java] Exception in thread “main” java.lang.Exception: Could not find package for null with type :all.
[java] at codegen.generator$get_package.invoke(generator.clj:92)
[java] at codegen.generator$raw_package.invoke(generator.clj:199)
[java] at codegen.generator$fn__103.invoke(generator.clj:217)
[java] at clojure.lang.MultiFn.invoke(MultiFn.java:227)
[java] at codegen.generator$structure_dependencies$fn__197.invoke(generator.clj:507)
[java] at clojure.core$map$fn__4245.invoke(core.clj:2559)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:56)
[java] at clojure.lang.RT.seq(RT.java:484)
[java] at clojure.lang.RT.nthFrom(RT.java:848)
[java] at clojure.lang.RT.nth(RT.java:807)
[java] at clojure.core$distinct$step__4716$fn__4717$fn__4719.invoke(core.clj:4618)
[java] at clojure.core$distinct$step__4716$fn__4717.invoke(core.clj:4618)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:49)
[java] at clojure.lang.Cons.next(Cons.java:39)
[java] at clojure.lang.RT.length(RT.java:1646)
[java] at clojure.lang.RT.seqToArray(RT.java:1587)
[java] at clojure.lang.LazySeq.toArray(LazySeq.java:126)
[java] at clojure.lang.RT.toArray(RT.java:1565)
[java] at clojure.core$to_array.invoke(core.clj:333)
[java] at clojure.core$sort.invoke(core.clj:2828)
[java] at codegen.generator$structure_dependencies.invoke(generator.clj:503)
[java] at codegen.generator$mustachify_structure.invoke(generator.clj:674)
[java] at clojure.core$map$fn__4245.invoke(core.clj:2559)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:56)
[java] at clojure.lang.LazySeq.first(LazySeq.java:71)
[java] at clojure.lang.RT.first(RT.java:577)
[java] at clojure.core$first.invoke(core.clj:55)
[java] at codegen.generator$render_template_many_to_one.invoke(generator.clj:835)
[java] at codegen.generator$render_template.invoke(generator.clj:857)
[java] at codegen.generator$generate$fn__372.invoke(generator.clj:882)
[java] at clojure.core$map$fn__4245.invoke(core.clj:2559)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:49)
[java] at clojure.lang.Cons.next(Cons.java:39)
[java] at clojure.lang.RT.boundedLength(RT.java:1654)
[java] at clojure.lang.RestFn.applyTo(RestFn.java:130)
[java] at clojure.core$apply.invoke(core.clj:624)
[java] at clojure.core$mapcat.doInvoke(core.clj:2586)
[java] at clojure.lang.RestFn.invoke(RestFn.java:423)
[java] at codegen.generator$generate.invoke(generator.clj:882)
[java] at codegen.core$run.invoke(core.clj:46)
[java] at codegen.core$_main.doInvoke(core.clj:97)
[java] at clojure.lang.RestFn.applyTo(RestFn.java:137)
[java] at codegen.core.main(Unknown Source)
[foreach] Exception in thread “Thread-1” The following error occurred while executing this line:
[foreach] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\build.xml:130: Java returned: 1
[foreach] at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:570)
[foreach] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:443)
[foreach] at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
[foreach] at net.sf.antcontrib.logic.ForEach$1.run(ForEach.java:125)
[foreach] at net.sf.antcontrib.util.ThreadPoolThread.run(ThreadPoolThread.java:53)
What’s wrong?
Cheers and thanks again.
Alessandro
11:22, EEST
April 3, 2012
11:24, EEST
June 28, 2016
<NamespaceUris>
<Uri>http://ua.prosysopc.com/Sample…..ri>
</NamespaceUris>
<Aliases>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasEncoding">i=38</Alias>
</Aliases>
<UADataType NodeId="ns=1;i=3001" BrowseName="1:BasicTestStructure">
<DisplayName>BasicTestStructure</DisplayName>
<References>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5001</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5002</Reference>
</References>
<Definition Name="1:BasicTestStructure">
<Field DataType="Double" Name="DoubleField"/>
<Field DataType="Int32" Name="Int32Field"/>
</Definition>
</UADataType>
</UANodeSet>
11:33, EEST
April 3, 2012
11:48, EEST
June 28, 2016
I added the two aliases, but I still obtain errors. For convenience I’m reporting the entire log:
codegen.codegen:
codegen.codegen-templates:
codegen.codegen-single-check:
codegen.codegen-single-check:
codegen.codegen-single-check:
codegen.codegen-single-with-package:
codegen.codegen-single-with-package:
codegen.codegen-single-with-package:
[java] Arguments: C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/lib C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\templates\client C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples com.prosysopc.ua.samples.types
[java] Arguments: C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/lib C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\templates\server C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples com.prosysopc.ua.samples.types
[java] Arguments: C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/lib C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\templates\common C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples com.prosysopc.ua.samples.types
[java] Generating Java classes from UaNodeSet file C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml (namespace: http://ua.prosysopc.com/SampleTypes).
[java] Using library files:
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Adi.NodeSet2.xml (namespace: http://opcfoundation.org/UA/ADI/)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Di.NodeSet2.xml (namespace: http://opcfoundation.org/UA/DI/)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.NodeSet2.xml (namespace: http://opcfoundation.org/UA/)
[java] Generating Java classes from UaNodeSet file C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml (namespace: http://ua.prosysopc.com/SampleTypes).
[java] Generating Java classes from UaNodeSet file C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml (namespace: http://ua.prosysopc.com/SampleTypes).
[java] Using library files:
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Plc.NodeSet2.xml (namespace: http://PLCopen.org/OpcUa/IEC61131-3/)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Adi.NodeSet2.xml (namespace: http://opcfoundation.org/UA/ADI/)
[java] Exception in thread "main" java.lang.NullPointerException
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Di.NodeSet2.xml (namespace: http://opcfoundation.org/UA/DI/)
[java] writing file C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\..\samples\com\prosysopc\ua\samples\types\client\InformationModel.java
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.NodeSet2.xml (namespace: http://opcfoundation.org/UA/)
[java] at clojure.core$with_meta.invoke(core.clj:214)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Plc.NodeSet2.xml (namespace: http://PLCopen.org/OpcUa/IEC61131-3/)
[java] Wrote 1 files
[java] writing file C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\..\samples\com\prosysopc\ua\samples\types\server\InformationModel.java
[java] Using library files:
[java] Wrote 1 files
[java] "Elapsed time: 70.921082 msecs"
[java] "Elapsed time: 119.827285 msecs"
[java] at clojure.data.zip$mapcat_chain.invoke(zip.clj:86)
codegen.codegen-single-without-package:
[java] at clojure.data.zip.xml$xml__GT_.doInvoke(xml.clj:74)
codegen.codegen-single:
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Adi.NodeSet2.xml (namespace: http://opcfoundation.org/UA/ADI/)
[java] at clojure.lang.RestFn.applyTo(RestFn.java:139)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Di.NodeSet2.xml (namespace: http://opcfoundation.org/UA/DI/) at clojure.core$apply.invoke(core.clj:626)
[echo] Generated code for C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml
[java]
[java] at clojure.data.zip.xml$xml1__GT_.doInvoke(xml.clj:82)
[echo] Generated code to C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples
[java] at clojure.lang.RestFn.invoke(RestFn.java:439)
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.NodeSet2.xml (namespace: http://opcfoundation.org/UA/) at codegen.queries$description.invoke(queries.clj:50)
[java]
[java] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\lib\Opc.Ua.Plc.NodeSet2.xml (namespace: http://PLCopen.org/OpcUa/IEC61131-3/)
[java] at codegen.generator$description.invoke(generator.clj:28)ERROR occured during generation.
codegen.codegen-single-without-package:
[java] at codegen.generator$mustachify_node.invoke(generator.clj:583)
codegen.codegen-single:
[java]
[echo] Generated code for C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\StructureTest.xml
[java] at codegen.generator$mustachify_structure.invoke(generator.clj:675)
[echo] Generated code to C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen/../samples
[java] at clojure.core$map$fn__4245.invoke(core.clj:2559)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:56)
[java] at clojure.lang.LazySeq.first(LazySeq.java:71)
[java] at clojure.lang.RT.first(RT.java:577)
[java] at clojure.core$first.invoke(core.clj:55)
[java] at codegen.generator$render_template_many_to_one.invoke(generator.clj:835)
[java] at codegen.generator$render_template.invoke(generator.clj:857)
[java] at codegen.generator$generate$fn__372.invoke(generator.clj:882)
[java] at clojure.core$map$fn__4245.invoke(core.clj:2559)
[java] at clojure.lang.LazySeq.sval(LazySeq.java:40)
[java] at clojure.lang.LazySeq.seq(LazySeq.java:49)
[java] at clojure.lang.Cons.next(Cons.java:39)
[java] at clojure.lang.RT.boundedLength(RT.java:1654)
[java] at clojure.lang.RestFn.applyTo(RestFn.java:130)
[java] at clojure.core$apply.invoke(core.clj:624)
[java] at clojure.core$mapcat.doInvoke(core.clj:2586)
[java] at clojure.lang.RestFn.invoke(RestFn.java:423)
[java] at codegen.generator$generate.invoke(generator.clj:882)
[java] at codegen.core$run.invoke(core.clj:46)
[java] at codegen.core$_main.doInvoke(core.clj:97)
[java] at clojure.lang.RestFn.applyTo(RestFn.java:137)
[java] at codegen.core.main(Unknown Source)
[foreach] Exception in thread "Thread-1" The following error occurred while executing this line:
[foreach] C:\Users\Alex\Documents\Lavoro\OACT\COLD\ASTRI\Sviluppo\OPC-UA\Prosys\Prova\codegen\build.xml:130: Java returned: 1
[foreach] at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:570)
[foreach] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:443)
[foreach] at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
[foreach] at net.sf.antcontrib.logic.ForEach$1.run(ForEach.java:125)
[foreach] at net.sf.antcontrib.util.ThreadPoolThread.run(ThreadPoolThread.java:53)
12:28, EEST
April 3, 2012
Sorry x2, there should still be more aliases. Probably at least the following:
<Alias Alias="Double">i=11</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="ByteString">i=15</Alias>
<Alias Alias="HasEncoding">i=38</Alias>
<Alias Alias="HasDescription">i=39</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasComponent">i=47</Alias>
Anyway you should have received the UaModeler so please try using that. Creating the model by hand is error prone.
(I suppose I could mention here for future readers that you can look at Spefication Part 6 Annex F for links to schemas of the XML + some explanations).
I created one test model (with UaModeler) that contains one structure, see below
<NamespaceUris>
<Uri>http://yourorganisation.org/st…..ri>
</NamespaceUris>
<Aliases>
<Alias Alias="Int32">i=6</Alias>
<Alias Alias="Double">i=11</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="ByteString">i=15</Alias>
<Alias Alias="HasEncoding">i=38</Alias>
<Alias Alias="HasDescription">i=39</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasComponent">i=47</Alias>
</Aliases>
<Extensions>
<Extension>
<ModelInfo Tool="UaModeler" Hash="+cKrs8DgxTxT3HCloTNCPA==" Version="1.3.3"/>
</Extension>
</Extensions>
<UADataType NodeId="ns=1;i=3001" BrowseName="1:TestStructure">
<DisplayName>TestStructure</DisplayName>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5001</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5002</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:TestStructure">
<Field DataType="Double" Name="DoubleTestField1"/>
<Field DataType="Int32" Name="Int32TestField2"/>
</Definition>
</UADataType>
<UAVariable DataType="String" Historizing="true" ParentNodeId="ns=1;i=6001" NodeId="ns=1;i=6005" BrowseName="1:TestStructure">
<DisplayName>TestStructure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=69</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=6001</Reference>
<Reference ReferenceType="HasDescription" IsForward="false">ns=1;i=5001</Reference>
</References>
<Value>
<uax:String>TestStructure</uax:String>
</Value>
</UAVariable>
<UAVariable DataType="String" Historizing="true" ParentNodeId="ns=1;i=6003" NodeId="ns=1;i=6006" BrowseName="1:TestStructure">
<DisplayName>TestStructure</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=69</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=6003</Reference>
<Reference ReferenceType="HasDescription" IsForward="false">ns=1;i=5002</Reference>
</References>
<Value>
<uax:String>//xs:element[@name=’TestStructure’]</uax:String>
</Value>
</UAVariable>
<UAVariable DataType="ByteString" NodeId="ns=1;i=6001" BrowseName="1:TypeDictionary">
<DisplayName>TypeDictionary</DisplayName>
<Description>Collects the data type descriptions of http://yourorganisation.org/structure/</Description>
<References>
<Reference ReferenceType="HasProperty">ns=1;i=6002</Reference>
<Reference ReferenceType="HasTypeDefinition">i=72</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=6005</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">i=93</Reference>
</References>
<Value>
<uax:ByteString>PG9wYzpUeXBlRGljdGlvbmFyeSB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4bWxuczp0bnM9Imh0dHA6Ly95b3Vyb3JnYW5pc2F0aW9uLm9yZy9zdHJ1Y3R1cmUvIiBEZWZhdWx0Qnl0ZU9yZGVyPSJMaXR0bGVFbmRpYW4iIHhtbG5zOm9wYz0iaHR0cDovL29wY2ZvdW5kYXRpb24ub3JnL0JpbmFyeVNjaGVtYS8iIHhtbG5zOnVhPSJodHRwOi8vb3BjZm91bmRhdGlvbi5vcmcvVUEvIiBUYXJnZXROYW1lc3BhY2U9Imh0dHA6Ly95b3Vyb3JnYW5pc2F0aW9uLm9yZy9zdHJ1Y3R1cmUvIj4KIDxvcGM6SW1wb3J0IE5hbWVzcGFjZT0iaHR0cDovL29wY2ZvdW5kYXRpb24ub3JnL1VBLyIvPgogPG9wYzpTdHJ1Y3R1cmVkVHlwZSBCYXNlVHlwZT0idWE6RXh0ZW5zaW9uT2JqZWN0IiBOYW1lPSJUZXN0U3RydWN0dXJlIj4KICA8b3BjOkZpZWxkIFR5cGVOYW1lPSJvcGM6RG91YmxlIiBOYW1lPSJEb3VibGVUZXN0RmllbGQxIi8+CiAgPG9wYzpGaWVsZCBUeXBlTmFtZT0ib3BjOkludDMyIiBOYW1lPSJJbnQzMlRlc3RGaWVsZDIiLz4KIDwvb3BjOlN0cnVjdHVyZWRUeXBlPgo8L29wYzpUeXBlRGljdGlvbmFyeT4K</uax:ByteString>
</Value>
</UAVariable>
<UAVariable DataType="String" Historizing="true" ParentNodeId="ns=1;i=6001" ValueRank="-2" NodeId="ns=1;i=6002" BrowseName="NamespaceUri">
<DisplayName>NamespaceUri</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
<Reference ReferenceType="HasProperty" IsForward="false">ns=1;i=6001</Reference>
</References>
<Value>
<uax:String>http://yourorganisation.org/structure/</uax:String>
</Value>
</UAVariable>
<UAVariable DataType="ByteString" NodeId="ns=1;i=6003" BrowseName="1:TypeDictionary">
<DisplayName>TypeDictionary</DisplayName>
<Description>Collects the data type descriptions of http://yourorganisation.org/structure/</Description>
<References>
<Reference ReferenceType="HasProperty">ns=1;i=6004</Reference>
<Reference ReferenceType="HasTypeDefinition">i=72</Reference>
<Reference ReferenceType="HasComponent">ns=1;i=6006</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">i=92</Reference>
</References>
</UAVariable>
<UAVariable DataType="String" Historizing="true" ParentNodeId="ns=1;i=6003" ValueRank="-2" NodeId="ns=1;i=6004" BrowseName="NamespaceUri">
<DisplayName>NamespaceUri</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=68</Reference>
<Reference ReferenceType="HasProperty" IsForward="false">ns=1;i=6003</Reference>
</References>
<Value>
<uax:String>http://yourorganisation.org/structure/</uax:String>
</Value>
</UAVariable>
<UAObject SymbolicName="DefaultBinary" NodeId="ns=1;i=5001" BrowseName="Default Binary">
<DisplayName>Default Binary</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=76</Reference>
<Reference ReferenceType="HasEncoding" IsForward="false">ns=1;i=3001</Reference>
<Reference ReferenceType="HasDescription">ns=1;i=6005</Reference>
</References>
</UAObject>
<UAObject SymbolicName="DefaultXml" NodeId="ns=1;i=5002" BrowseName="Default XML">
<DisplayName>Default XML</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=76</Reference>
<Reference ReferenceType="HasEncoding" IsForward="false">ns=1;i=3001</Reference>
<Reference ReferenceType="HasDescription">ns=1;i=6006</Reference>
</References>
</UAObject>
</UANodeSet>
18:17, EEST
June 28, 2016
Hi,
finally, using the UaModeler I received this morning, and following your suggestions, I generated the XML data model, and then I generated the java code using the codegen.
In detail, I obtained the following java sources:
FiberPulserConfigDataType.java
Ids.java
Serializers.java
and two folders (client and server) each containing one file, InformationModel.java.
Then I put these sources in my project and registered the model in the OPC UA server as described in the Readme.md file.
Finally I tried to create an instance of FiberPulserConfigDataType in my NodeManager using:
FiberPulserConfigDataType fibPulserConfigData = createInstance(FiberPulserConfigDataType.class, “fibPulserConfigData”);
but Eclipse shows an error:
The method createInstance(Class, String) in the type NodeManagerUaNode is not applicable for the arguments (Class, String)
Maybe this is a wrong way to create an instance of this type?
Another question: may I define the method WriteConfigData (that takes my structure as argument) directly in NodeManager like in the createMethodNode() example in SampleConsoleServer?
Cheers
Alessandro
18:48, EEST
December 21, 2011
Structure instances must be created with their constructors – createInstance is for objects and variables (which implement Uainstance interface). I suppose this hasn’t been mentioned in the Readme, so sorry for the inconvenience.
In principle, you should be able to define the method manually as well. You just need to use the correct DataTypeId – basically you need to convert from ExpandedNodeid to NodeId using the NamespaceTable:
Most Users Ever Online: 1919
Currently Online:
21 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 737
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1524
Posts: 6450
Newest Members:
fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerleyModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1