Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
CodeGenerator fails on StructuredDataType
April 8, 2016
15:39, EEST
Avatar
mmaus
Member
Members
Forum Posts: 4
Member Since:
April 7, 2016
sp_UserOfflineSmall Offline

I have created an XML file in NodeSet2 form with the definition of a datatype derived from structure (XY-Position), for which codegen fails.

The relevant part is:

<UADataType NodeId=”ns=1;i=8008″ BrowseName=”1:XYPosition”>
<DisplayName>XYPosition</DisplayName>
<Description>Describes a position in the plane</Description>
<References>
<Reference ReferenceType=”HasSubtype” IsForward=”false”>i=22</Reference>
</References>
<Definition Name=”XYPosition”>
<Field DataType=”Double” Name=”x”/>
<Field DataType=”Double” Name=”y”/>
</Definition>
</UADataType>

CodeGeneration fails if this DataType is included in the XML file; if it’s removed, other elements (e.g. UAObjectTypes) are created.
Codegen fails with:
[java] ERROR occured during generation.
[java] Exception in thread “main” java.lang.NullPointerException
[java] at clojure.core$with_meta.invoke(core.clj:214)
[java] at clojure.data.zip$mapcat_chain.invoke(zip.clj:86)

Which does not help me any further. Is this a (known?) bug, or am I missing something here?
Thanks a lot!

April 8, 2016
17:06, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello,

Thanks for contacting us. Indeed, the error message in this case does not help you further.

Probably the error occurs because encoding nodes Default Binary and Default XML have not been defined for the DataType in question. The XML shown above seems to be correct otherwise.

Here is an example definition of these missing nodes:

<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>

Here the NodeId ns=1;i=3001 refers to my custom structure type.

Let us know if this helps.

By the way, are you generating the XML by hand? Ready made tools are valuable, especially with larger information models. Please see UA Modeler for reference https://prosysopc.com/products/opc-ua-modeler/

April 11, 2016
12:37, EEST
Avatar
mmaus
Member
Members
Forum Posts: 4
Member Since:
April 7, 2016
sp_UserOfflineSmall Offline

Thank you, this helped!
I’ve implemented that test in the UA modeler, which adds these information in the exported XML. This compiles fine.

So far I’ve been using vim to edit the xml manually based on samples (OpcUa, DI, …). This allows good control of every detail, and worked quite well on another, larger example.
However, creating these structured data types convinced me to use this UA modeler tool, despite its quite frequent crashes, instead of manually editing the xml, because it seems a really large effort to maintain these structured data types (e.g. to provide the base64-encoded xml “ByteString” Value version as well…).

Furthermore, I found an error in the “Opc.Ua.Di.Nodeset2.xml” file provided in the lib directory of the codegenerator: the NodeId “ns=1;i=6164″ has DataType=”Boolean”, it should be “String” according to DI standard.

April 11, 2016
14:50, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello,

Good to know that the original issue was resolved.

You are correct about the Opc.Ua.Di.Nodeset2.xml file. I looked at the mantis bug tracker of OPC Foundation and it seems that this is already reported and actually should be fixed in the current development version of the Opc.Ua.Di.Nodeset2.xml. If you are interested, see https://opcfoundation.org/resources/issue-tracking/ for more information about the bug tracking. Issue 3290: “Issues in OPC DI UANodeSet XML file” describes this error in the Nodeset file.

Thanks for letting us know about this. We will update the Nodeset files in the SDK as soon as they are published.

Let us know if you have some further questions or comments.

July 27, 2016
17:36, EEST
Avatar
opcstudent
Member
Members
Forum Posts: 5
Member Since:
July 27, 2016
sp_UserOfflineSmall Offline

Hi,

I’m still having the same problem.
I created the address space in UaModeler(version 1.4.2) and a the following structured datatype.

<UADataType NodeId="ns=1;i=3004" BrowseName="1:InspectionInfo">
<DisplayName>InspectionInfo</DisplayName>
<Description>a</Description>
<References>
<Reference ReferenceType="HasEncoding">ns=1;i=5001</Reference>
<Reference ReferenceType="HasEncoding">ns=1;i=5006</Reference>
<Reference ReferenceType="HasSubtype" IsForward="false">i=22</Reference>
</References>
<Definition Name="1:InspectionInfo">
<Field DataType="DateTime" Name="StartTime"/>
<Field DataType="DateTime" Name="FinishTime"/>
<Field DataType="Int32" Name="ID"/>
</Definition>
</UADataType>

