system.perspective.sendMessage() function

Has anyone been able to use the system.perspective.sendMessage() function when it is triggered by a tag change event?


Without explicitly specifying a session id, what session would you expect it to get sent to in this case?

What are you trying to do?

I am trying to run script on a component by starting it via a message from a tag change event. Yes, I have passed the sessionID and set the scope to session. Even when I pass the sessionID I get an error stating that "No perspective session attached to this thread."

Hmm, yeah, not sure if that function works if there's no associated session. Tags are global resources, not part of a project, not associated with a session.

Change your mindset about these things.

You wrote some logic in a button or component or whatever. Now you want to call that same logic from somewhere else.

Don't think "okay, now I need to click that button somehow!".

Move that code to a function in a script library and just call that function from the tag change script.


Some further discussions that might help you:

See especially this alternate approach to such problems that better fits a highly multi-user multi-tasking platform like Ignition:

There shouldn't be any need to do that.

  • A view's component tag binding will refresh any time the tag changes.
  • That means you should only need to bind some property of the component to the tag.
  • You can then use a transform to do something quite unrelated to the tag value itself.

In the example below I monitor the memCounter tag and when it changes I update the time displayed in the label. The memTag's actual {value} isn't used!

I understand that tags are not specifically associated or part of a session. However, the misleading part of this is that the sendMessage() function accepts a session ID as an input. This to me would mean that it can send messages to one or all sessions. Apparently NOT the case, so this is a misleading parameter for sendMessage()

I did (with help) accomplish my goal by creating session variables that are linked to the actual tags. So when a tag value changes the session variable sees it and changes while initiating the sendMessage() function and running the script on the component.

No doubt I have much to learn in ignition however, sendMessage() apparently does not care nor work across sesssions even when you tell it which session to send the message to.

Did you include a pageId parameter when attempting to target a specific session?

Which sendMessage() are you talking about? system.util.sendMessage can be used in gateway scope and can target a specific session, but only delivers to session events. system.perspective.sendMessage() only works from within a Perspective event, but can target page and view scopes, too.

Can you show the script you were using to invoke sendMessage, and an example id and source of the ID you were using to target?

It should be a full UUID string, according to the code, so something like e9262efe-36fe-4228-b8ad-4c3f3023389b.

It was definately the system.perspective.sendMessage() script.
system.perspective.sendMessage(messageType, payload, [scope], [sessionId], [pageId])
According to the manual the scope is Gateway, Perspective Session thus my misunderstanding of its allowable use.

Yes, there are two session ID's as I understand, one for the designer and one for a web session. The UUID is (as I understand) for the designer, the other shorter one is for the actual web session. I actually passed both and neither worked.

I'm going to do some testing. My expectation is the same as yours; anywhere on the gateway you should be able to call system.perspective.sendMessage, you'll just have to explicitly pass whatever you're targeting.

Okay, so this does work the way we both thought, but with a caveat that I suspect is the source of your frustration.

So, what I think you did, because it's a logical thing to do, is that you configured a 'Session Message Handler' that you're trying to reach with system.perspective.sendMessage:

I'm guessing this is what you did, because it's what I did at first, before I remembered the distinction. These 'session message handlers' are actually those targeted by system.util.sendMessage.

The 'scope' argument of system.perspective.sendMessage corresponds to the listening scope of the component message handlers on any Perspective component:

The granularity of broadcasting/listening scopes is for extra utility, but unfortunately overloads the terminology here. system.util.sendMessage long predates Perspective, and has important Vision and EAM functionality, so it wasn't like we could remove or deprecate it, and it made the most sense to extend it for use with Perspective sessions once they were introduced. But then Perspective's own message handling concept happens to overlap, terminology wise, and there's not a ton we can do about it.

I can also confirm that, with the appropriate listening/targeting scopes set up, you can reach either message handler from an isolated gateway script, such as a tag event script:


1 Like

Perhaps it would be best to expand the "Description" box on the component message handlers to clarify that they only listen to messages from system.perspective.sendMessage(), and add a "Description" box to the session message handlers indicating that they only listen to system.util.sendMessage().

And add this information to the user manual.


Or perhaps annotate that system.util.sendMessage() must be used when the triggering event is on the gateway or outside of a session (i.e. tag update event etc.)

When the triggering event is in a session system.perspective.sendMessage() may/should be used.

The easy fix for me was to use the custom session properties which I had bound to the tags I was needing to trigger sendMessage() to trigger the script in the component. Seems very simple now.