Hello,
Version 8.1. The process unfortunately consists of many items and is difficult to post it in a logical way, however I found a solution.
1st step: The tag change script aggregates the min, max, avg and dev from each historian tag and places the results into a dataset. At the end of the script a memory integer tag is written to so that it’s value is incremented from 1 to 2.
endTime = system.tag.read('[default]Folder/EndedDateTime').value
startTime = system.tag.read('[default]Folder/StartedDateTime').value
dataSet = system.tag.queryTagCalculations(paths=[
'[default]Folder/ActualAbsoluteHeightReal',
'[default]Folder/ActualAbsoluteWidthReal',
#many more values here...
],
calculations=['Minimum','Maximum','SimpleAverage','StdDev'],startDate=startTime,endDate=endTime,ignoreBadQuality=1)
system.tag.write('[default]Folder/MinMaxAvgDev', dataSet)
system.tag.write('[default]Folder/IncrementTag', 2) #This will trigger the next step of the process, waiting for values to change by triggering delay before transaction group is completed
2nd step: Expression tags are used to extract the individual cell values from the dataset by copying the values to their values using an expression like this: {[.]MinMaxAvgDev}[0,3]
3rd step: Expression tags are used to calculate Cpk values from the above expression tags
//Cpk = min(USL - μ, μ - LSL) / (3σ)
//where USL and LSL are the upper and lower specification limits,
//μ is the process mean, and σ is the process standard deviation.
try(
if({[.]HeightDev}!=0, //avoid divide by 0 error
if(({[.]HeightUSL}-{[.]HeightAvg}) < ({[.]HeightAvg}-{[.]HeightLSL}),
(({[.]HeightUSL}-{[.]HeightAvg}) / (3*{[.]HeightDev})),
(({[.]HeightAvg}-{[.]HeightLSL}) / (3*{[.]HeightDev})))
,0)
,0)
4th step: A gateway timer script is set to 2,000ms fixed delay with shared threading since perfect timing is not necessary. the script looks like this:
HandShakeIncremented = system.tag.read('[default]Folder/IncrementTag').value
if HandShakeIncremented == 2:
system.tag.write('[default]Folder/IncrementTag', 3) #This will trigger the transaction group once the aggregation is completed
else:
pass
5th step: A transaction group is set to trigger when [default]Folder/IncrementTag = 3. The transaction group then stores all min, max, avg, dev and Cpk values to an SQL table
I then use the “Write handshake on sucess” on the transaction group to set [default]Folder/IncrementTag back to 1. I use the write handshake on failure to alert me and to have the system retry again.
Hopefully this makes sense and can help someone else. If anyone knows of an easier way to do this, I’d be glad to hear it.
Thanks