No !
You don’t pass the function, the script in the message handler already knows what to do. The payload is only data you need to PASS to system.tag.configure()
or to compute its parameters.
Let’s do a concrete example.
Say you want to create a memory tag named foo
, with value bar
on gateway GWA
, which has a project A
, when a button in the project B
that is on gateway GWB
is clicked.
In project A
, you make a message
script in the gateway event scripts, and you call it addTag
:
tag = payload.tag
path = payload.path
system.tag.configure(path, tag, 'o')
This is in charge of configuring a tag at path path
.
Now, on the onActionPerformed
event of your button, you add this:
path = "[]baz"
tag = {
'name': "foo",
'valueSource': "memory",
'dataType': "String",
'value': "bar",
'tagType': "AtomicTag"
}
payload = {
path: path,
tag: tag
}
system.util.sendMessage('A', 'addTag', payload=payload, remoteServers=['GWA'])
This sends ONLY sends a message that needs to be intercepted by an handler called addTag
, in project A
, that lives in gateway GWA
, with some data that’s conventionally called payload
.
When the message is sent, the handler in project A
receives it, and does whatever it was configured to do. Here, it will use the data in payload to create a tag.
Project B
has no notion of writing tags or calling function, all it does is toss a bottle in the ocean, with a label on it that says this is for A !
and a piece of paper inside where the payload is written.
When A
find the bottle, it opens it, reads the paper inside and does its thing. Turns out, its thing is writing tags based on papers it finds in bottles.
Now, there are ways of doing it differently. You could actually send a function name as payload, to give more specific instructions. But this gets more complicated, and you don’t need it in your case.
edit:
Adapt the above example to match your case, for example if all the tags you need to write are memory tags of type String at the same location, you could just pass the name and the value of the tag and let the handler construct the tag:
on B
:
payload = {
name: "foo"
value: "bar"
}
system.util.sendMessage('A', 'addTag', payload=payload, remoteServers=['GWA'])
and on A
:
tag = {
'name': payload.name,
'valueSource': "memory",
'dataType': "String",
'deadbandMode': "Off",
'value': name.value,
'tagType': "AtomicTag"
}
system.tag.configure("[]thisIsThePath", tag, 'o')