Turn on a plc tag based on visibility of a component and the open/close state of a window

Does this have to be two separate windows? Can this be done in one window with separate containers for your top and bottom ‘views’, for lack of a better word? It seems like a lot of work to what is essentially toggling visibilities.

1 Like

I am trying to trigger this in property event change:

if event.propertyName == 'visible' and 'Top' in system.gui.getOpenedWindowNames():
    systme.tag.writeBlocking('[default]LED',event.newValue)

I also tried to trigger it from the client events, but it did not work.

The other thing I did was to:

  1. when the label is visible, I wrote value “1” to a boolean memory tag.
  2. Then I used that as a trigger tag for my client events and
  3. I wrote this script:
if system.nav.getCurrentWindow()== "Top":
	if newValue.getValue():
		print("hi")

but it did not work.

I tried to use system tags instead of “getCurrentWindow”, “[system]Client/User/CurrentWindow” but that one did not work either

Unfortunately this has to be two window name, there is device that needs to installed and that device has a top and bottom view, every time the operator has to switch the screen to be able to see the proper hardware for the top view or the bottom view. The operator toggle the screens with an Optical touch button. and when they are in certain screen let’s say “bottom”, specific LED needs to be turned off, and once they toggle back to “Top” that led needs to be On. I was thinking instead of the script above it is beeter to have everything here but I could not make it working.

I wrote this script for toggling the screen based on OPT touch button only, it is working, but the odd thing is about the first sentence which seems to be not correct.

if system.nav.getCurrentWindow()== "Top":
	system.nav.swapTo('Bottom')
else:
	system.nav.swapTo('Top')

you posted this code before in a different question, wasnt this solved over there?

Yes, it is solved. So it is working perfectly fine, so the tag that is triggering this script in the client tag (OPTtouch) is able to toggle the screen. However, when I write a print statement the first sentence seems to not working, that is why I wanted to use “[system]Client/User/CurrentWindow” instead.

if system.nav.getCurrentWindow()== “Top”:
system.nav.swapTo(‘Bottom’)
else:
system.nav.swapTo(‘Top’)

will probably not work in the designer but should work in clients

So even if we have print statement after that we should be able to see the name of the screen in console, right?

if i print this out while in the desinger i get ‘none’


if i do it while running the app with diagnostics i do get the name
image

1 Like

I see. That is why then I saw None in the console! Thank you!!!

1 Like

I used the same code you wrote here, but I still do see
Click
None

on both! Not sure what I am doing wrong

The designer does not have a “Current Window”. It doesn’t have docks, either. You can open them, but they don’t behave as docks. Some things can only be tested in a real Vision client. Preview mode in the designer isn’t sufficient. That’s all.

1 Like

Thank you very much, Phill. Appreciate the information. I guess the problem is with my windows then.
I checked the setting for both of them and they were:
image
They are both main windows and not pop up or anything else. Is there any other place that I need to check for their configuration?

Also, I checked project properties and this is what I saw:

Also, intrestingly, when I add the “[system]Client/User/CurrentWindow” to a text box, I can read the current window name when I launch the project. But somehow I get value None when I use system.nav.getCurrentWindow(). So not sure which one is correct

It seems to me from what I have read here that you are successfully turning the LED ON, and that your problem is that the LED is not turning OFF.

Your code below will turn the LED ON if propertyName is 'visible' and 'Top', but will do nothing (ie the LED will remain ON) if those conditions are not met.
You need to detect the condition where you want the LED to be OFF, and do the tag write to OFF in that condition.

1 Like

I fixed this and will post the solution soon.

So here is what I did to fix this:

Instead of checking for visibility and the screen at the same time.
I created a query tag that corresponds to the visibility of the label. Also, I captured the value of my optical touch button ( 0 and 1), based on that value I could recognize what screen I am in right now.

I used OPT button value along with the query tag value and I wrote an expression in an expression tag to capture both conditions. In the value change of my expression tag, I wrote a script to make the current value of the expression tag equal to the value of the plc tag.

1 Like