Count production and runtime in the PLC using retentive counters and timers, publish them to the HMI interface DB, then use a scheduled task or a button with the LogFileCopy or export functions to write a CSV to USB or a network drive at shift end. Reset shift totals only after the export has succeeded.
- Counters and runtime totals belong in the PLC with retentive memory, so a panel restart never loses production data.
- Separate shift totals from lifetime totals; resetting the wrong one destroys the machine history.
- Export before reset, and confirm the file was written before clearing anything.
Production Data the PLC Should Provide
Everything on a shift report starts as a counter or a timer in the controller. Build them in the PLC where they are safe from a panel restart, and publish them as read-only values to the HMI.
| Value | Source | Data type |
|---|---|---|
| Good parts produced | CTU on the completion sensor | DINT, retentive |
| Rejected parts | CTU on the reject gate | DINT, retentive |
| Machine running time | Accumulating timer while running | DINT seconds, retentive |
| Downtime | Accumulating timer while faulted or idle | DINT seconds, retentive |
| Number of stops | CTU on the falling edge of Running | INT, retentive |
| Longest stop | Maximum of the stop timer | DINT seconds |
| Last cycle time | Timer captured at cycle end | REAL seconds |
Mark the counters and totals retentive so they survive a power cycle. Counter programming details are covered in Siemens PLC counters CTU, CTD and CTUD.
Count from a sensor that sees the finished part, not from the command that starts a cycle. Counting commands means an aborted cycle still counts as production, and the report quietly overstates output.
Shift Totals, Lifetime Totals and Reset Logic
Keep two sets of numbers. Shift totals are reset at every shift change. Lifetime totals never reset and are the basis for maintenance intervals and machine history.
A safe reset sequence looks like this:
- The shift end event occurs, either from a scheduled task or an operator button.
- The current shift values are copied into a snapshot structure.
- The report is written to file from the snapshot.
- The write is confirmed successful.
- Only then are the shift counters cleared, while lifetime totals continue accumulating.
Copying into a snapshot first matters more than it looks. If the report is generated directly from the live counters, a part completed during the export lands in neither the old shift nor the new one.
Protect the reset with a user authorisation so an operator cannot clear production figures accidentally. User groups are covered in HMI user administration and runtime settings.
Displaying the Shift Summary on the Panel
The shift screen should answer three questions at a glance: how much have we made, how much time did we lose, and what stopped us.
- Output block: good parts, rejects and reject percentage as output fields.
- Time block: running time, downtime and availability as a percentage.
- Stop block: number of stops, longest stop and the most recent fault text.
- Rate block: parts per hour, calculated in the PLC rather than the panel.
Do the arithmetic in the PLC. A percentage calculated on the panel exists only there, so the same figure sent to SCADA or a report will not match. One calculation in the controller keeps every display consistent.
Add a small trend of parts per hour across the shift if the panel supports data logging, using the setup in HMI trends and data logs. A flat line with one deep notch tells a supervisor exactly when the problem happened.
Build production reporting in class
Sessions cover PLC counters, HMI reports, WinCC archives and SQL Server reporting for real plants.
Exporting the Report to CSV
Comfort panels can write CSV files to an SD card, a USB stick or a mapped network path. There are two practical routes.
Data log export
Log the shift values to a data log configured as segmented, so each shift produces its own file. Then use the system function that copies or closes the log at shift end. The file lands on the storage medium in CSV format ready for Excel.
Scripted export
On panels that support VBScript, a script can assemble a formatted report with a header row, the shift values and a timestamp, then write it to the target path. This gives full control over layout at the cost of a script to maintain.
| Trigger | Configured in | Notes |
|---|---|---|
| Scheduled task at a fixed time | Scheduled tasks, time-of-day trigger | Reliable for fixed shift patterns |
| Operator button at shift end | Button event calling the export function | Suits variable shift timings |
| PLC bit at end of production run | Scheduled task on tag change | Best for batch or order based production |
Always test what happens when the USB stick is missing or the network path is unavailable. The export must fail visibly with an alarm, and the reset must not run. A silent failure that also clears the counters loses a shift of data permanently.
Hands-On Lab: Build and Export a Shift Report
Hands-on- TIA Portal with WinCC Comfort and a panel or simulation
- PLC counters and runtime timers with retentive memory
- An SD card, USB stick or simulated storage path
- Estimated time: 45 minutes
Build the counters
Create retentive counters for good parts, rejects and stops, plus accumulating timers for running and downtime.
Publish and display
Copy the values into the HMI interface DB and build a shift screen with output fields and calculated rate and availability.
Create the snapshot
Add a snapshot structure and copy shift values into it when a shift end bit is set.
Configure the export
Set up a segmented data log or a scheduled task that writes the snapshot to CSV on the storage medium.
Test the failure case
Remove the storage medium and trigger the export again.
Production data survives restarts, shift and lifetime totals are separate, the export produces a readable CSV, and a failed export never clears the counters.
Frequently asked questions
Should counters be kept in the PLC or on the HMI?
In the PLC with retentive memory. A panel can be replaced, restarted or swapped for a spare, and production data must not depend on it.
Why copy values to a snapshot before writing the report?
So parts produced during the export are not lost between the closing shift and the new one. The report is written from a frozen set of values.
Can a Comfort panel write directly to a network drive?
Yes, if the path is reachable and the panel has permission. Always handle the case where the network is unavailable, so the export fails visibly instead of silently.
Where should availability and parts per hour be calculated?
In the PLC. Calculating on the panel means SCADA, reports and the panel can each show a slightly different number for the same shift.
