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

Broken docs.rs documentation. How to do a simple one time read without subscription? #295

Open
kwinz opened this issue Oct 27, 2023 · 5 comments · May be fixed by #369
Open

Broken docs.rs documentation. How to do a simple one time read without subscription? #295

kwinz opened this issue Oct 27, 2023 · 5 comments · May be fixed by #369

Comments

@kwinz
Copy link

kwinz commented Oct 27, 2023

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

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.

@kwinz
Copy link
Author

kwinz commented Oct 30, 2023

Besides the broken link in the README.md and not finding Session documentation.
I also created a question in discussions: #296 (comment)

@mfwre
Copy link

mfwre commented Nov 7, 2023

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.

@kwinz
Copy link
Author

kwinz commented Nov 8, 2023

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/ReadValueIds 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.

@mfwre
Copy link

mfwre commented Nov 9, 2023

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 NodeIds.

I'll attach a screenshot of the page here for convenience.
20231109_13h14m48s_grim

@AiyionPrime
Copy link
Contributor

@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?

@AiyionPrime AiyionPrime linked a pull request Jul 25, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants