Produce a Readings Report
hard
Captures eight readings and holds their average, spread, extremes and first out-of-limit position.
What it teaches
Combine Capture Machine Readings, Measure Reading Spread and Measure Reading Extremes into a report that remains useful after live data changes. Snapshot first, calculate from that snapshot, and publish a complete result. What matters is that the report finishes, not how many scans it takes.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Report | Input | BOOL | 0 | Request a report on the current readings |
| Cfg_Low | Input | REAL | 0 | Inclusive lower acceptable reading |
| Cfg_High | Input | REAL | 10 | Inclusive upper acceptable reading |
| Sts_Ready | Output | BOOL | 0 | 1 when the latest requested report is complete |
| Out_Mean | Output | REAL | 0 | Mean of the captured readings |
| Out_Spread | Output | REAL | 0 | Sample standard deviation of the captured readings |
| Out_Min | Output | REAL | 0 | Lowest captured reading |
| Out_Max | Output | REAL | 0 | Highest captured reading |
| Out_FirstOutside | Output | DINT | 0 | First out-of-limit snapshot index, or -1 if all are within limits |
| Ref_Live | InOut | REAL[8] | — | Read-only live readings, eight of them |
| Ref_Snapshot | InOut | REAL[8] | — | Captured readings in original order |
Required behavior
- In_Report acts once on a change from 0 to 1. Holding it on does not repeat the report.
- On that scan, copy all eight Ref_Live readings into Ref_Snapshot and remember Cfg_Low and Cfg_High. Never write Ref_Live.
- Out_Mean, Out_Min and Out_Max are the average, lowest and highest snapshot readings.
- Out_Spread is the sample standard deviation: divide the sum of squared differences from the mean by 7, then take the square root.
- Out_FirstOutside is the lowest snapshot index whose reading is below Cfg_Low or above Cfg_High. A reading equal to a limit is inside. No such reading gives -1.
- Finish within four scans, counting the request scan. Sts_Ready is 0 while working and 1 once the report is complete.
- Publish the five numbers together. Keep the previous report until the next one completes, even if live readings or limits change.
- A request that arrives while working is discarded, not queued. A new report needs a new rising edge.
- Before the first report, the numbers are 0 and Out_FirstOutside is -1. Cfg_Low is at most Cfg_High. Readings and limits are finite and at most 10000 in size.