Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing elements in an Array #382

Open
TanJunKiat opened this issue Sep 14, 2024 · 1 comment
Open

Accessing elements in an Array #382

TanJunKiat opened this issue Sep 14, 2024 · 1 comment

Comments

@TanJunKiat
Copy link

I followed the guide and created a simple OPC-UA server with one of the variables being an array

Variable::new(&array_varab;e_node, "ArrayVariable", "ArrayVariable", vec![0_i32; 3]),

And I want to read and modify the variable in a polling_action node

server.add_polling_action(2000, move || {
    let address_space = address_space.write();
    let value = address_space.get_variable_value(&car_call_request).unwrap().value.unwrap();
}

I am stuck at this point because the elements in the array are inaccessible.

> value: Array(Array { value_type: Int32, values: [Int32(0), Int32(0), Int32(0)], dimensions: None })

I understand that the array is an enum that has a Box as the component (Array(Box<Array>)).

Is there any way to get the elements out of the array?

@einarmo
Copy link
Contributor

einarmo commented Sep 14, 2024

The fields of Array are all public, you can simply access the values field, which is a vector of Variant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants