Gateway MessageHandler

Hello,

I am currently assigned to a project that is supposed to auto refresh some tables, write to tags on refresh and essentially automate our run schedule into the PLC.

I currently am thinking I will have a scheduled gateway event run every 15 minutes. This event will send a message handler, then on each page with the tables I have a checkbox that is listening for that message handler. When it hears it, self.props.selected will become True, and if True it will run my queries to refresh some tables inside of the project and when the table is refreshed, it will have to write the tables values into some tags. I haven't figured out just how to write to tags with table values just yet.

I am struggling with getting the message handler to function properly. I have tried system.perspective.sendMessage() and system.util.sendMessage(); however, I'm not sure if I'm using it improperly or it just cannot be done.

If anyone has any knowledge on this or a better way of accomplishing this task, it'd be much appreciated. I've never used the gateway schedule or a message handler from the gateway level.

Code for my scheduled script:

project = 'R3'
messageHandler = 'Refresh'
system.util.sendMessage(project, messageHandler)

Code for gateway message (if even necessary):

system.perspective.sendMessage("Refresh")

Code for the checkbox script on the page with table:

self.props.selected = True

Code for checkbox self.props.selected change script:

if self.props.selected == True:
	returnedData = system.db.runNamedQuery("L2 Schedule")
	self.getSibling("Table").props.data = returnedData

Automating in gateway events is a very good idea, as critical operations can be made to run reliably, in one spot, regardless what is happening with client connections. However, including client UIs in the control loop is a very bad idea.

Instead, make the event script self-contained, working directly with the tags that control the process, tags and/or database entries that your UI sets to provide guidance, and tags that your script updates to provide UI feedback. The latter would often be dataset tags or document tags to deliver chunks of fresh data conveniently.

With this arrangement, you need few, if any, message handlers. Your UI would include tag bindings to display the process and feedback tags, and entry fields and/or command scripts that would update the guidance tags and database entries. Treat the gateway event as if it were an extra task running alongside your PLC's realtime tasks. Run it fast enough so that guidance is acted upon with reasonably low latency.

If you still think you need to send messages from gateway scope into your perspective sessions, see this topic for the nuances:

1 Like

I thought to myself "Why not just use a minute tag, then say 'if minute == 0, or 15, or 30, or 45, set checkbox to True?" but even that isn't working for some reason. I am going to try the session event out, thank you for the link.

This is a terrible design. Don't do it. Just write to those tags from the gateway event, using the data the gateway event has queried, and that the gateway event will write into a dataset memory tag. The UI table would just bind to the dataset tag. No messages needed. No writes from the UI back to PLC control tags in this loop.

This works great. I am running the query, inserting it into a dataset tag and have the tables linked to that dataset tag. I have a schedule hitting at the hour, 15, 30 and 45. Now I just need to figure out how to loop through the dataset and insert the values into separate tags for each individual value. Thank you for this!