Created
November 3, 2022 19:56
-
-
Save HelloMorrisMoss/be989b3c0d283eb345b4fb8b7566caae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""An example Ignition SCADA Gateway tag change event script that sends a simple JSON message to a flask | |
server when the production line starts and stops. The server runs alongside a tkinter window that | |
will shrink to a small semi-transparent button when the line starts running. The computer this runs | |
on was there for a reason, so obscuring the existing software was not an option. If there is an | |
unsaved defect record active in the window, it will pop back up when they stop so that they can update | |
it when finished. | |
When this was set up we hadn't gotten the WebDev module yet, so when the operator creates a new defect | |
record, by pushing the button, the available tag data is read directly from the Postgres/Timescale | |
database with the tag history using the psycopg2 library. | |
This is quite quick. The line start has a ~5 second delay while a line-starting signal goes off. So, the | |
fraction of a second delay is nothing. | |
Ignition SCADA version == 8.1.17 | |
""" | |
if not initialChange: | |
src_path = event.getTagPath().toString() # tag path that triggered this event | |
lam_num = Shared.L.get_num_from_path(src_path) # get the production line number from the path | |
# ip address for the industrial PC with the flask server depends on the line number | |
flask_server_url = {1: '10.155.0.102', 2: '10.155.0.201'}[lam_num] # static IP addresses! | |
defects_url = 'http://{}:5000/popup'.format(flask_server_url) # the address for for the flask endpoint | |
hc = system.net.httpClient() # this class can be used for POST and GET requests | |
# if the lam has started running, hide the popup | |
if newValue.getValue(): # boolean tags, so if the line is running, this is True | |
param_dict = {"action": "shrink"} | |
else: | |
param_dict = {"action": "show"} | |
result = hc.post(defects_url, params=param_dict).json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment