Main script location for multiple gateways

I have a frontend gateway housing a perspective project and a backend gateway housing the connection to a database and a connection to the plc. There will be another backend gateway housing connection to a database and a connection to another 5 plc’s.

The frontend accesses the backend tags through a remote tag provider.

I recently discovered that a tag event script can’t access the script on the frontend and I would have to export and import the same script to a project on the backend to allow both frontend and backend access to the same gateway script.

Going forward is there a better way to do this? If I wanted a global area so both or multiple gateways can access the same gateway scripts what would be the best way to go about this? Again I am using perspective and not vision.

Since scripts run IN the gateway where they are located, what about the current behavior is surprising?

Where necessary, use the scripting functions system.util.sendMessage() and system.util.sendRequest(), which permit targeting a message handler in a different gateway.

I have a few tag event scripts, where the tags reside on the backend, which try to access a script within the frontend and could not. It told me it could not find the gateway script from the frontend on the backend

Exactly. It isn’t there. Going outside one’s own processor requires network communication, not just a function call. sendMessage and sendRequest cause communication to happen.

I would choose one gateway as your EAM master and update your shared scripts there. Send the project with shared scripts you want access to on all gateways from your EAM master to the other gateways. If you don’t have enough use for EAM to justify the cost, you can still use it in demo mode to send the script project to the other two gateways by resetting trial time on all gateways involved first.

would this essentially be the same as exporting and importing the same script from one project to another and then setting up the gateway script property to access that “default” project within each gateway?

So if I were to do something like that which one would get the send message and which one would get the send request?

Can you explain high level the steps?

I have a tag event script on a backend tag. Based on valuechanged I want to access a script within the frontend gateway scripts.

On the front-end gateway, add a gateway message handler to the project containing the frontend script you are trying to call. That script would unpack the function arguments from the message payload dictionary, call the function, and if appropriate, return the result.

On the back-end gateway, in the valueChange event, pack up the function arguments into a dictionary, then call system.util.sendMessage() with that payload, identifying the project, message handler, and the target gateway. If you need a return value, use sendRequest instead, and you probably should delegate to an asynchronous thread (you can bog down tag processing if replies takes too long).

4 Likes

I’d suggest also creating a wrapper function to wrap the system.util.send* calls so you’re not having to pass in the project name, gateway name, etc. in multiple places and are just passing in the payload (and maybe the function to call as well, see Calling function on another gateway? - #3 by nminchin)

1 Like

Yes, same result but an easier way to maintain things. Whether this or using sendMessage/Request makes more sense depends on where what you need to do makes the most sense to do. If the gateway where the tag event happened has everything it needs (except this script) to do what's needed, I'd lean towards giving it a copy of the script (via sharing script project with EAM) rather than sending the message to the other gateway to execute the script. On the other hand, if you need things done on the other gateway, sendMessage/Request is the way to go.

1 Like