Broken docs.rs documentation. How to do a simple one time read without subscription?
kwinz opened this issue · 5 comments
Hi,
https://docs.rs/opcua/0.11.0/opcua/client/index.html shows how to start a subscription, but now how to one time poll/read/write a variable. Neither does the code in https://github.com/locka99/opcua/tree/master/samples
https://docs.rs/opcua/0.11.0/opcua/client/index.html links to
- https://docs.rs/opcua/0.11.0/opcua/client/client_builder/struct.ClientBuilder.html (The requested resource does not exist)
- https://docs.rs/opcua/0.11.0/opcua/client/session/struct.Session.html (The requested resource does not exist)
Both of those links are broken. Probably the info how to read a variable was somewhere in that Session documentation?
I also tried https://docs.rs/opcua/0.10.0/opcua/client/session/struct.Session.html but that doesn't work either.
Ironically the only breadcrumb of an example how to do a one off read I found in an old closed issue #93 (although that code is outdated and doesn't compile any more with the current library) and obviously reading the source code helps a bit.
Besides the broken link in the README.md and not finding Session documentation.
I also created a question in discussions: #296 (comment)
You can find the Session documentation here.
It is indeed broken if you click the link from the opcua::client
description. You can reach it following this route: client > prelude > Session
.
In the Session documentation you'll find the AttributeService
trait which gives you the fn read
method.
To do a simple read you can then:
let mut client = Client::new(config);
let session = client.connect_to_endpoint(..);
let values = session.read(&[ReadValueId], TimestampsToReturn::Both, 0f64);
Of course this is pseudo-code. Create an array of NodeId you want to get the value from, convert it into an array of ReadValueId (it implements Into
) and pass it to the read
method with some other parameters.
I hope this was useful.
Thank you @mfwre, much appreciated! I am not sure if you have time to also look at my question in the discussions #296. Specifically how to list all available variable names/paths/ReadValueId
s on a OPC UA server with this crate as client. I found the browse
function in the Session documentation that you linked, but I am afraid I am unsure how to use it to query all existing variables/nodes.
Hi, this is a more tricky answer.
The function you listed, browse
, is the correct one.
If you have no clue on which nodes to start browsing on simply call the method NodeId::root_node_id()
to get the server's root node.
As for what parameters to use in the function (#296: I'm referring to the \\ ????
comments in your linked question) you'll find a detailed explanation in the OPC-UA specification; part 4 - section 5.8.2 and 5.8.3.
You still need to implement a "recursive" browsing yourself by repeating the browse
call with different NodeId
s.
@kwinz I take it, the second half of this issue is resolved,
so all that's left here is to fix the dead links in the documentation?