#ads #plc #real-time #industrial #twincat

roboplc-io-ads

RoboPLC I/O 连接器用于 TwinCAT/ADS

4 个稳定版本

1.2.0 2024年6月30日
1.1.0 2024年6月15日
1.0.1 2024年4月26日

硬件支持 中排名第 406

Download history 176/week @ 2024-04-26 7/week @ 2024-05-03 1/week @ 2024-05-24 1/week @ 2024-05-31 208/week @ 2024-06-14 4/week @ 2024-06-21 185/week @ 2024-06-28 34/week @ 2024-07-05

每月下载量 288

自定义许可

160KB
3.5K SLoC

RoboPLC I/O 连接器用于 TwinCAT/ADS crates.io 页面 docs.rs 页面

简介

ADS 是由 Beckhoff GmbH 开发的可编程逻辑控制器(PLC)和 TwinCAT 自动化系统使用的本地协议。

ADS 规范可以在 Beckhoff 信息系统页面上找到:ADS 规范

此包为 RoboPLC 提供了 I/O 连接器。

该包不是免费用于任何商业或生产用途。有关更多信息,请参阅 https://github.com/roboplc/roboplc-io-ads/blob/main/LICENSE.md

示例

RoboPLC I/O 映射

use ads::client::Client;
use roboplc::{comm::Timeouts, io::IoMapping, prelude::binrw};
use roboplc_io_ads as ads;
use std::time::Duration;

#[binrw]
struct MyStruct {
    field1: u32,
    field2: f32,
    field3: [u8; 8],
    field4: f64
}

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

// The socket is automatically reconnected if the connection is lost.
let (client, reader) = Client::new(("plchost", ads::PORT),
    Timeouts::new(Duration::from_secs(1)),
    ads::Source::Auto).unwrap();

// The reader thread MUST be started manually. Apply real-time settings if needed.
std::thread::spawn(move || { reader.run(); });

// 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));

// Create a mapping for a symbol. The mapping contains a handle (automatically recreated on
// each reconnect) as well as a pre-allocated buffer.
let mut mapping = device.mapping("MY_SYMBOL", 24);

// Read a structure from the PLC.
let mut data: MyStruct = mapping.read().unwrap();
data.field1 += 1;
// Write the modified structure back to the PLC.
mapping.write(&data).unwrap();

示例

直接使用

use ads::client::Client;
use roboplc::comm::Timeouts;
use roboplc_io_ads as ads;
use std::time::Duration;

let (client, reader) = Client::new(("plchost", ads::PORT),
    Timeouts::new(Duration::from_secs(1)),
    ads::Source::Auto).unwrap();

std::thread::spawn(move || { reader.run(); });

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().unwrap().0 == ads::AdsState::Run);

// Request a handle to a named symbol in the PLC instance.
let handle = ads::Handle::new(&device, "MY_SYMBOL").unwrap();

// Read data in form of an u32 from the handle.
let value: u32 = handle.read_value().unwrap();
println!("MY_SYMBOL value is {}", value);

API 与免费版本略有不同,因为许多方法已被重写为更少 panic 和线程安全的代码。某些内部类型已被 RoboPLC 默认值替换。

该包代码基于 https://github.com/birkenfeld/ads-rs 项目,(c) Georg Brandl, Serhij Symonenko 和其他贡献者。

商业客户端还支持

  • 自动重连
  • 多线程
  • 实时安全性
  • 来自供应商的企业级支持

注意:由于客户端具有异步方式读取循环,强烈建议使用超时。如果远程不响应,没有超时的请求将永久卡住。

依赖关系

~9–18MB
~248K SLoC