Related encondig nodes:

<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=3004</Reference>
<Reference ReferenceType="HasDescription">ns=1;i=6050</Reference>
</References>
</UAObject>
<UAObject SymbolicName="DefaultXml" NodeId="ns=1;i=5006" BrowseName="Default XML">
<DisplayName>Default XML</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=76</Reference>
<Reference ReferenceType="HasEncoding" IsForward="false">ns=1;i=3004</Reference>
<Reference ReferenceType="HasDescription">ns=1;i=6051</Reference>
</References>
</UAObject>

the codegen does not report errors, but java files from StructuredDataType are not created.
I am using ‘Prosys-OPC-UA-Java-SDK-Client-Server-Evaluation-2.2.2-638’ version of SDK.

thanks in advance

July 28, 2016
15:34, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hi,

Sorry to hear that you are having problems.

Are you able to generate some code successfully and only this structured data type is not produced? Or is the problem that the code generator is not producing anything?

This sounds like some kind of a configuration issue as the code generator does not produce errors and also no Java files are generated.

July 28, 2016
15:53, EEST
Avatar
opcstudent
Member
Members
Forum Posts: 5
Member Since:
July 27, 2016
sp_UserOfflineSmall Offline

Hi,

I am able to generate code for ObjectType, EventType, EnumType, but not to DataType and Objects.

I read the ReadmeSample.md Readme.md files about configuration steps. I think i did it right.

July 29, 2016
13:37, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hi,

Well, this sounds a little strange. The XML snippets that you posted earlier look correctly formatted and you are able to use the code generator otherwise normally.

One detail to note is that the code generator will make an up-to-date check for the input files and will not generate code if the source files have not changed. This can sometimes cause confusion. In case you wish to force the generation, you can remove the hidden ‘.codegen’ file from the destination directory. This is handled in the part “Up-to-date check” of the Readme.md file.

The name of the ID field in the InspectionInfo structure probably needs to be changed to something else because the code generator generates field named ID into the generated Java class. However, this should not stop the code generator from working so you should worry about this only later when you use the generated Java class.

We’ll need to have some information to help you further. Could you for example post the output that you get from the code generator?

August 2, 2016
17:20, EEST
Avatar
opcstudent
Member
Members
Forum Posts: 5
Member Since:
July 27, 2016
sp_UserOfflineSmall Offline

Hi,

First of all, i think that there is no problem with “up-todate check”, since i have deleted the output file every time before call code generator.
So, it must generate all files from scratch.

One example of generated code of :
– public abstract class InspectionItemTypeImplBase extends BaseObjectTypeImpl implements InspectionItemType

@Mandatory
@Override
public InspectionInfo[] getInspections() {
UaVariable node = getInspectionsNode();
if (node == null)
throw new RuntimeException("Mandatory node Inspections does not exist");
Object value = node.getValue().getValue().getValue();
return (InspectionInfo[]) value;
}

The returned type ‘InspectionInfo’ cannot be found because was not generated. But for other types, like String or NodeId, worked fine.

Besides StructuresDataTypes, I would like to recall that code for Objects, Methods were not generated as well.

August 3, 2016
9:02, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hi,

I understand that something is going wrong. However, it’s hard to say what’s going wrong based on this information. The XML snippets that you posted earlier are valid and the code generator should work with them. The conditions “java files are not created” or “InspectionInfo cannot be found ” are just too vague to make any meaningful guessing.

To inspect this further, we would need to know how to reproduce your issue or at least get the output from the code generator. This log may show what is going wrong.

If you would like to share us your information model and steps to reproduce the issue but you don’t like to post them here on the forum, you can also share them with us by emailing them to uajava-support@prosysopc.com.

October 25, 2016
19:26, EEST
Avatar
opcstudent
Member
Members
Forum Posts: 5
Member Since:
July 27, 2016
sp_UserOfflineSmall Offline

Hi,
I’m sorry about last post. I did not mean to be rude.
I gave up working with codegeneretor but i can send the model information and more details later.

