def CreateTags(country, state, depotid, pmid, ewontype):
#Tag paths for the tag creation
ftpPath = "[default]FTP/"+str(country)+"/"+str(state)+"/"+str(depotid)+"/PM " + str(pmid)
mqttPath = "[MQTT Engine]"+str(country)+"/"+str(state)+"/"+str(depotid)+"/PM " + str(pmid)
#Tag paths for the Auto Start and Wash Start tags - For the script Counters
autoTagPath = "[default]Counts/PM " + str(pmid) + "/AutoCount"
washTagPath = "[default]Counts/PM " + str(pmid) + "/WashCount"
autoTagPathW = "[default]Counts/PM " + str(pmid)
washTagPathW = autoTagPathW
if ewontype == 0:
baseTagPath = ftpPath
else:
baseTagPath = mqttPath
#######################################################################################################################################################
#Auto Count Script
AutoScript = '''tagPathRead = ''' +"'"+ autoTagPath +"'"+'''
tagPathWrite = ''' +"'"+ autoTagPathW +"'"+ '''
count = system.tag.read(tagPathRead).value
tagExist = system.tag.exists(tagPathRead)
if tagExist == False:
auto = 0
else:
if currentValue.value == 1:
auto = count + 1
else:
auto = count
# Configure the tags. Manually doing this for the example, but a for-loop could simplify the process.
tagAuto = {
'name': 'AutoCount',
'valueSource': 'memory',
'value' : auto,
'tagType' : 'AtomicTag',
'dataType' : 'Int8'
}
# Add the tags a list
tagList = [tagAuto]
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
# Edit the tags.
system.tag.configure(tagPathWrite, tagList, collisionPolicy)'''
#Create the tag ready for operation
tagAuto = {
'name': 'AutoCount',
'valueSource': 'memory',
'value' : 0,
'tagType' : 'AtomicTag',
'dataType' : 'Int8'
}
# Add the tags a list
tagList = [tagAuto]
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
# Edit the tags.
system.tag.configure(autoTagPathW, tagList, collisionPolicy)
#######################################################################################################################################################
#Wash Count Script
WashScript = '''tagPathRead = ''' +"'"+ washTagPath +"'"+'''
tagPathWrite = ''' +"'"+ washTagPathW +"'"+ '''
count = system.tag.read(tagPathRead).value
tagExist = system.tag.exists(tagPathRead)
if tagExist == False:
auto = 0
else:
if currentValue.value == 1:
auto = count + 1
else:
auto = count
# Configure the tags. Manually doing this for the example, but a for-loop could simplify the process.
tagWash = {
'name': 'WashCount',
'valueSource': 'memory',
'value' : auto,
'tagType' : 'AtomicTag',
'dataType' : 'Int8'
}
# Add the tags a list
tagList = [tagWash]
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
# Edit the tags.
system.tag.configure(tagPathWrite, tagList, collisionPolicy)'''
#Create the tag ready for operation
tagWash = {
'name': 'WashCount',
'valueSource': 'memory',
'value' : 0,
'tagType' : 'AtomicTag',
'dataType' : 'Int8'
}
# Add the tags a list
tagList = [tagWash]
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
# Edit the tags.
system.tag.configure(washTagPathW, tagList, collisionPolicy)
#######################################################################################################################################################
tagNames = [ "AI 0 Fault",
"AI 1 Fault",
"Goliath Comms Fault",
"Goliath Drive Fault",
"Goliath Lifter Hyd OL",
"Goliath Pump OL",
"Goliath Pump Overheat",
"Goliath Sheer Pin Jam",
"Grinder Drive Fault",
"Lid Has Not Closed",
"Lid Open Fault",
"Overfill Alarm",
"Pulpmaster Sheer Pin Jam",
"Pump Outfeed Blocked",
"Pump Overload",
"Safety Relay Fault",
"Tank Full",
"Tank is Full",
"Tank Three Qrt",
"Water Pressure Low",
"Tank 5 percent",
"Tank Percentage",
"HMI Reset",
"Screw Speed",
"Grinder Run Time"]
tagList = []
for tagName in tagNames:
tag = { "name":tagName,"valueSource": "memory", "value" : 0}
tagList.append(tag)
# Set the collision policy. If editing existing tags, then we'll use "o" to overwrite
collisionPolicy = "o"
# Edit the tags.
system.tag.configure(baseTagPath, tagList, collisionPolicy)
#Create the tag for Auto Start which has the script for the Auto Counter
tagList2 = []
tag2 = { "name":"Auto Start","valueSource": "memory", "value" : 0, "eventScripts":{"eventid":"valueChanged", "script":AutoScript}}
tagList2.append(tag2)
# Edit the tags.
system.tag.configure(baseTagPath, tagList2, collisionPolicy)
#Create the tag for Wash Start which has the script for the Wash Counter
tagList3 = []
tag3 = { "name":"Wash Start","valueSource": "memory", "value" : 0, "eventScripts":{"eventid":"valueChanged", "script":WashScript}}
tagList3.append(tag3)
# Edit the tags.
system.tag.configure(baseTagPath, tagList3, collisionPolicy)
for tagName in tagNames:
if tagName == tagNames[16]:
system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})
elif tagName == tagNames[17]:
system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})
elif tagName == tagNames[18]:
system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})
elif tagName == tagNames[20]:
system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})
else:
system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Fault"]]})
system.tag.editTag(tagPath = baseTagPath+"/Tank Percentage", attributes={"HistoryEnabled":True})#, "PrimaryHistoryProvider":"Pulp_Master"})