Hi Wilfried,
Please find the example code below:
+ create a structure which will have value(which will hold the status) time and quality.
ex:
typedef struct
{
uint32_t value; // it could also be of type String. so that to display the text instead of integer value about the status
int64_t timestamp;
uint32_t status;
}struct_multi_state_descrete_info_t;
+ create a variable of that structure.
ex:
struct_multi_state_descrete_info_t multiState;
+ add node of type UA_MultiStateDiscrete_t in address space follow below code snippet.
ex:
UA_MultiStateDiscrete_t variable2;
UAServer_Init_config_structure_MultiStateDiscrete(&variable2);
multiState.value = 0; //Based on the type of value initialization varies!
multiState.status = OpcUa_Good;
multiState.timestamp = 0;
variable2.enum_handle = 1; // This is the position in 2D array ENUM_STRINGS
variable2.no_of_values = 3; // This is the number of states
variable2.data_item_config.data_variable_config.base_config.node_handle = HANDLE_MultiState;
variable2.data_item_config.data_variable_config.base_config.display_name_handle = HANDLE_MultiState;
variable2.data_item_config.data_variable_config.value_type = UA_TYPE_UInt32;
variable2.data_item_config.data_variable_config.user_write_permissions = 0x00;
variable2.data_item_config.use_definition = FALSE;
variable2.data_item_config.value_precision = FALSE;
status = UAServer_Create_MultiStateDiscrete(&variable2);
if (status != 0)
{
printf("UAServer_Create_MultiStateDiscrete returned: %d\n", (uint16_t)status);
return;
}
status = UAServer_Add_to_objects_folder(variable2.data_item_config.data_variable_config.base_config.node_handle);
if (status != 0)
{
printf("UAServer_Add_to_folder returned: %d\n", (uint16_t)status);
return;
}
Note:
HANDLE_MultiState is defined in the header file (with some integer number). It is similar to other node handles which you might already familiar with.
for enum_handle and no_of_values, please check the definition below
const uint8_t EN_DISPLAYNAME_rotateRight[] = "RIGHT_ROTATE";
const uint8_t EN_DISPLAYNAME_rotateLeft[] = "LEFT_ROTATE";
const uint8_t EN_DISPLAYNAME_stopped[] = "STOPPED";
const UA_UTF8_string_t ENUM_STRINGS[1][3] =
{
{
{ sizeof(EN_DISPLAYNAME_rotateRight) - 1, EN_DISPLAYNAME_rotateRight },
{ sizeof(EN_DISPLAYNAME_rotateLeft) - 1, EN_DISPLAYNAME_rotateLeft },
{ sizeof(EN_DISPLAYNAME_stopped) - 1, EN_DISPLAYNAME_stopped }
}
};
+ multiState.value has to be update at server side, based on the motor status. If motor is rotating right then multiState.value = 0 (if it is of type UInt32_t)
+ to read the node at client side, update the UAServer_Callback_read() function as below:
ex:
if((value_type == UA_TYPE_UInt32) && (handle == HANDLE_MultiState))
{
source_timestamp = my_variable.source_timestamp;
/* Set data quality */
status_code = my_variable.status_code;
data_value.value_UInt32 = &multiState.value;
}
+ in UAServer_Callback_translate_enumstrings() function return the enum value like below:
ex:
return &ENUM_STRINGS[enum_handle - 1][enum_index];
I hope this helps you to solve the problem that you are facing.
Please let me know if anything is not clear.
Thank you.
Regards,
Basavaraju B V