Below is a dev script running on a Control Logix, still fairly new to Ignition was needing feedback from experienced folks. Would like to create a gateway timer script to read/write to OPC tag to coms drop locally and raise server alarm.
type or paste code h# OPC Server and Tag Paths
opcServer = "Ignition OPC-UA Server"
itemPath = "ns=1;s=[AFSPL1RtRepair]OPC.Ping"
tag_path = "[Default]OPC/Assembly/L1/RTRPR/Ping"
isAlarmLogged = system.tag.readBlocking(['[Default]OPC/Assembly/L1/RTRPR/isAlarmLogged'])[0].value
isErrorLogged = system.tag.readBlocking(['[Default]OPC/Assembly/L1/RTRPR/isErrorLogged'])[0].value
system.tag.writeBlocking(['[Default]OPC/Assembly/L1/RTRPR/isErrorLogged'], [False])
try:
# Read the tag value and quality
value = system.tag.readBlocking([tag_path])[0]
tagValue = value.value
tagQuality = value.quality
# Check if the tag quality is good
if tagQuality.isGood():
if tagValue == True:
writeOperationStatus = system.opc.writeValue(opcServer, itemPath, 0)
if writeOperationStatus.isGood():
pass # Successful OPC Write 0
else:
writeOperationStatus = system.opc.writeValue(opcServer, itemPath, 1)
if writeOperationStatus.isGood():
pass # Successful OPC Write 1
# Reset active flags to False after a successful tag read/write operation
if isAlarmLogged:
system.tag.writeBlocking(['[Default]OPC/Assembly/L1/RTRPR/isAlarmLogged'], [False])
else:
# If "QUALITY IS BAD"
if isAlarmLogged == False:
system.util.getLogger("L1RtRepair_PingQuality").error("BadQuality=[Default]OPC/Assembly/L1/RTRPR/Ping.Quality")
system.tag.writeBlocking(['[Default]OPC/Assembly/L1/RTRPR/isAlarmLogged'], [True])
except Exception as e:
# Log exception definiton defined by Igniton
if not isErrorLogged:
system.util.getLogger("L1RtRepair_Exception").error("Alarm: %s" % e)
system.tag.writeBlocking(['[Default]OPC/Assembly/L1/RTRPR/isErrorLogged'], [True])
ere