But came a new question regarding: how to write a structured variable?
I always get bad enconding exception.

consider the code below:

InspectionInfoClass v= new InspectionInfoClass();
v.setStartTime(new DateTime());
v.setFinishTime(new DateTime());
v.setId(1);

EncoderContext encoderContext = myClient.getEncoderContext();
ExtensionObject extensionObject = ExtensionObject.binaryEncode(v, encoderContext);

=class=

public class InspectionInfoClass implements Structure, Cloneable {

public static final ExpandedNodeId TYPE_ID;
public static final ExpandedNodeId BINARY;
public static final ExpandedNodeId XML;

private DateTime startTime;
private DateTime finishTime;
private int id;

public InspectionInfoClass(){

}

public InspectionInfoClass clone() {
InspectionInfoClass a = new InspectionInfoClass();
return a;
}

public int hashCode() {
byte var2 = 1;
int var3 = 31 * var2 + (this.startTime == null?0:this.startTime.hashCode());
var3 = 31 * var3 + (this.finishTime == null?0:this.finishTime.hashCode());
var3 = 31 * var3 + (this.id == 0 ?0:new Integer(this.id).hashCode());
return var3;
}

public DateTime getStartTime() {
return startTime;
}

public void setStartTime(DateTime startTime) {
this.startTime = startTime;
}

public DateTime getFinishTime() {
return finishTime;
}

public void setFinishTime(DateTime finishTime) {
this.finishTime = finishTime;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Override
public ExpandedNodeId getTypeId() {
return TYPE_ID;
}

@Override
public ExpandedNodeId getXmlEncodeId() {
return XML;
}

@Override
public ExpandedNodeId getBinaryEncodeId() {
return BINARY;
}

static {
TYPE_ID = new ExpandedNodeId(new NodeId(1, UnsignedInteger.getFromBits(3004)));
BINARY = new ExpandedNodeId(new NodeId(1, UnsignedInteger.getFromBits(5006)));
XML = new ExpandedNodeId(new NodeId(1, UnsignedInteger.getFromBits(5001)));
}
}

October 26, 2016
13:49, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

At least, you must define the ExpandedNodeId constant using the NamespaceUris, instead of NamespaceIndex:s (=1 in your example), since the actual Index may be whatever in practice.

As you can see, writing the code manually is not very simple either, so I would still recommend working with the code generation.

The code generator should generate the structure types to the common interface part. It does not generate any instances, such as Objects. The instances are to be generated in code – or they will also be created when you read the information model from the Nodeset.xml into your application.

October 31, 2016
17:29, EET
Avatar
opcstudent
Member
Members
Forum Posts: 5
Member Since:
July 27, 2016
sp_UserOfflineSmall Offline

Hi,

let me see if i can summarise.
I have two related problems. One is about the codegen and the second is about the java client framework.

1- when i use the output xml genereted by UaModeler, the codegen was not able to generate the class related to the structured type, but could generate other classes. (post from August). No error is shown, but it is incomplete.
So, i created a new model with only one strutured type (with same children types) and the codegen could generate the class.

I do not understand why it does not work when i use my xml with the complete AddressSpace.

2- I want to write a structured type. I am able to write simple data types using java framework on Android app, but i could write a structured type only using the .Net framework and C# code generated by UaModeler.
So, based on the code generated (when it worked with only one structured type), i wrote the class manually and used the classes EncoderContext and ExtensionObject (like my last post). In the client side i have not read Nodeset.xml.

How can i write a structured type using client java framework?
Where can i find an example?

November 1, 2016
9:23, EET
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello,

Sorry to hear that you keep experiencing issues.

1. To inspect this issue further, we would need to know how to reproduce your issue or at least get the output from the code generator. Preferably, send the information model that causes problems to uajava-support mailing list. This way we can reproduce and fix the issue in the best way.

2. Have you looked at the tutorial documents that are supplied together with the Java SDK? These are available in the doc-folder. As a start to use generated classes in the OPC UA client application, please take a look at the client tutorial chapter 15 (more specifically 15.1-15.4.).

Also, the code generator is supplied together with sample UaNodeset file called SampleTypes.xml. You can start by generating code from this sample and then using the generated example classes in your client and server application code.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
20 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: 731

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

PromotionToold, HypromeImpupe, toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1