#automation #devices #plc #beckhoff #file-access #server-client

ads

Client for the Beckhoff Automation Device Specification protocol for PLCs

10 releases

0.4.4 Oct 3, 2024
0.4.3 Nov 17, 2022
0.4.2 Sep 22, 2022
0.4.1 Aug 26, 2022
0.0.1 May 1, 2018

#114 in Hardware support

Download history 14/week @ 2024-08-22 16/week @ 2024-08-29 23/week @ 2024-09-05 25/week @ 2024-09-12 39/week @ 2024-09-19 44/week @ 2024-09-26 187/week @ 2024-10-03 62/week @ 2024-10-10 43/week @ 2024-10-17 16/week @ 2024-10-24 27/week @ 2024-10-31 27/week @ 2024-11-07 42/week @ 2024-11-14 59/week @ 2024-11-21 54/week @ 2024-11-28 28/week @ 2024-12-05

185 downloads per month
Used in ads-proxy

MIT/Apache

150KB
3K SLoC

ads

Build status crates.io docs.rs

This crate allows to connect to Beckhoff TwinCAT devices and other servers speaking the ADS (Automation Device Specification) protocol.

Installation

Use with Cargo as usual, no system dependencies are required.

[dependencies]
ads = "0.4"

Rust version

Minimum supported Rust version is 1.63.0.

Usage

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(())
}

Features

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.

Examples

A utility called adstool is found under examples/, very similar to the one provided by the C++ library.

Dependencies

~1.6–2.3MB
~41K SLoC