Loop Mode Script Issue

We are trying to configure a label to output the current in-mode of a loop as feedback back to the user which exists in a UDT popup. The label contains a script that is supposed to look at three tag paths and determine what to show the user based on these paths, but it lacks the ability to update in real-time. Currently the method is only called in the startup event of the label. Ideally it should be set to update within a specified interval to give better/more up-to-date feedback. We have considered putting the custom method in the gateway, but this would complicate the transfer of data between the gateway and the label. What is the most effective way to go about getting the label to correctly display the in-mode of the loop in real-time?

Script:

def method_loop_mode(self, text):
autoBit = self.view.params.Loop_auto_mode.value
cascadeBit = self.view.params.Loop_cascade_mode.value
manualBit = self.view.params.Loop_manual_switch.value
output = " "

if manualBit == 1:
output = "Manual"
elif autoBit == 1:
output = "Auto"
elif cascadeBit == 1:
output = "Cascade"
else:
output = "Manual"

self.props.text = output
#print output

One possible solution we have investigated using is the perspective refresh function or alternatively a timer script which may allow for the periodic updates to the label. These may be work but we’d like to avoid potential additional overhead that this may introduce after the pop-up has been closed.

Any help is greatly appreciated!

Edit: The case statement worked but we did have to add additional cases for other possible combinations.

The most common cause of this phenomenon with popups is passing a UDT value to the popup instead of a string tagpath parameter. The popup needs its own indirect tag bindings to the tags of interest (typically in custom props) in order to have live data.

(While IU teaches it, using UDT properties in your UIs is a terrible practice.)

6 Likes

Also don't use a script. Use an expression binding.

case(
    binEnc(self.custom.manual, self.custom.auto, self.custom.cascade),
    1, "Manual",
    2, "Auto",
    4, "Cascade",
    "Manual"
)
6 Likes

We had already configured this to use tag path parameters which allowed the case expression to work properly. It’s a good reminder of best practice for UDTs.

Consider using binEnum() instead of binEnc() for your use-case. Can handle multiple true bits the way your script transform did.

1 Like