I just finished implementing and testing controlled, organized, supported global storage in Ignition.
It is called “gstore”, short for Global Storage. It provides a simple way to have and use global state in Ignition.
Global project state is stored in a global dictionary at pa.gstore. pa.gstore is global to each project. It can be used in Gateway scripts or client/designer scripts.
Here’s the code to use in your circumstance:
Put this code in a Gateway Startup Script:[code]def read_udp():
UDP_IP = “192.168.1.250”
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
pa.gstore[“sock”] = sock
data, addr = sock.recvfrom(1024)
print “Received %s from %s” % (binascii.hexlify(data), addr)
The only difference to your code is adding the socket to gstore.
Then add the following code to the Gateway Shutdown Script:
pa.gstore["sock"].close()gstore has more functionality than this but I haven’t updated the documentation yet, but I will soon. If you want to use this and need any help let me know.
gstore is the newest capability in the PA Power Scripting Module.
Edit: getting rid of GStore: nickmudge.info/post/getting-rid-of-gstore
Use Python module level variables instead: nickmudge.info/post/python-modul … lient-tags