logo

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline dima_t  
#1 Posted : Friday, January 29, 2016 3:52:23 PM(UTC)
dima_t

Rank: Member

Joined: 9/23/2015(UTC)
Posts: 29

Was thanked: 6 time(s) in 5 post(s)
Here is code from the example:

//Add Variable
UA_BaseDataVariable_t variable;
UAServer_Init_config_structure_BaseDataVariable(&variable);

variable.base_config.node_handle = HANDLE_Variable;
variable.base_config.display_name_handle = HANDLE_Variable;
variable.value_type = UA_TYPE_Int32;
//variable.value_type = UA_TYPE_String;
variable.user_write_permissions = 0xFFFF;

status = UAServer_Create_BaseDataVariable(&variable);
if (status != 0) {
printf("UAServer_Create_BaseDataVariable returned: %d\n", (uint16_t) status);
return;
}


It works fine. But if I try to call it like this, all I want is to add more than one int32 node.
//Add Variable
UA_BaseDataVariable_t variable;
UAServer_Init_config_structure_BaseDataVariable(&variable);

variable.base_config.node_handle = HANDLE_Variable;
variable.base_config.display_name_handle = HANDLE_Variable;
variable.value_type = UA_TYPE_Int32;
//variable.value_type = UA_TYPE_String;
variable.user_write_permissions = 0xFFFF;

