pub struct Client { /* private fields */ }Expand description
An ADS client to use in combination with the TC1000 ADS router.
The client opens a port on the local ADS router in order to submit ADS requests. Use the Client::new method to create an instance.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn read(
&self,
idx_grp: u32,
idx_offs: u32,
data: &mut [u8],
) -> Result<u32>
pub async fn read( &self, idx_grp: u32, idx_offs: u32, data: &mut [u8], ) -> Result<u32>
Submit an asynchronous ADS Read request.
§Example
use ads_client::{ClientBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let ads_client = ClientBuilder::new("5.80.201.232.1.1", 851).build().await?;
// Get symbol handle
let mut hdl : [u8; 4] = [0; 4];
let symbol = b"MAIN.n_cnt_a";
if let Err(err) = ads_client.read_write(0xF003, 0, &mut hdl, symbol).await{
println!("Error: {}", err.to_string());
}
let n_hdl = u32::from_ne_bytes(hdl.try_into().unwrap());
if n_hdl != 0 {
println!("Got handle!");
let mut plc_n_cnt_a : [u8; 2] = [0; 2];
let read_hdl = ads_client.read(0xF005, n_hdl, &mut plc_n_cnt_a).await;
match read_hdl {
Ok(_bytes_read) => {
let n_cnt_a = u16::from_ne_bytes(plc_n_cnt_a.try_into().unwrap());
println!("MAIN.n_cnt_a: {}", n_cnt_a);
},
Err(err) => println!("Read failed: {}", err.to_string())
}
}
Ok(())
}Checkout the examples read_symbol and read_symbol_async.
Source§impl Client
impl Client
Sourcepub async fn write(
&self,
idx_grp: u32,
idx_offs: u32,
data: &[u8],
) -> Result<()>
pub async fn write( &self, idx_grp: u32, idx_offs: u32, data: &[u8], ) -> Result<()>
Submit an asynchronous ADS Write request.
§Example
use ads_client::{ClientBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let ads_client = ClientBuilder::new("5.80.201.232.1.1", 851).build().await?;
// Get symbol handle
let mut hdl : [u8; 4] = [0; 4];
let symbol = b"MAIN.n_cnt_a";
if let Err(err) = ads_client.read_write(0xF003, 0, &mut hdl, symbol).await{
println!("Error: {}", err.to_string());
}
let n_hdl = u32::from_ne_bytes(hdl.try_into().unwrap());
if n_hdl != 0 {
println!("Got handle!");
let n_cnt_a : u16 = 1000;
match ads_client.write(0xF005, n_hdl, &n_cnt_a.to_ne_bytes()).await{
Ok(_) => println!("Variable successfully written!"),
Err(err) => println!("Error: {}", err.to_string())
}
}
Ok(())
}Checkout the examples write_symbol and write_symbol_async.
Source§impl Client
impl Client
Sourcepub async fn read_state(&self) -> Result<StateInfo>
pub async fn read_state(&self) -> Result<StateInfo>
Submit an asynchronous ADS Read State request.
§Example
use ads_client::{ClientBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let ads_client = ClientBuilder::new("5.80.201.232.1.1", 10000).build().await?;
match ads_client.read_state().await {
Ok(state) => println!("State: {:?}", state),
Err(err) => println!("Error: {}", err.to_string())
}
Ok(())
}Checkout the examples read_state and read_state_async.
Source§impl Client
impl Client
Sourcepub async fn read_write(
&self,
idx_grp: u32,
idx_offs: u32,
read_data: &mut [u8],
write_data: &[u8],
) -> Result<u32>
pub async fn read_write( &self, idx_grp: u32, idx_offs: u32, read_data: &mut [u8], write_data: &[u8], ) -> Result<u32>
Submit an asynchronous ADS Read Write request.
§Example
use ads_client::{ClientBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let ads_client = ClientBuilder::new("5.80.201.232.1.1", 851).build().await?;
// Get symbol handle
let mut hdl : [u8; 4] = [0; 4];
let symbol = b"MAIN.n_cnt_a";
if let Err(err) = ads_client.read_write(0xF003, 0, &mut hdl, symbol).await{
println!("Error: {}", err.to_string());
}
Ok(())
}Checkout the examples read_symbol and read_symbol_async.
Source§impl Client
impl Client
Sourcepub async fn add_device_notification(
&self,
idx_grp: u32,
idx_offs: u32,
attributes: &AdsNotificationAttrib,
handle: &mut u32,
callback: Notification,
user_data: Option<&Arc<Mutex<BytesMut>>>,
) -> Result<()>
pub async fn add_device_notification( &self, idx_grp: u32, idx_offs: u32, attributes: &AdsNotificationAttrib, handle: &mut u32, callback: Notification, user_data: Option<&Arc<Mutex<BytesMut>>>, ) -> Result<()>
Submit an asynchronous ADS Add Device Notification request.
Checkout the extensive examples notification and notification_async.
Source§impl Client
impl Client
Sourcepub async fn delete_device_notification(&self, handle: u32) -> Result<()>
pub async fn delete_device_notification(&self, handle: u32) -> Result<()>
Submit an asynchronous ADS Delete Device Notification request.
Checkout the extensive examples notification and notification_async.
Source§impl Client
impl Client
Sourcepub async fn read_device_info(&self) -> Result<DeviceStateInfo>
pub async fn read_device_info(&self) -> Result<DeviceStateInfo>
Submit an asynchronous ADS Read Device Info request.
§Example
use ads_client::{ClientBuilder, Result};
#[tokio::main]
async fn main() -> Result<()> {
let ads_client = ClientBuilder::new("5.80.201.232.1.1", 10000).build().await?;
match ads_client.read_device_info().await {
Ok(device_info) => {
println!("DeviceInfo: TwinCAT {}.{}.{} , Device Name: {}",
device_info.major,
device_info.minor,
device_info.build,
device_info.device_name)
}
Err(err) => println!("Error: {}", err.to_string())
}
Ok(())
}Checkout the examples read_device_info and read_device_info_async.