Crate ads

source · []
Expand description

Work with PLCs using the ADS protocol

Introduction

ADS is the native protocol used by programmable logic controllers (PLCs) and the TwinCAT automation system produced by Beckhoff GmbH.

The specification can be found on their Information System pages.

Example

// 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 = ads::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);

Re-exports

pub use client::AdsState;
pub use client::Client;
pub use client::Device;
pub use client::Source;
pub use client::Timeouts;
pub use errors::Error;
pub use errors::Result;
pub use file::File;
pub use netid::AmsAddr;
pub use netid::AmsNetId;
pub use netid::AmsPort;
pub use symbol::Handle;

Modules

Contains the TCP client to connect to an ADS server.
Defines ADS error types.
File access over ADS.
Well-known index groups as defined here and here.
Contains the AMS NetId and related types.
Everything to do with ADS notifications.
Well known ADS ports as defined here.
Utilities to generate and work with fixed-length string types.
Wrappers for symbol operations and symbol handles.
Implements the Beckhoff UDP message protocol for basic operations.

Macros

Create a new type representing a STRING(len) in the PLC, which can be used with Device::read/write_value or Symbol::read/write_value.
Create a new type representing a WSTRING(len) in the PLC, which can be used with Device::read/write_value or Symbol::read/write_value.

Constants

The default port for TCP communication.
The default port for UDP communication.