How do I update a variable found in another container

I’m relatively new to FactoryPMI. One of the problems I’m encountering, is determining the various objects/properties etc. found within a project.

What I’m trying to accomplish: I have an object in a window that supports control operations. When the user mouse clicks on this object, a popup window appears with a Open and Close buttons. I would like the code attached to the button mouse click event to update a dynamic variable found in the first/calling window. I’ve successfully passed parameters to the popup window, now I’m trying to update the variable and I’m not sure how to reference this object. This code is used for a demo system so I want to fake the correct operation normally found in the field.
Can someone provide a code example?

You’d be better off reading the actual state in the first window and setting the actual value via the DB/PLC in the second. This is much more meaningful than setting the first window variable from the popup window. Obviously if it goes all the way through the PLC it could represent the true state. If it goes through the database then at least all your concurrent clients would be on the same page.

I’m going to use user selectable valves for this example. Parameter passing wouldn’t be necessary with only one valve.

  1. Create a selectedValve dynamic property in the main window, allowing the user to choose a valve. You have many ways of doing this.

  2. The dynamic variable, valveState, in the main window represents the actual state of the selected valve. This should be periodically polling (bound to) the SQL database.

  3. Clicking on your object should open the popup window, passing selectedValve to tell the window which valve to open/close.

  4. Have the open and close buttons in the popup window write to the SQL database for selectedValve. It’s better practice to write to a “request to open” bit and read from an “open status” bit rather than using a single “open”. You can read from and write to the same bit for a demo system or if your valve doesn’t distinguish between the states.

Do you still need a code example? I think you know how to do all the steps.

note - if you’re still interested in changing a dynamic variable in another window there are a couple of options. The hard way (shown below) uses Jython to “drill down” the object model to set the variable. The “easy way” is to do it exactly like you did with the popup window. Use fpmi.gui.openWindow() and pass valveState, which should be on the Root Container. openWindow sets focus if the window is already open. If your variable isn’t on the Root Container you can bind it to a dynamic variable that is. If valveState is set to update the SQL database on a change the value will get written back to the DB/PLC. You would probably then want to close the popup window with the next line of Jython code.

“hard way” example without error handling

window = fpmi.gui.getWindow('main') rc=window.getRootContainer() rc.valveState=1

SQLTags will allow you to use global dynamic variables. In this case I would still set it up as described above.