tokio based async wrapper for libplctag
.
Add plctag-async
to your Cargo.toml
toml
[dependencies]
plctag-async= "0.1"
```rust use plctag_async::{AsyncTag, Error, TagEntry}; use tokio::runtime;
let rt = runtime::Runtime::new().unwrap()?; rt.blockon(async { let path="protocol=ab-eip&plc=controllogix&path=1,0&gateway=192.168.1.120&name=MyTag1&elemcount=1&elem_size=16";// YOUR TAG DEFINITION
let tag = TagEntry::create(path).await.unwrap(); let tagref = tag.get().await.unwrap(); let offset = 0; let value:u16 = tagref.read_value(offset).await.unwrap(); println!("tag value: {}", value);
let value = value + 10; tagref.writevalue(offset, value).await.unwrap(); }); ```
```rust use plctag_async::{AsyncTag, Error, Pool, PoolEntry}; use tokio::runtime;
let rt = runtime::Runtime::new().unwrap()?; rt.blockon(async { let path="protocol=ab-eip&plc=controllogix&path=1,0&gateway=192.168.1.120&name=MyTag1&elemcount=1&elemsize=16";// YOUR TAG DEFINITION let pool = Pool::new(); let tag = pool.entry(path).await.unwrap(); let tagref = tag.get().await.unwrap(); let offset = 0; let value:u16 = tagref.readvalue(offset).await.unwrap(); println!("tag value: {}", value);
let value = value + 10; tagref.writevalue(offset, value).await.unwrap(); }); ```
It's thread-safe to perform operations with plctag-async
.
Please refer to How to use
to setup build environment.
Because mutithread will cause troubles, you need to run tests with:
shell
cargo test -- --test-threads=1
MIT