Reading production statistics
Goal: count the labels printed per shift, and detect missed prints.
Printer setup
Add read-only statistic mappings, using 32-bit types:
| Address | Mapping | Name | Data type |
|---|---|---|---|
| 11 | Statistic | printer.NoLabel.labels.printed | UINT32 |
| 50 | Statistic | printer.NoLabel.triggers.ignored.total | UINT32 |
See Statistics for the available counters. (The example mapping list only has the first one.)
PLC
The statistics count from when the printer started, and cannot be reset over Modbus. To count per shift, store the value at the start of the shift, and subtract it from later readings.
The count starts over at 0 when the printer restarts. If a reading is lower than the stored start value, the printer has restarted: add the stored count to the shift total, and take the new reading as the start value.
An increase in ignored triggers means products passed the printer without being printed, for example because it was not ready.
Try it
from common import *
printed = from_uint32(check(client.read_holding_registers(11, count=2)).registers)
print(f"{printed} labels printed since the printer started")