Crates.io | ads |
lib.rs | ads |
version | 0.4.4 |
source | src |
created_at | 2018-05-01 16:03:01.474482 |
updated_at | 2024-10-03 13:06:56.894885 |
description | Client for the Beckhoff Automation Device Specification protocol for PLCs |
homepage | |
repository | https://github.com/birkenfeld/ads-rs |
max_upload_size | |
id | 63292 |
size | 216,304 |
ads
This crate allows to connect to Beckhoff TwinCAT devices and other servers speaking the ADS (Automation Device Specification) protocol.
Use with Cargo as usual, no system dependencies are required.
[dependencies]
ads = "0.4"
Minimum supported Rust version is 1.63.0.
A simple example:
fn main() -> ads::Result<()> {
// Open a connection to an ADS device identified by hostname/IP and port.
// For TwinCAT devices, a route must be set to allow the client to connect.
// The source AMS address is automatically generated from the local IP,
// but can be explicitly specified as the third argument.
let client = ads::Client::new(("plchost", ads::PORT), ads::Timeouts::none(),
ads::Source::Auto)?;
// Specify the target ADS device to talk to, by NetID and AMS port.
// Port 851 usually refers to the first PLC instance.
let device = client.device(ads::AmsAddr::new([5, 32, 116, 5, 1, 1].into(), 851));
// Ensure that the PLC instance is running.
assert!(device.get_state()?.0 == ads::AdsState::Run);
// Request a handle to a named symbol in the PLC instance.
let handle = Handle::new(device, "MY_SYMBOL")?;
// Read data in form of an u32 from the handle.
let value: u32 = handle.read_value()?;
println!("MY_SYMBOL value is {}", value);
// Connection will be closed when the client is dropped.
Ok(())
}
All ADS requests are implemented.
Further features include support for receiving notifications from a channel, file access via ADS, and communication via UDP to identify an ADS system and set routes automatically.
A utility called adstool
is found under examples/
, very similar to the one
provided by the C++ library.