[AnalogItemType] Accessing property 'EngineeringUnits'

412 views
Skip to first unread message

h.kron...@medek.at

unread,
Oct 25, 2018, 4:58:23 AM10/25/18
to open62541
hi!

using open62541 version 0.3-rc2-445-g5c6bc7b3 with ua_namespace_zero=full the following code adds a variable of type 'analogitemtype' and tries to set the properties 'eurange' and 'engineeringunits':

static void create_model(UA_Server *server)
{
    UA_VariableAttributes attr
= UA_VariableAttributes_default;

    attr
.description = UA_LOCALIZEDTEXT("en-US", "My analog item");
    attr
.displayName = UA_LOCALIZEDTEXT("en-US", "MyAnalogItem");
    attr
.dataType = UA_TYPES[UA_TYPES_UINT32].typeId;
    attr
.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;

    UA_QualifiedName qname
= UA_QUALIFIEDNAME(1, "MyAnalogItem");
    UA_NodeId parent
= UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
    UA_NodeId parent_ref
= UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
    UA_NodeId nodeid
;

    UA_StatusCode ret
= UA_Server_addVariableNode(
            server
,
            UA_NODEID_NULL
,
            parent
,
            parent_ref
,
            qname
,
            UA_NODEID_NUMERIC
(0, UA_NS0ID_ANALOGITEMTYPE),
            attr
,
            NULL
,
           
&nodeid);

   
if (ret != UA_STATUSCODE_GOOD)
        UA_LOG_ERROR
(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
               
"%s: %s", qname.name.data,
                UA_StatusCode_name
(ret));

    qname
= UA_QUALIFIEDNAME(0, "EURange");

    UA_Range minmax
= { .low = 0.0, .high = 100.0 };

    ret
= UA_Server_writeObjectProperty_scalar(
            server
,
            nodeid
,
            qname
,
           
&minmax,
           
&UA_TYPES[UA_TYPES_RANGE]);

   
if (ret != UA_STATUSCODE_GOOD)
        UA_LOG_ERROR
(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
               
"%s: %s", qname.name.data,
                UA_StatusCode_name
(ret));

    qname
= UA_QUALIFIEDNAME(0, "EngineeringUnits");

    UA_EUInformation eu
= {
       
.namespaceUri = UA_STRING("somecompany.com"),
       
.unitId = -1,
       
.displayName = UA_LOCALIZEDTEXT("en-US", "m/s"),
       
.description = UA_LOCALIZEDTEXT("en-US", "meter per second"),
   
};

    ret
= UA_Server_writeObjectProperty_scalar(
            server
,
            nodeid
,
            qname
,
           
&eu,
           
&UA_TYPES[UA_TYPES_EUINFORMATION]);

   
if (ret != UA_STATUSCODE_GOOD)
        UA_LOG_ERROR
(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
               
"%s: %s", qname.name.data,
                UA_StatusCode_name
(ret));
}

adding the variable and setting property 'eurange' succeeds but setting property 'engineeringunits' fails with error 'badnomatch'.

according to opcua spec 1.04 part 8 section 5.3.2 'analogitemtype' property 'engineeringunits' has modellingrule 'optional' and
to part 3 section 6.4.4.5.3 'optional' that (afaiu) an optional node may not be provided if it does not reference a mandatory node.

in case my assumption is correct how do i need to change the code to get access to property 'engineeringunits'?

best regards
horst

marcus...@googlemail.com

unread,
Apr 9, 2019, 9:23:10 AM4/9/19
to open62541
Hello Horst

I had the same problem. My solution is to use UA_NS0ID_ANALOGUNITRANGETYPE for creating the variable.
In your case:

    UA_StatusCode ret = UA_Server_addVariableNode(
            server
,
            UA_NODEID_NULL
,
            parent
,
            parent_ref
,
            qname
,

            UA_NODEID_NUMERIC
(0, UA_NS0ID_ANALOGUNITRANGETYPE ),
            attr
,
            NULL
,
            
&nodeid);

Best regards
  Marcus 
Reply all
Reply to author
Forward
0 new messages