-
Hi, I'm very new to OPC in general, so this might be a trivial question. I have a Weintek OPC server which reads data from a PLC. What I did is: VariableBuilder::new(&node_id, server_attr, server_attr)
.property_of(/* ... */)
.data_type(/* ... */)
/* I tried with and without these settings
.historizing(true)
.history_readable()
.minimum_sampling_interval(500f64)
*/
.has_type_definition(VariableTypeId::PropertyType)
.value_getter(AttrFnGetter::new_boxed(
move |_, _, _, _, _, _| -> Result<Option<DataValue>, StatusCode> {
/* following client.read() call is a connection from the bridge server
* to the Weintek server
* */
let session = client.read();
session
.read(
&[NodeId::new(2, weintek_node_srting_id).into()],
TimestampsToReturn::Server,
1.0,
)
.map(|v| v.into_iter().nth(0))
},
))
.insert(address_space); On another OPC client I tried to subscribe to these nodes via let subscription_id = session.write()
.create_subscription(
2000.0,
10,
30,
0,
0,
true,
DataChangeCallback::new(|changed_data| {
println!("Data change:");
changed_data.iter().for_each(|i| println!("{i:#?}"));
}),
)
.unwrap();
// followed by a
session.write()
.create_monitored_items(
subscription_id,
TimestampsToReturn::Server,
&items // Vec<MonitoredItemCreateRequest> created from the NodeIds
)
.unwrap();
Session::run(session) The code compiles and runs. On srv, if I use some tools like I don't see however prints made by the Other somewhat related questions: what is the point of creating a The last one isn't that much a question. But feel free to suggest other ways to solve my bridging solution. I'm still new to automation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It appears I was the coconut all along. Putting all the setting up the subscription and monitored items calls in a separated expression block fixed the issue. The subscription fires DataChangeCallback events now. |
Beta Was this translation helpful? Give feedback.
It appears I was the coconut all along.
Since I was coding a PoC I wrote all piece of code in a single
main.rs
file.Putting all the setting up the subscription and monitored items calls in a separated expression block fixed the issue. The subscription fires DataChangeCallback events now.