OPC tag value change upon opening a perspective session

Hello…

In a project I inherited, we have this partcount INT tag configured with a COUNT query binding (SQL) populating the tag. I monitor that tag in the PLC to do other stuff.

Whenever the perspective session is opened, the tag briefly (half a sec) goes to zero and returns to it’s actual value. Tag group config looks like below:

Please throw some light on what might be going on. Thanks!

Inspect the session event scripts. There may be something in the session startup event that is writing to your tag.

2 Likes

Also look for bidirectional bindings in the UI to that tag. They are known to sometimes misbehave on startup. /:

2 Likes

So this is how the value is being written to the tag. The last line writes the value from a query binding to the tag. It’s run in a ValueChanged script

<>

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
        if self.props.value == 0:
            self.getSibling("Header").props.style.backgroundColor = "#FFFFFF"
            self.getSibling("Header").props.text = ""
        else:
            if self.props.value >= 512:
                self.getSibling("Header").props.style.backgroundColor = "#0FD72F"
                system.tag.writeBlocking("[HighVol_Upper]Pallet_Complete/Sta55_PalletComplete", [1])
                self.getSibling("Header").props.text = "Pallet Complete - Remove Pallet"
                system.perspective.openPopup("Sta55_RemovePallet",'Sta 55 User/Sta 55 Remove Pallet')
        system.tag.writeBlocking("[HighVol_Upper]Stations/Sta55/Sta55_PartCount", [currentValue])

Is this change script on a numeric entry field? If it is, you might want to ignore all value changes except those originating from Browser, that should make sure it only fires when a user enters something.

For maintenance sake I would suggest the following improvements:

Make style classes for the different states of the header, and use a map transform to set the style class of the header based on the value of the property with this change script. Or just put an expression binding on the styles.backgroundColor property of the header, if you feel lazy.

The value driving this property change(or at least its source) should be in the view custom properties.

The header text should just be an expression binding.

Change the

else:
    if self.props.value >= 512:

in the script to be

elif self.props.value >= 512:
1 Like

@ryan.white Correct. This is from a query binding populating a numeric entry field

Are you expecting it to only write/update tag values if the user has entered something? Or do you also want it to write/update if the value from the query changes?

Right now it updates only if the query result changes. That part is fine.

My only concern is the PartCount tag going to zero and reverting back to it’s actual value when a session is opened for that project

This is not the place for this script then. This script will fire on every open perspective session running this project whenever the query result changes.

This is likely from the value changing from its uninitialized or default value to the value returned by the query, which will trigger the change script.

You may need to change your script to ignore the initial transition from default to actual.

Why do you think it runs everytime a session opens?

Properties with bindings will either load with an uninitilized or default value on session startup and await their binding to return an actual value, and switch to that value once received. That transition will trigger a value changed script.

2 Likes