I'm trying to use a Flex Repeater to iterate through a tag folder, look inside each tag folder, see if a particular tag is flagged on or off, and insert a template based on that status. My tag structure is set up as PLC Tags/Pumps/ and then inside Pumps is a UDT instance for each pump, called 1 through 6, and then another called Master. Inside the Pump UDT is a "Visibility" boolean element that reads a bit in the PLC. This bit designates if the pump is actually present or not.
I have a template view set up to read the same pump tag structure. Is there a way to iterate through, and for each tag folder where the visibility boolean is on, create a template instance that matches?
A flex repeater is only going to repeat a single view. You can create a vew for this purpose that includes an indirect tag binding for the boolean tag, and include an embedded view whose view path is conditional on that boolean property.
They are all the same view. What varies is how many there are, and currently the customer does this with a boolean in the PLC. Probably not ideal, but this is a retrofit and changing the PLC program is a last resort.
I was able to turn visibility on and off just by using separate embedded views on my dashboard page. I may end up just doing that. It's what their existing Panelview Plus app does now, and while I'd love to do this all "the right way," I'm afraid I might have to be picking my battles on this project due to time constraints. If only we were programming the PLC, too.
I would normally write a binding script on the instances param that scans the folder of pumps and for each pump with visibility enabled, I append another instance to a JSON array that becomes the return value that populates the instance parameter.
def transform(self, value, quality, timestamp):
totalPumpUdts = 10 #Total number of pumps to scan through
tagPaths = []
instances = []
#Make a list of tag paths to read the pump visibility from
for pump in range(totalPumpUdts):
tagPaths.append("[default]PLC Tags/Pumps/Pump " + str(pump+1) + "/Visibility")
tagResults = system.tag.readBlocking(tagPaths)
#Build instance array
for visiblePump in tagResults:
if visiblePump.value:
instances.append({
"instanceStyle": {
"classes": ""
},
"instancePosition": {},
"udtPath": "[default]PLC Tags/Pumps/Pump " + str(visiblePump+1),
})
return instances