You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I'm new to opcua and rust. I'm confused about how to set up a setter for a variable node.
I have tried to modify the ”add_example_variables“ function in project “simple-server”.
The modified code is as follows.
fn add_example_variables(server: &mut Server, ns: u16) {
// These will be the node ids of the new variables
let v1_node = NodeId::new(ns, "v1");
let v2_node = NodeId::new(ns, "v2");
let v3_node = NodeId::new(ns, "v3");
let v4_node = NodeId::new(ns, "v4");
let address_space = server.address_space();
let address_space_1 = server.address_space();
// The address space is guarded so obtain a lock to change it
{
let mut address_space = address_space.write();
// Create a sample folder under objects folder
let sample_folder_id = address_space
.add_folder("Sample", "Sample", &NodeId::objects_folder_id())
.unwrap();
// Add some variables to our sample folder. Values will be overwritten by the timer
let _ = address_space.add_variables(
vec![
Variable::new(&v1_node, "v1", "v1", 0 as i32),
Variable::new(&v2_node, "v2", "v2", false),
Variable::new(&v3_node, "v3", "v3", UAString::from("")),
Variable::new(&v4_node, "v4", "v4", 0f64),
],
&sample_folder_id,
);
}
// OPC UA for Rust allows you to push or pull values from a variable so here are examples
// of each method.
// 1) Pull. This code will add getters to v3 & v4 that returns their values by calling
// function.
{
// let address_space = server.address_space();
let mut address_space = address_space.write();
if let Some(ref mut v) = address_space.find_variable_mut(v3_node.clone()) {
let setter = AttrFnSetter::new(
move| _, _, _, value| -> Result<(), StatusCode> {
let now = DateTime::now();
println!("Ready");
let mut address_space = address_space_1.write();
println!("Ok");
address_space.set_variable_value(v3_node.clone(), value, &now, &now);
Ok(())
},
);
v.set_value_setter(Arc::new(Mutex::new(setter)));
}
}
}
I expect that when I modify the value of the v3 node through the client, the function in the setter is triggered, printing out "Ok".
But the program seems to block on the let mut address_space = address_space_1.write(); because the program only outputs "Ready" and no longer reacts to client interactions.
I think it's that I'm not setting the setter correctly, but I don't know how to fix it, please tell me what I should do?
Thanks in advance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm new to opcua and rust. I'm confused about how to set up a setter for a variable node.
I have tried to modify the ”add_example_variables“ function in project “simple-server”.
The modified code is as follows.
I expect that when I modify the value of the v3 node through the client, the function in the setter is triggered, printing out "Ok".
But the program seems to block on the
let mut address_space = address_space_1.write();
because the program only outputs "Ready" and no longer reacts to client interactions.I think it's that I'm not setting the setter correctly, but I don't know how to fix it, please tell me what I should do?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions