DataSourceNodes rejected from opc server, when callback status returns not Good

45 views
Skip to first unread message

Jean-Patrick Theisen

unread,
Jul 15, 2022, 7:41:54 AM7/15/22
to open62541
Hello open62541 community,

I am currently working with the open62541 version v1.2.

Situation:
I am trying to add a DataSourceNode to the opc server, at a time when the datasource is not yet available. From my testing, I observed that the DataSourceNode is rejected, or rather automatically deleted from the opc server in this particular situation.

I found out, that the DataSourceNode callback has to to return twice a StatusCode "Good", in order not get rejected form the opc server at the instance of time calling of UA_Server_addDataSourceVariableNode. Even returning the StatusCode "UA_STATUSCODE_BADWAITINGFORINITIALDATA" does not enfuse the situation..

This behaviour is specific for DataSourceNodes. VariableNodes are not affected by this kind of behaviour.

Is this API behaviour intentional can I do something different? 

-------------------------------------------
Specific Node Callback Function (--> DataSourceNode is accepted)

static scalar_value_t int_value_ds = static_cast<int16_t>(1); 

scalar_value_read_callback read_cb = []()

 {

         return int_value;      

 };

Specific Node Callback Function (--> DataSourceNode is rejected)

    static scalar_value_t int_value_ds = static_cast<int16_t>(1);

    static uint16_t counter = 0;

    scalar_value_read_callback read_cb = []()

    {

        counter_ds++;

        if(counter_ds > 1)

        {

            return std::optional<scalar_value_t>{int_value_ds};

        }

        else

        {

            return std::optional<scalar_value_t>{};

        }

    };

with 

static UA_StatusCode

scalar_value_node_read_callback(UA_Server * i_server,

                                const UA_NodeId * /*i_session_id*/,

                                void * /*i_session_context*/,

                                const UA_NodeId * i_node_id,

                                void * i_node_context,

                                UA_Boolean i_include_timestamp,

                                const UA_NumericRange * /*i_limits*/,

                                UA_DataValue * i_data)

{

    // […]

    auto * callbacks = reinterpret_cast<value_callbacks_t *>(i_node_context);

    auto cb = callbacks->before_read_cb;

    scalar_value_read_callback before_read_callback = cb.value();

    std::optional<scalar_value_t> rc = before_read_callback();

     if(!rc.has_value())

    {      

        return UA_STATUSCODE_BADNODATAAVAILABLE;

    }

    // […]

    return UA_STATUSCODE_GOOD;

}

Error message: "add_data_source_node name: data source int_read_only, error: BadWaitingForInitialData”

Reply all
Reply to author
Forward
0 new messages