Few months ago JordanCClark advised gateway tag change script for a counter:
‘’'if not initialChange:
# Get current and previous values
currentValue = event.getCurrentValue().getValue()
previousValue = event.getPreviousValue().getValue()
if currentValue == 0 and previousValue != 0: # Create logger logger = system.util.getLogger('batchCountResetMonitor') # Get the parent path basePath = str(event.getTagPath().getParentPath()) # Create list of tags tagPaths = [basePath + '/Previous Batch Count', basePath + '/BatchResetBit'] # Create list of values values = [previousValue, 1] # Write values to tags system.tag.writeBlocking(tagPaths,values) # Send information to logger info = 'Batch Count Reset. Value of ' + str(previousValue) + ' written to ' tagPaths logger.info(info)'''
which works fine, if the machine is stopped, the counter has been reset, and then the machine restarted.
In some cases however, when there is no product change, only lots change, the counter might be reset when the machine is still running. On the snip below it is shown that in this particular case the output is not calculated properly and the previous lot production is lost:
Since the transaction group execution rate is 1 minute, the counter “zero” value is not captured. What can be the approach/solution in this case? Gateway Timer Script?