Open popup with script

Hi guys, the code is wrong ?

#sobretensão barramento
tagValue2 = system.tag.read('[default]Geradores_Sinal/TensaoBarramento').value
if tagValue2 > 15050:
    system.tag.write('[default]AcionaSobretTensaoBarramento', 1)
    system.tag.write('[default]AcionaSobretTensaoBarramento', 0)
system.perspective.openPopup(12344,'SobreTensaoEntrada')

i wanna open a popup when the value of electrical tension is bigger then 15050.
when i put this code system.perspective.openPopup(12344,'SobreTensaoEntrada') inside an event click on button, works perfectly. but i don wanna this. he needs open automatically

i want this, but without the button
thank you

Well then, what trigger do you want ?

Does this popup need to appear no matter what page the user is viewing or only a certain page?

Right, I missed that part.

Add a custom property to your view, bind it to the tag, then add a change script on that property with the script to open your popup.

2 Likes

Mildly related, how would you handle if the value kept oscillating above and below the setpoint, and you wanted prevent the popup from re-opening itself if it was already present?

1 Like

Tip: system.tag.read and system.tag.write are depreciated. You should be using the following functions:

system.tag.readAsync
system.tag.readBlocking
system.tag.writeAsync
system.tag.writeBlocking

See system.tag - Ignition User Manual 8.1 - Ignition Documentation to understand the differences.

First thing that comes to my mind would be to instead of monitoring the tag value, monitor an alarm with an Active Delay.
image

i'll try. but i'm a junior programmer

this option do not exist. the value will oscilete one single time. because he's a status of a digital output from my plc

Then I recommend that you talk to a senior programmer and talk to your users to see how they expect the system to operate.

Make your user interface work in a way the users are familiar with from Windows / Linux / Mac OS, etc. Don't do strange things.

this is for my TCC high school.

You should know that if you add a custom property to that view, the binding and therefore the script will only execute when that particular view is open. If you want it to happen regardless of the screen the user has opened, consider adding a Session custom property


See how these two last lines have different indentations? This means that your script will always fire even if tagValue2 isn't bigger than 15050

If you want to make things more elaborate for your final paper, think about what should happen if the user just closes the popup. The value will remain above 15050 and there won't be any popups to alert the user of that condition.

You can make this all much easier and have no popup.

Create a view for a footer which can display error messages.

  • Create a couple of session variables on the main Perspective properties and use these to control the footer view.
  • Bind the controls on the footer view to the session variables.
  • In the Page Configuration add in the footer view.

Now you have a layout that's easy to understand and easy to code. The messages will be visible on every page of your project. No popups!

`

2 Likes