Crates.io | process-image |
lib.rs | process-image |
version | 0.2.1 |
source | src |
created_at | 2023-09-09 12:06:40.274712 |
updated_at | 2024-11-03 13:21:18.504228 |
description | Zero-cost abstraction for convenient access to process image tags. |
homepage | |
repository | https://github.com/rahix/process-image |
max_upload_size | |
id | 968114 |
size | 40,320 |
process-image
process-image
is a Rust crate for conveniently accessing data inside a
process image using zero-cost abstractions. A process image (short PI) is
nothing else than a block of memory describing state. This concept stems from
the industrial automation world where such process images are used to represent
the state of all inputs and outputs used to control a machine or process.
process-image
provides abstractions for absolute addressing of tags (=values)
and for building tag tables that then allow symbolic access.
use process_image as pi;
let mut buf = [0x00; 8];
// Absolute tag addressing
let sensor_limit_1 = pi::tag!(&mut buf, X, 5, 6); // Read %MX3.6
let sensor_limit_2 = pi::tag!(&mut buf, X, 5, 7); // Read %MX3.7
let temperature: u16 = pi::tag!(&mut buf, W, 2); // Read %MW2
*pi::tag_mut!(&mut buf, X, 0, 2) = true; // Set %MX0.2 := TRUE;
*pi::tag_mut!(&mut buf, W, 6) = 2300; // Set %MW6 := 2300;
use process_image as pi;
let mut buf = [0x00; 8];
// Build tag table definition
pi::process_image! {
// Process Image over 8 bytes
pub struct PiExample, mut PiExampleMut: 8 {
pub indicator_light: (X, 0, 2),
pub sensor_limit_1: (X, 5, 6),
pub sensor_limit_2: (X, 5, 7),
pub temperature: (W, 2),
pub setpoint: (W, 6),
}
}
// Read-access only
let pi = PiExample::try_from(&buf).unwrap();
dbg!(pi.sensor_limit_1());
dbg!(pi.sensor_limit_2());
dbg!(pi.temperature());
// Read-write access
let mut pi = PiExampleMut::try_from(&mut buf).unwrap();
if *pi.sensor_limit_1() {
*pi.indicator_light() = true;
*pi.setpoint() = 2300;
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.