I need the “range” between 2 OPC tag values (value difference between Min and Max) in a Numerical Field or a LED for the shifts. Is there a least path of resistance or can someone help me over the hump? I can read the tags with system.tag.readBlocking(paths) in the script console from the example in the manual, but I am stuck on how to pass the values and get the “Range” from the outputs.
The code below works and I like the aggregationMode=“Range”. I don’t want to use the date time picker/input perspective component for the specific start and end times of a shift or system.date.xxx(). I would like to use my current shift tags from my Line Instances from UDT.
'[default]P3L3/L3accumB' is the opc tag with history enabled and recording.
......but I would like to use these tags as the start and end for time.
'[default]P3L3/Line7Summary/Shift9/ShiftStartString}' tag value = 2022-08-19 5:30
'[default]P3L3/Line7Summary/Shift9/ShiftEndString}' tag value = 2022-08-19 15:30
You will need to read the tags and parse them into Dates.
tagList = ['[default]P3L3/Line7Summary/Shift9/ShiftStartString}', '[default]P3L3/Line7Summary/Shift9/ShiftEndString}']
# Get the tag Values
stringValues = [tag.value for tag in system.tag.readBlocking(tagList)]
# parse to Date
startTime, endTime = [system.date.parse(value, 'yyyy-MM-dd HH:mm') for value in stringValues]
dataSet = system.tag.queryTagHistory(paths=['[default]P3L3/L3accumB'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')
valueOut = dataSet.getValueAt(0,1)
There are a few ways to do this, I will show them here in what is IMO best to worse case.
1.) Use a Tag Histroy Binding.
You will need to create two properties on either the view or the same component that is displaying the result. A property for each beginning and end of shift.
Then bind the properties as appropriate to each of the tags. Since your tags are Strings you will want to use an expression binding. (Best case would be to store the dates as actual dates, but I understand if there is some limitation keeping you from that.)
I am getting a null on a transform or in the script console.
tagList = ['[default]P3L3/Line7Summary/Shift7/ShiftStartString', '[default]P3L3/Line7Summary/Shift9/ShiftEndString']
# Get the tag Values
stringValues = [tag.value for tag in system.tag.readBlocking(tagList)]
# parse to Date
startTime, endTime = [system.date.parse(value, 'yyyy-MM-dd HH:mm') for value in stringValues]
dataSet = system.tag.queryTagHistory(paths=['[default]P3L3/L3accumB'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')
ValueOut = dataSet.getValueAt(0,1)
I have not got either suggestion to work yet, but when i figure out my problem, I will update this. I tried a few ways with the custom properties and could not get anything to work yet. TY for the guidance.