Reporting flow totals, issue with PLC data rollover

I ran into an issue with a customers flow total report. My issue is that the variable used in the PLC is only a 16 bit unsigned integer so the value rolls over every 2-3 days. The report was setup to use Aggregation mode Range with an interval of 24 hours. Report runs at the beginning of a new month and reports on the flow total for each day of the month so 12am - 12am.

The Range Aggregation mode is not accounting for rollover, it just reports on the absolute difference between the values recorded at each 24hr increment at 12am.

I tried other aggregation modes but nothing is working the way I needed it to.

Ignition is version 8.0.12

Maybe this will be helpful,

1 Like

My approach was something like this:

  • Create a new memory tag allTimeBatchSum.
  • On your OPC cycle count tag add a script on the Value Changed event.
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	"""
	Watch for the machine's counter being rolling over and, when it does, 
	add the rollover value to the All-Time cumulative counters.
	2023-06-03 @Transistor	
	"""
	currentCycles 	= currentValue.value			# From PLC's resetting cycle counter
	prevCycles 		= previousValue.value			# This memory tag.

	if currentCycles < prevCycles:			# Batch counter has been reset.
		rollover = 65535                    # or whatever
		paths = ["[.]allTimeBatchSum"]
		values = system.tag.readBlocking(paths)
		system.tag.writeBlocking(paths, [values[0].value + rollover]
  • Now create an expression tag totalMachineCycles to sum the allTimeBatchSum with the current count. e.g.,
    {[.]allTimeBatchSum} + {[.]MachineCountCycles}
  • Log this tag in your historian or whatever and you can now get the difference between any two timestamps very easily.

Note: I've adapted this script from my application and haven't tested it but it should give you a good idea how to go about it.

What happens if you download a program with "stale" data? This is rheorical. :slight_smile:

Don't!

On a practical note, you could get the last count from Ignition and load it back in automatically or manually. I've never done it.

A lot easier to reset on first scan and let Ignition handle the rest. Just my two pennies.

OK, but you'd have to modify my script not to add in 65535 but get the last count value from somewhere.

I'm not using your script :slight_smile:

2 Likes