Adding Custom Structure Using UaModeler

Questions regarding the use of the High Perfomance SDK for Server development

Moderator: uasdkhpc

Post Reply
Utkrist
Hero Member
Hero Member
Posts: 22
Joined: 15 May 2023, 09:50

Adding Custom Structure Using UaModeler

Post by Utkrist »

Hi,
I am trying to add a custom structure known at compile time using the UaModeler. So far, I can add a variable and objects to the information model, and am able to view it using UaExpert. To add the custom structure, I followed the documentation and added a new structured data type, and also enabled the AddVariableType option. Then I gave some value to my variables in variable types and added an instance of the structure in the Objects folder, but when I try and view the structure the datatype is displayed as null and I cannot view the structure. However it still contains the variables and I can view them just fine.

Image
https://ibb.co/zR93SPs

One possible problem I can think of is that in Additional Attributes, the value for my variable type is automatically set to Null, which I think is causing the error.
Image
https://ibb.co/NW9Vzpw

Any insight will be greatly appreciated.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Adding Custom Structure Using UaModeler

Post by Support Team »

Hello,

the HP SDK does not support values for custom structures in XML (which is used as an intermediate format when the UaModeler generates code for the HP SDK), so these values must be set in code after generating.
Best regards
Unified Automation Support Team

Utkrist
Hero Member
Hero Member
Posts: 22
Joined: 15 May 2023, 09:50

Re: Adding Custom Structure Using UaModeler

Post by Utkrist »

Hi,
Thanks for the reply. I tried following thishttps://documentation.unified-automation.com/uasdkhp/1.7.1/html/usingextensionobjects.html , but was unable to implement the required structure. Could you link some examples, where a custom structure is implemented?

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Adding Custom Structure Using UaModeler

Post by Support Team »

Hi,

the create_eurange() function from the link also works for other structures, instead of the struct ua_range, the struct of the custom datatype must be used, which is created by the UaModeler and instead of UA_ID_RANGE, the identifier (and namespace index) of the custom datatype must be used, which is also generated by the UaModeler.
Best regards
Unified Automation Support Team

Utkrist
Hero Member
Hero Member
Posts: 22
Joined: 15 May 2023, 09:50

Re: Adding Custom Structure Using UaModeler

Post by Utkrist »

Hi,

So, I defined the function is server_utilities.c and I am calling it in the same file, specifically inside the server_init_main function. I have added a print message in my functions, which is printed at the output. However, there is no change at the output of UaExpert. I have tried all the possible values for the identifier. Am I calling the function at the wrong place? I have managed to implement my structure using the CPP SDK, but HP SDK has me totally stumped.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Adding Custom Structure Using UaModeler

Post by Support Team »

Hi,

the server_utilities.c is not intended to be modified, this code should be added to your provider which is generated as provider_*_impl.c, the concept of providers is explained here: https://documentation.unified-automation.com/uasdkhp/1.7.1/html/provider.html
The custom value will also need a value store which is also explained in the linked document and further demonstrated in Lesson 2, linked at the end of that document.
Best regards
Unified Automation Support Team

ReidLi
Full Member
Full Member
Posts: 6
Joined: 15 Aug 2023, 06:39

Re: Adding Custom Structure Using UaModeler

Post by ReidLi »

It seems UA ns0 structure type also cannot be identified by uaExpert. created 'tmpOutput3' variable whose type is ns0 'CurrencyUnitType' and assign the initial value to each field.

Image
https://ibb.co/Chqkr8H

After uaModeler compile and execute 'build.sh', run the application program, 'tmpOutput3' value is 'NULL'. Although its Datatype is 'CurrencyUnitType' from 'Attributes' window, cannot view its Datatype or edit its value from 'Data Access View' window.

Image
https://ibb.co/grWm038

For variable of UA namespace 0 structure type, also need to create the same datatype into provider which is generated as provider_*_impl.c ?

SDK version: v1.7.1
uaModeler version: 1.6.9 517
uaExpert version: 1.6.3

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Adding Custom Structure Using UaModeler

Post by Support Team »

Hi,

the xml2c/xml2bin tools support the UA builtin datatypes as well as the following UA structures: Argument, EnumValueType, EUInformation and Range. Values of these datatypes can be loaded from xml files, other values need to be set in code which is explained following the link from my previous post:
https://documentation.unified-automation.com/uasdkhp/1.7.1/html/provider.html

Further information can be found in Lesson 2, linked at the end of that document.
Best regards
Unified Automation Support Team

ReidLi
Full Member
Full Member
Posts: 6
Joined: 15 Aug 2023, 06:39

Re: Adding Custom Structure Using UaModeler

Post by ReidLi »

It looks a little bit strange. Since xml2c/xml2bin have already supported above four UA structures, why not support all UA structures since the encode/decode method should be applicable for all UA structures, do you have any plan to support all UA structures by xml2c/xml2bin?

It means customer need add the initial values in code for variables of custom type or even UA structure type, the values set in uaModeler is useless. Also need create separate valuestore and read/write functions in code to support read/write the values of these variables. It may add a big burden for the application.

ReidLi
Full Member
Full Member
Posts: 6
Joined: 15 Aug 2023, 06:39

Re: Adding Custom Structure Using UaModeler

Post by ReidLi »

About the variable of BuiltInType datatype, it can read the value set in xml value, but seems cannot change the value.
Below ‘tmpOutput2’ set initial value ‘234’ in xml file and compiled by uaModeler and build with ‘build.sh’, uaExpert can view its value of ‘234’, but change its value will get the fault ‘BadNotWriteable’ fault. And all fields of ‘tmpOutput3’ whose type is ‘CurrencyUnitType’ is either 0 or blank.
Image
https://ibb.co/VVRw2HF

After added the valuestore and read/write function to ‘tmpOutput2’, ‘tmpOutput3’, the values of these two variables can be updated
Image
https://ibb.co/fQfTS81

It means that if we want to change the values of the variable no matter it’s structure type or builtInType, we need add valuestore and read/write functions on it. It could be a big burden for application!

BTW, I need set ‘ENABLE_STRUCTURE_INTERNAL_CURRENCYUNITTYPE’ to ‘ON’ in ‘uatype_config.cmake’, otherwise ‘CurrencyUnitType’ cannot be found.

Please correct me if my above understanding is wrong, could you please provide your thoughts about it? thanks in advance.

Utkrist
Hero Member
Hero Member
Posts: 22
Joined: 15 May 2023, 09:50

Re: Adding Custom Structure Using UaModeler

Post by Utkrist »

Hi ReidLi,

I was wondering if you could share your code, or include some more detail on how you added the valuestore and read/write function to your structures. I just came back from vacation, and completely forgot all the leads I had about this. I would really appreciate it.

ReidLi
Full Member
Full Member
Posts: 6
Joined: 15 Aug 2023, 06:39

Re: Adding Custom Structure Using UaModeler

Post by ReidLi »

Hi, Utkrist,
you may look at https://documentation.unified-automation.com/uasdkhp/1.7.1/html/server_gettingstarted2.html and related files are located in the folder \examples\server_gettingstarted\lesson02, I also use them for reference.

Post Reply