Perspective Write Label Data to Memory Tag

What is the best method to write to a memory tag in Perspective using a Gateway Event on a Timer? I’m trying to write property values on a View to a Memory Tag every 30 seconds. I was able to get it working with a button click:

path0 = “[default]HXL_7205/JobDetails_7205/sfOrderNumber”
tagVal0 = self.getSibling(“lbl_7205_OrderNumber”).props.text
system.tag.writeAsync([path0],[tagVal0],runAction)

But now I’d like to do it at the Gateway level and without user interaction. I don’t know how to reference the View where the label is located. Any ideas?

You can’t. Imagine there could be 100s of clients open at once, which client would the gateway use? It’s impossible for the gateway to access anything from a client without the client initiating it.
Can you explain why you want to write the values of the fields on the screen to memory tags periodically? What is the end goal? Perhaps there’s a better way to do what you’re wanting

Sounds like you need a bi-directional binding.

I’m grabbing data from a vendor database via named query with parameters and then assigning it to a label with polling. So as the data changes I’d like to have a timer that runs on the gateway looks at that specific perspective view and label value and then writes the label value to a memory tag.

How would I setup bi directional tag?

That view exists in client scope, if it exists at all. Not readable from a gateway timer script. If this needs to be live all the time, you should be running the named query in the gateway timer script and writing to the memory tag there. Then the client view(s) that care can just display the memory tag.

2 Likes

Looks like I’m able to use a Transform on the label and add my script there to write the value to the memory tag.

What happens when the page isn’t being displayed in a client? Do you need the memory tags to be updated then?

You just need to bind the fields to your memory tags and check the “bi-directional” checkbox. This will then write the value changed on the bound property back to the bound tag

Technically yes…, the machine center will run as a kiosk so the view should always be running. However, there may be times when it is not. Is there a better way to write the tag data when the view isn’t open?

Yes, four comments up.

1 Like