Hello,
I have a problem defining a matrix of dynamic dimension (ex. uint8_t [4][]) and saving it in one ua_variant variable? Could you please help me with how can I do that and if it is possible at all?
Thank you in advance.
Greetings,
Elena
Matrix of dynamic dimension in an ua_variant variable
Moderator: uasdkhpc
-
- Full Member
- Posts: 5
- Joined: 16 Oct 2015, 11:10
- Support Team
- Hero Member
- Posts: 3068
- Joined: 18 Mar 2011, 15:09
Re: Matrix of dynamic dimension in an ua_variant variable
Hello Elena,
the dynamic dimensions are only possible in UA meta data (array_dimensiosn attribute),
but not and a variant.
A variant value always needs concrete length information, because real memory is allocated for this.
So the array length of a variable may be dynamic, but the variant value is the state of the variable's value at a specific point in time,
where this must be defined.
The next version V1.2.0 will contain some enhancements regarding this topic:
- array dimensions attribute will be supported (this is missing in previous versions)
- new convenience functions for array and matrix handling have been added.
Example code for filling a variant array/matrix:
the dynamic dimensions are only possible in UA meta data (array_dimensiosn attribute),
but not and a variant.
A variant value always needs concrete length information, because real memory is allocated for this.
So the array length of a variable may be dynamic, but the variant value is the state of the variable's value at a specific point in time,
where this must be defined.
The next version V1.2.0 will contain some enhancements regarding this topic:
- array dimensions attribute will be supported (this is missing in previous versions)
- new convenience functions for array and matrix handling have been added.
Code: Select all
int ua_variant_set_array(struct ua_variant *v, enum ua_variant_type type, const void *val, size_t num);
int ua_variant_set_matrix(struct ua_variant *v, enum ua_variant_type type, const void *val, size_t num, int32_t *dimensions, int32_t num_dimensions);
int ua_variant_get_array(const struct ua_variant *v, struct ua_variant_array const **array);
int ua_variant_array_get_data(const struct ua_variant_array *array, void const **data, int32_t *length);
int ua_variant_get_matrix(const struct ua_variant *v, struct ua_variant_matrix const **matrix);
int ua_variant_matrix_get_data(const struct ua_variant_matrix *matrix, void const **data, int32_t *length);
int ua_variant_matrix_get_dimensions(const struct ua_variant_matrix *matrix, int32_t const **dimensions, int32_t *num_dimensions);
Code: Select all
void demo_array(void)
{
uint32_t data[5] = { 1, 2, 3, 4, 5 };
struct ua_variant value;
/* Available already in V1.1.0 */
ua_variant_set_array(&value, UA_VT_UINT32, data, countof(data));
}
void demo_matrix(void)
{
uint32_t data[3][5] = {
{ 1, 2, 3, 4, 5 },
{ 1, 2, 3, 4, 5 },
{ 1, 2, 3, 4, 5 }
};
struct ua_variant value;
int32_t num_dimensions = 2;
int32_t dimensions[2] = { 3, 5 };
size_t num_elements;
int i;
/* calculate number of elements in data */
for (num_elements = 1, i = 0; i < num_dimensions; ++i) {
num_elements *= dimensions[i];
}
/* Available already in V1.2.0 */
ua_variant_set_matrix(&value, UA_VT_UINT32, data, num_elements, dimensions, num_dimensions);
}
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Full Member
- Posts: 5
- Joined: 16 Oct 2015, 11:10
Re: Matrix of dynamic dimension in an ua_variant variable
Hello,
Thank you for the fast and detailed answer! Then, I suppose I will wait for the next version .
Greetings,
Elena
Thank you for the fast and detailed answer! Then, I suppose I will wait for the next version .
Greetings,
Elena