Reset the batch counters by owning them: declare PassBatch and FailBatch as inspection script variables, increment them in the judgment step, and on the rising edge of the coil-complete input copy them into a log row, zero them, and clear the chart's history property in the same UI cycle. The built-in reset cannot do this job: the menu command Inspection>>Reset Inspection Statistics will not run from the script, and even by hand it leaves the chart's x-axis counting. You are measuring tooth sets in a coil of band-saw stock: the operator display shows #Pass and #Fail, a sweep chart plots every set, and at coil change all of it must go back to zero. This guide gives you the variable list, the reset sequence, a full coil in numbers, and the checks to run before the next coil starts.
Why can't the script reset the built-in #Pass and #Fail counters?
The built-in counters belong to the inspection engine, so the only documented reset is the menu command Inspection>>Reset Inspection Statistics — an operator action — and it zeros #Parts Inspected, #Pass and #Fail while leaving the sweep chart running.
In this class of software the state diagram has no step that clears them, and there is no hidden script call to hunt for. The menu command has a second defect you have already seen: the chart keeps its own point buffer, so the counters read zero while the trace plots on from its old length. Re-selecting the running inspection (Select Inspection pointed at itself) reloads everything, but it reinitializes your variables with it, and any tuning not saved in the inspection file is gone mid-run. That leaves one sound answer: count in your own layer and reset it yourself.
How do you build per-batch counters step by step?
Declare six variables in the inspection script, drive them from the judgment step and one edge, and the batch layer is done: two counters, two totals, one batch ID and one chart flag. None of them duplicates the engine's job — this is the per-batch layer the engine does not give you.
- Declare the variables with types and starting values:
BatchID(integer, 1),PassBatch(integer, 0),FailBatch(integer, 0),PassTotal(integer, 0),FailTotal(integer, 0),ResetChart(boolean, FALSE). - In the measurement step, after each set is judged: on a pass run
PassBatch = PassBatch + 1, otherwiseFailBatch = FailBatch + 1. Never read #Pass or #Fail inside the script. - Display parts inspected as the sum, never as a third counter you also increment — two counters incremented separately drift apart, a sum cannot.
- On the rising edge of the coil-complete input, copy first:
LastPass = PassBatch,LastFail = FailBatch; add them intoPassTotalandFailTotal; append one log row — timestamp, BatchID, LastPass, LastFail, yield. - Then zero:
PassBatch = 0,FailBatch = 0,BatchID = BatchID + 1,ResetChart = TRUE. - In the Custom UI code that the Update Inspection UI step calls, clear the chart's history property — a property node set to an empty array — whenever
ResetChartis TRUE, then setResetChart = FALSEin the same pass. - Bind the operator display to
PassBatchandFailBatch. Take the built-in #Pass / #Fail readout off the panel, or relabel it as run totals, so two numbers can never disagree on one screen.
The order of steps 4 and 5 is the whole trick: the log row must exist before the zeros. If your engine writes files asynchronously, close the row before the edge returns.
When should the counters reset, and what happens first?
Reset once, on the rising edge of the coil-complete signal, after the totals are copied out — never on inspection start and never on a timer. The order inside the edge is fixed: copy, log, add to totals, zero, bump the batch ID, raise the chart flag. One edge per batch. If the coil-complete bit can bounce, debounce it in the PLC or in the script, because a second edge a few milliseconds later halves your batch and burns a batch ID. When the PLC already owns the coil count — most lines do — take the trigger from it rather than inventing a camera-side one; the machine vision PLC integration guide covers the handshakes. Switch the light recipe on the same edge if a new coil means new material: one event, one set of changes, one log row.
How do you reset the sweep chart back to zero?
Clear the chart's history buffer from the Custom UI code that the Update Inspection UI step already runs, gated by a hidden boolean the script sets at coil complete — the x-axis then restarts in the same cycle the counters zero. The chart object owns its point buffer, and the menu reset command never touches it, which is the mismatch on your screen. Setting the history property to an empty array empties the buffer, so the first set of the new coil lands at x = 0. Two rules keep it clean: clear the boolean in the same pass so one edge means one clear, and plot against the within-batch set number rather than wall-clock time, so every coil starts at zero and coils overlay for comparison.
What does a full coil look like in the numbers?
One coil of 8,400 inspected sets ends with PassBatch at 8,323 and FailBatch at 77 — 99.08% yield, a 0.92% fail rate, one log row, and then zeros everywhere. Run the arithmetic with the formula above:
- Parts inspected: 8,323 + 77 = 8,400 — matches the coil count, so no set went unjudged.
- Yield: 8,323 ÷ 8,400 = 0.9908 → 99.08%.
- Fail rate: 77 ÷ 8,400 = 0.00917 → 0.92%.
- Log row:
2026-03-14 06:42:11, 147, 8323, 77, 99.08. - After the edge: counters 0, BatchID 148, chart at 0 points.
Now the fault you are replacing: reset the built-in counters from the menu after three coils and the chart holds 3 × 8,400 = 25,200 points while the counters show at most 8,400 — a 16,800-point disagreement on one screen. Put the alarm on your own numbers too: with a 1.5% fail limit, the edge compares FailBatch ÷ PartsBatch = 0.92% against 1.5% and passes this coil. Percentages only repeat when the per-set judgment does — start from stable 2D vision inspection systems if the judgment itself still moves.
Which hardware should the counters and chart run on?
Run the script and the chart on the device that already owns the inspection: a vision controller for multi-camera lines, the smart camera itself for a single station. A controller also carries the disk for the batch log and the ports for the PLC handshake in one box.
A vision controller such as the MV-VC3301H-128G66 brings 5+ LAN ports and 4 built-in light channels, so the handshake, the log file and the lighting land on the same machine.
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- Light outputs
- 4 built-in channels
- Memory
- 8 GB
On a single measuring station, a smart camera runs the same six variables in its on-device script and streams only results; the MV-SC3050XC-16M-ATN-H pairs a 5 MP global shutter with an M12 mount for compact gauges. If a new coil means a new light recipe, switch it on the same edge: a light controller like the LS-CTL-0322 drives 4 channels with an 8 A total output.
- Interface
- Fast Ethernet
- Resolution
- 5 MP
- Output
- Constant voltage 24 V
- Channels
- 4 channels
Push the row upstream on the same edge. Write LastPass, LastFail and BatchID to the PLC, or expose them as OPC UA variables — the smart camera results over OPC UA mapping is the same job, and the log row stays the source of record.
How do you prove the reset worked before the next coil?
Run one full coil and check five things at the boundary: the log row exists, both batch counters read 0, BatchID advanced by 1, the chart restarted at 0 points, and the grand totals grew by the old batch numbers. The fast test takes two minutes: pause after two judged sets, force the coil-complete bit for one cycle, and expect a log row reading 2 passes and 0 fails, both counters at 0, and an empty chart. Then force one mid-batch restart and decide what it does — a fresh batch ID or a restore from the last log row. Either policy is fine; an undocumented one is not.
Hand it back to the operator only when this list passes:
- One pass count on screen, bound to
PassBatch— the engine readout is gone or relabeled. - Log row timestamped before the counters zeroed.
- Coil-complete edge debounced; two edges inside one second cannot create two batch IDs.
- Chart clear tied to
ResetChart, with the boolean clearing itself in the same UI pass. - Grand totals, yield and batch ID in every row, so a script reload costs one row, not the history.
When is the built-in menu reset still good enough?
Keep the built-in counters when one inspection run equals one batch, no chart is plotted, and a person is present at changeover — the menu command Inspection>>Reset Inspection Statistics then does the whole job. A single-shift line with no per-coil yield record and no traceability requirement loses nothing by it. The moment you log yield per coil, plot a trace, or answer an auditor with batch numbers, the six variables earn their keep. The same reset-on-event pattern applies to the line HMI as well, and batch reset script methods for HMI tags cover the scripting side there.
To size the controller, camera and lights for a new station, start at the configurator from the controller step:
The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.
If your coil signal is messier than one clean edge, or your engine's variable names differ from these, tell us on the contact page and we will map the sequence onto your line.
Questions
Should the counters reset on inspection start instead of coil complete?
Only when one inspection start always means one new coil. On lines where a coil runs across a shift change or a restart, start-of-run resetting cuts a batch in two and the per-coil yield stops meaning anything. Reset on the batch ID change: the coil-complete edge changes the ID and the counters follow it. For a mid-run restart, pick one policy — a new batch ID, or a restore from the last log row — and write the choice into the script comments.
How do you push the batch totals to the PLC or MES?
At the coil-complete edge, write LastPass, LastFail and BatchID to the outputs your controller already exposes, then pulse a data-valid bit for one scan so the PLC latches the row. When the plant collects quality data centrally, expose the same three values over OPC UA instead of wiring registers — the mapping is the same one-time job as any result variable, and the log row stays the source of record.
Can you keep a yearly total while the batch counters reset?
Yes. Keep PassTotal and FailTotal as grand counters the reset edge never touches: the edge adds the batch copies into them, then zeros only the batch copies. Grand totals still vanish on a script reload, so write them into every batch row; rebuilding the year is then a sum over the log file, not a reconstruction job.
Does resetting counters also clear the saved images and log rows?
No. Images, CSV rows and database entries are files the reset never touches; only the in-memory variables and the chart buffer go to zero. That is why the sequence logs before it zeroes — the batch record is already on disk when the screen returns to zero. Archive by BatchID so a coil's images and its counters line up months later.
What extra fields are worth logging beside pass and fail?
Log timestamp, BatchID, pass, fail and yield as the core row, then add the material or coil code and the light recipe number when a new coil can mean new stock. Those two let you compare yield across coils of the same material and catch lighting drift before it becomes rejects. Operator ID earns its column only where audits require attribution.


