birkenfeld / ads-rs

Rust crate to access PLCs via the Beckhoff ADS protocol
https://crates.io/crates/ads
Apache License 2.0
45 stars 8 forks source link

Getting the symbol type of a specific handle #20

Closed goudcode closed 3 months ago

goudcode commented 1 year ago

When using this library, I am trying to get the symbol information for a specific handle.

I am using the get_symbol_information method to retrieve all the symbols that are in the PLC. However, looking through the docs and (quickly) through the implementation, I could not find a way to map an instance of a Handle to a Symbol in TypeMap.

let symbol_info = ads::symbol::get_symbol_info(device)?;

let handle_name= "MAIN.m_info";
let handle = Handle::new(device, handle_name)?;
// How to get the Symbol/Type for this handle?

Is this possible? If not, I might have some time to help with the implementation if needed.

birkenfeld commented 3 months ago

First of all, sorry for not responding in a long time. But in case you still need this information, the first element returned by get_symbol_info is the list of symbols, so you'll want to find the one whose sym.name is the same as your handle_name. Then you can check the type in the type map (second element returned by get_symbol_info) by looking up sym.typ.