I design an HMI on ignition vision. When I'm on a specific window, I need to wait that a modbus register changes from 0 to 1 to change to another window. To do this, I created a client tag change script on the modbus register. But I need to know if I'm in the specific waiting window to swap to the desired window (ex : don't swap to that window if the current window is the home page). So, on the event, I check the current opened window with "system.nav.getCurrentWindow()", but the function don't always return the window that is showing in the HMI. If there is other windows that are still opened in background, the function sometimes return one of those windows.
What is happening?
How can I get the "Currently showing window" in the client tag change scripts?
There is the complete script:
print event.tagPath
print initialChange
print newValue.value
current_window = system.nav.getCurrentWindow()
print "this is the current window : "
print current_window
if current_window == "main_windows/rfid_successs" and newValue.value == 1:
system.nav.closeWindow(current_window)
system.nav.openWindow("main_windows/charging_2")
system.tag.writeBlocking("[Sample_Tags]_Intesis OCPP 1_6 Modbus Gateway_/UnitId 0/trans_id0-trans_id0/trans_id0", 321)
system.tag.writeBlocking("[Sample_Tags]_Intesis OCPP 1_6 Modbus Gateway_/UnitId 0/start_proces0-start_proces0/start_proces0", 1)
Tag Change Scripts are in a different scope than the GUI. Thanks for setting me straight @pturmel
You should create a custom property on the root container and bind it to the tag that represents the modbus register you want to wait for the change on. Then in the property change script of the root container you can filter for the custom property and when it changes to 1 execute any script that you want.
Also, notice that I have changed the order of the code so that you write to the tags prior to navigating away from the window. This guarantees that the tag write occurs before the window closes since writeBlocking() blocks the thread until it returns. If you don't want to wait to navigate, then consider using writeAsync() instead.
Since you are closing the current window and opening another, you can just use system.nav.swapTo(), the function closes the current window and opens the window at the provided path.
Emile specifically called out Client Tag Change Scripts, which are very much in client scope in Vision. But "current window" is only for main windows, and if there are more than one of those, the result is unreliable. Popups are not main windows.