#industrial-automation #process #automation #plc #tags #access #data-access

no-std process-image

Zero-cost abstraction for convenient access to process image tags

4 releases

new 0.2.1 Nov 3, 2024
0.2.0 Apr 12, 2024
0.1.1 Sep 18, 2023
0.1.0 Sep 9, 2023

#207 in Memory management


Used in profirust

MIT/Apache

26KB
525 lines

process-image crates.io page docs.rs

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.

Example

Absolute Addressing

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;

Symbolic Addressing

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;
}

License

Licensed under either of

at your option.

Contribution

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.

No runtime deps