status = UAServer_Create_BaseDataVariable(&variable);
if (status != 0) {
printf("UAServer_Create_BaseDataVariable returned: %d\n", (uint16_t) status);
return;
}
status = UAServer_Create_BaseDataVariable(&variable);
if (status != 0) {
printf("UAServer_Create_BaseDataVariable returned: %d\n", (uint16_t) status);
return;


Second call to UAServer_Create_BaseDataVariable fails with OpcUa_BadNodeIdExists 0x805E0000 code.
I have tried many options like reinitialization of UA_BaseDataVariable_t variable. I have tried to supply my own IDs and enabling UA_INCLUDE_APP_DEFINED_NODE_IDS.
But every time I get this error.

By default I'm using server with UA_INCLUDE_APP_DEFINED_NODE_IDS 0.
The manual says that server should care about node IDs on its own, but looks like it doesn't.
Maybe I should reset something in between UAServer_Create_BaseDataVariable calls?

Any suggestions would be appreciated.

Edited by user Thursday, February 11, 2016 4:32:09 PM(UTC)  | Reason: Not specified

Offline Basavaraju B V  
#2 Posted : Sunday, January 31, 2016 8:40:53 PM(UTC)
Basavaraju B V

Rank: Advanced Member

Joined: 6/10/2015(UTC)
Posts: 34
Location: Bengaluru

Was thanked: 1 time(s) in 1 post(s)
Hi Dima_t,

Good to see you again. I hope you are doing fine.

When UAServer_Create_BaseDataVariable(&variable) is called for a variable, it will verify the uniqueness of the node_handle and display_name_handle. If node_handle and display_name_handle are matching with any of the existing nodes then it will report OpcUa_BadNodeIdExists 0x805E0000 error.

So, before calling UAServer_Create_BaseDataVariable(&variable) for the second time, variable has to be re-initialized with different values of node_handle and display_name_handle.

Description of node_handle and display_name_handle can be found in ua_types.h file. In ua_types.h file, for every structure type definition there is a description on member variables.

Note:
UA_INCLUDE_APP_DEFINED_NODE_IDS is by default set to 0 meaning, when node is created in address space, SDK will generate an opaque node id for a node. Which can be seen when client is connected to server. If UA_INCLUDE_APP_DEFINED_NODE_IDS is set to 1 then, node id and node id type value has to be specified for a node. There are structure member variables which can be used to assign the node id and node id type. Ex:

UA_BaseDataVariable_t variable;
UAServer_Init_config_structure_BaseDataVariable(&variable);

variable.base_config.node_handle = HANDLE_Variable;
variable.base_config.display_name_handle = HANDLE_Variable;

variable.base_config.node_id.identifier_type = opcua_node_encoding_numeric; // as type is defined as numeric here, then only numeric value should be provided as node id.
variable.base_config.node_id.numeric_identifier = 12345; // any uint32_t number.

variable.value_type = UA_TYPE_Int32;
variable.user_write_permissions = 0xFFFF;


Now, when UAServer_Create_BaseDataVariable(&variable) is called, a node will be created with the ID that programmer specified. The same can be verified in client when client is connect to server.

I hope this is helpful and helped to solve the problem.

Please let me know if anything is not clear.

Regards,
Basavaraju B V
Offline dima_t  
#3 Posted : Monday, February 1, 2016 10:23:25 AM(UTC)
dima_t

Rank: Member

Joined: 9/23/2015(UTC)
Posts: 29

Was thanked: 6 time(s) in 5 post(s)
Unfortunately server doesn't work in the way you have explained. The way it works right now is not usable.
Take a look at this simple code:


UA_BaseDataVariable_t variable;
UAServer_Init_config_structure_BaseDataVariable(&variable);
variable.base_config.node_handle = 2;
variable.base_config.display_name_handle = 2;
variable.value_type = UA_TYPE_Int32;
variable.user_write_permissions = 0xFFFF;

status = UAServer_Create_BaseDataVariable(&variable);

if (status != 0) {
Messenger::getInstance()->printMsg("UA Server: UAServer_Create_BaseDataVariable failed status code = ", status);
} else {
Messenger::getInstance()->printMsg("UA Server: UAServer_Create_BaseDataVariable succeded = ", status);
}

status = UAServer_Add_to_folder(folder.node_handle, variable.base_config.node_handle);

if (status != 0) {
Messenger::getInstance()->printMsg("UA Server: UAServer_Add_to_folder failed status code = ", status);
}



UA_BaseDataVariable_t variable1;
UAServer_Init_config_structure_BaseDataVariable(&variable1);
variable1.base_config.node_handle = 2;
variable1.base_config.display_name_handle = 3;
variable1.value_type = UA_TYPE_Int32;
variable1.user_write_permissions = 0xFFFF;

status = UAServer_Create_BaseDataVariable(&variable1);

if (status != 0) {
Messenger::getInstance()->printMsg("UA Server: UAServer_Create_BaseDataVariable failed status code = ", status);
} else {
Messenger::getInstance()->printMsg("UA Server: UAServer_Create_BaseDataVariable succeded = ", status);
}

status = UAServer_Add_to_folder(folder.node_handle, variable1.base_config.node_handle);

if (status != 0) {
Messenger::getInstance()->printMsg("UA Server: UAServer_Add_to_folder failed status code = ", status);
}


Thus (variable.base_config.node_handle AND variable.base_config.display_name_handle) != (variable1.base_config.node_handle AND variable1.base_config.display_name_handle), but server fails.
Here is the log:

UA Server: UAServer_Create_BaseDataVariable succeded = 0 @ 2016-02-02 09:59:59 - Green Section
2016-02-02 09:59:59.079 - Error: opcua_sdk_C9270E0BAFAC7C8334EE4663BAFD49073204F06D.cpp, Line: 2712
UA Server: UAServer_Create_BaseDataVariable failed status code = 2153644032 (0x805E0000) @ 2016-02-02 09:59:59 - Blue section


I can make variable.base_config.node_handle different and server succeeds in both cases. But it is useless because variable.base_config.node_handle = NodeClass so I can not add more than one folder or more than one variable.
If I use variable1.base_config.node_handle = 124 server is happy but neither Matrikon OPC UA client nor UA Expert are happy cause they can't identify that NodeClass.
Log from UA Expert 10:16:33.780 | AddressSpaceModel | PRODUCT_NAME - Basic128Rsa1... | Browse failed with error 'BadNodeIdUnknown'.

Is there a way to fix this?

Edited by user Monday, February 1, 2016 11:55:45 AM(UTC)  | Reason: Not specified

Offline Basavaraju B V  
#4 Posted : Monday, February 1, 2016 9:08:33 PM(UTC)
Basavaraju B V

Rank: Advanced Member

Joined: 6/10/2015(UTC)
Posts: 34
Location: Bengaluru

Was thanked: 1 time(s) in 1 post(s)
Hi Dima_t,

As per the code posted above shows that, variable.base_config.node_handle is same as variable1.base_config.node_handle. In that case server cannot create another node with the same node handle.

May be I was not clear in my previous response. <variable_name>.base_config.node_handle should not match with any of the node_handle which is already in address space as well as <variable_name>.base_config.display_name_handle also should not match with any of the display_name_handle which is in address space.
In ua_types.h it clearly says display_name_handle should be a unique identifier, as well as node_handle should also be a unique identifier. Please refer the ua_types.h file for the same

It is possible to create more than 1 folder and more than 1 variable. All needs to be done for creating more than 1 folder and more than 1 variable is, have unique node_handle and display_name_handle.

In the example code which is provided,
#define HANDLE_Folder 1
#define HANDLE_Variable 2

HANDLE_Folder represents the index in the array ENGLISH_TEXT which holds the information about the folder name.
HANDLE_Variable represents the index in the array ENGLISH_TEXT which holds the information about the Variable name.

So, when we browse the node in UA Client (ex: UA Expert), it will basically calls the UAServer_Callback_translate(), for getting the display name of the node. We can see that, UAServer_Callback_translate() actually returns the address of the ENGLISH_TEXT array index entry which was passed as display_name_handle.

So if you want to create an another folder and another variables, We can define new handles for the same and we have to add the entries to the ENGLISH_TEXT array and then pass the respective display_name_handle. For Ex:

#define HANDLE_Folder 1
#define HANDLE_Variable 2
#define HANDLE_Folder2 3
#define HANDLE_Variable2 4

In the ENGLISH_TEXT array please make an entry for HANDLE_Folder2 and HANDLE_Variable2 at the respective index.

Then while creating the Folder node for Folder2 please mention the display_name_handle as HANDLE_Folder2, For creating the another variable node Variable2, please mentions the display_name_handle as HANDLE_Variable2.

node_handle is the unique uint32_t value. So for each variable or folder node_handle value should always be the unique uint32_t value. as we have the unique display_name_handle s for each folder and each variable in the example above, node_handle can also be assigned with respective HANDLE_<folder/variable>.

I hope this will help to solve the problem.

Regards,
Basavaraju B V

Edited by user Monday, February 1, 2016 9:14:51 PM(UTC)  | Reason: Not specified

Offline dima_t  
#5 Posted : Tuesday, February 2, 2016 4:34:31 PM(UTC)
dima_t

Rank: Member

Joined: 9/23/2015(UTC)
Posts: 29

Was thanked: 6 time(s) in 5 post(s)
Found the root of the problem. It happens because I run the server as a separate thread.
Is server capable of running in its own separate thread?
It has UA_INCLUDE_ASYNC_OPS definition but it looks like that is only for callbacks.

Edited by user Tuesday, February 2, 2016 4:53:40 PM(UTC)  | Reason: Not specified

Offline Basavaraju B V  
#6 Posted : Tuesday, February 2, 2016 9:19:24 PM(UTC)
Basavaraju B V

Rank: Advanced Member

Joined: 6/10/2015(UTC)
Posts: 34
Location: Bengaluru

Was thanked: 1 time(s) in 1 post(s)
Hi Dima_t,

Good to hear the problem was resolved.

Is server capable of running in its own separate thread?
My understanding of the above question is, whether Server library can create different thread? Please correct me if I am wrong.

Server library(SDK) cannot create a new thread on its own. But library has provided an option for application to decide on whether some task has to be performed in different threads. The way to do that is by setting UA_INCLUDE_ASYNC_OPS to 1.

If UA_INCLUDE_ASYNC_OPS is set to 1, SDK will create a work items and calls a callback function UAServer_Callback_process_asynchronously() with the handle. Then, In application inside the UAServer_Callback_process_asynchronously(), a different thread can be created (if needed) and then application can call UAServer_Process_asynchronously() on that work item in that newly created thread. Once application finds that operation is done, application has to call UAServer_Operation_completed() to inform the SDK that task is completed.

Please refer ua_server.h file to know which functions needs to be considered (if needed) when UA_INCLUDE_ASYNC_OPS is set to 1.

I hope I have answered your question. Please let me know if anything is not clear.

Regards,
Basavaraju B V

Edited by user Wednesday, February 3, 2016 9:30:38 AM(UTC)  | Reason: Not specified

Offline dima_t  
#7 Posted : Thursday, February 4, 2016 9:43:51 AM(UTC)
dima_t

Rank: Member

Joined: 9/23/2015(UTC)
Posts: 29

Was thanked: 6 time(s) in 5 post(s)
This whole issue was related to completely another problem - User authentication.
Since I'm using user authentication and encryption, even for testing purposes UAServer_Callback_login_x509_certificate
should return TRUE and set user_index, I didn't set user_index explicitly.
Otherwise you can get some weird behavior like random node browsing fails on ARM architecture.

Thx to support for helping me to resolve this issue.

Edited by user Thursday, February 4, 2016 9:44:47 AM(UTC)  | Reason: Not specified

Offline Basavaraju B V  
#8 Posted : Thursday, February 4, 2016 10:15:55 AM(UTC)
Basavaraju B V

Rank: Advanced Member

Joined: 6/10/2015(UTC)
Posts: 34
Location: Bengaluru

Was thanked: 1 time(s) in 1 post(s)
Hi Dima_t,

Good to hear that problem is solved.

Thank you for the feedback.

Regards,
Basavaraju B V
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Matrikon Subscribe  |   Matrikon Unsubscribe  |   Global Unsubscribe  |   Privacy Statement  |   Do Not Sell My Personal Information   |   Cookie Notice