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.

Example

Absolute Addressing

```rust use process_image as pi; let mut buf = [0x00; 8];

// Absolute tag addressing let sensorlimit1 = pi::tag!(&mut buf, X, 5, 6); // Read %MX3.6 let sensorlimit2 = pi::tag!(&mut buf, X, 5, 7); // Read %MX3.7 let temperature: u16 = pi::tag!(&mut buf, W, 2); // Read %MW2

*pi::tagmut!(&mut buf, X, 0, 2) = true; // Set %MX0.2 := TRUE; *pi::tagmut!(&mut buf, W, 6) = 2300; // Set %MW6 := 2300; ```

Symbolic Addressing

```rust use process_image as pi; let mut buf = [0x00; 8];

// Build tag table definition pi::processimage! { // Process Image over 8 bytes pub struct PiExample, mut PiExampleMut: 8 { pub indicatorlight: (X, 0, 2), pub sensorlimit1: (X, 5, 6), pub sensorlimit2: (X, 5, 7), pub temperature: (W, 2), pub setpoint: (W, 6), } }

// Read-access only let pi = PiExample::tryfrom(&buf).unwrap(); dbg!(pi.sensorlimit1()); dbg!(pi.sensorlimit_2()); dbg!(pi.temperature());

// Read-write access let mut pi = PiExampleMut::tryfrom(&mut buf).unwrap(); if *pi.sensorlimit1() { *pi.indicatorlight() = 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.