plctag-rs
a rust wrapper of libplctag, with rust style APIs and useful extensions.
How to use
Add plctag to your Cargo.toml
[]
= "0.4"
crates
- plctag reexports everything from below crates.
- plctag-core a rust wrapper of libplctag, with rust style APIs and useful extensions.
- plctag-async async wrapper.
- plctag-log log adapter for
libplctag - plctag-derive macros for
plctag - plctag-sys native libplctag binding
Examples
read/write tag
use ;
let timeout = 100;//ms
let path="protocol=ab-eip&plc=controllogix&path=1,0&gateway=192.168.1.120&name=MyTag1&elem_count=1&elem_size=16";// YOUR TAG DEFINITION
let tag = new.unwrap;
//read tag
let status = tag.read;
assert!;
let offset = 0;
let value:u16 = tag.get_value.unwrap;
println!;
let value = value + 10;
tag.set_value.unwrap;
//write tag
let status = tag.write;
assert!;
println!;
UDT
read/write UDT
use ;
// define your UDT
let timeout = 100; //ms
// YOUR TAG DEFINITION
let path = "protocol=ab-eip&plc=controllogix&path=1,0&gateway=192.168.1.120&name=MyTag2&elem_count=2&elem_size=16";
let tag = new.unwrap;
//read tag
let status = tag.read;
assert!;
let offset = 0;
let mut value: MyUDT = tag.get_value.unwrap;
println!;
value.v1 += 10;
tag.set_value.unwrap;
//write tag
let status = tag.write;
assert!;
println!;
Note:
Do not perform expensive operations when you derives Decode or Encode.
Async
use ;
use runtime;
let rt = new.unwrap;
let res: = rt.block_on;
res.unwrap;
Path Builder
use *;
use RawTag;
let timeout = 100;
let path = default
.protocol
.gateway
.plc
.name
.element_size
.element_count
.path
.read_cache_ms
.build
.unwrap;
let tag = new.unwrap;
let status = tag.status;
assert!;
Logging adapter for libplctag
use log_adapt;
use set_debug_level;
use DebugLevel;
log_adapt; //register logger
set_debug_level; // set debug level
// now, you can receive log messages by any of logging implementations of crate `log`
Build
Please refer to How to build to setup build environment.
Static build
Please refer to Static build
Bench
cargo bench
The plots and saved data are stored under target/criterion/$BENCHMARK_NAME/
Bench Result
Processor: Intel(R) Core(TM) i7-9700KF CPU @ 3.60GHz 3.60 GHz RAM: 64.0 GB
async read time: [4.3608 ms 4.3937 ms 4.4287 ms]
change: [-3.7035% -2.5545% -1.3730%] (p = 0.00 < 0.05)
Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
7 (7.00%) high mild
async batch-20 read time: [11.852 ms 11.949 ms 12.054 ms]
change: [-2.2194% -0.9951% +0.2445%] (p = 0.11 > 0.05)
No change in performance detected.
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) low mild
3 (3.00%) high mild
1 (1.00%) high severe
sync read time: [3.1016 ms 3.1272 ms 3.1553 ms]
change: [-2.4462% -1.1947% +0.1535%] (p = 0.07 > 0.05)
No change in performance detected.
Found 9 outliers among 100 measurements (9.00%)
6 (6.00%) high mild
3 (3.00%) high severe
License
MIT