Does anyone have ideas on how to programmatically enable and disable the tag historian? I have an HMI application that requires that the tags to be stored by the historian only while the HMI is running. The end user is not allowed access to the tag provider configuration or the designer.
There is no global option for this and I have tried doing it using the following script but it requires a gateway restart after execution to make it work properly. Its also a messy solution.
from time import sleep # Added 7-21-20 RP
import system
#There is no global way to programmatically enable or disable the tag historian for multiple tags so #each tag must have the Enable History property changed manually using a script like this
#Unfortunately this script has a bug where it doesnât work properly. When the tags are re-enabled after #being disabled the historian breaks and doesnât store all of the tags.
#The only solution is to stop and start the Gateway after running this script.
#Even if a solution is found to fix this script it is a messy solution and would be difficult to maintain #when adding or removing more tags to the historian.
#Set the âhistoryEnabledâ state
def Enable(tagPath, boolVal):
tagConfig = system.tag.getConfiguration(tagPath + âvalueâ)
tagConfig[0][âhistoryEnabledâ] = boolVal
system.tag.configure(tagPath, tagConfig, âoâ)
def tagHistoryEnable():
# Set each Tag âhistoryEnabledâ parameter individually to True
# Pressure
tagPath = â[default]Param/PSI/â
Enable(tagPath, True)
# ROP
tagPath = â[default]Param/ROP/â
Enable(tagPath, True)
# Weight
tagPath = â[default]Param/WT/â
Enable(tagPath, True)
# Motor 1 Temp
tagPath = â[default]Param/Motor1_Temp/â
Enable(tagPath, True)
# Motor 2 temp
tagPath = â[default]Param/Motor2_Temp/â
Enable(tagPath, True)
# Tension
tagPath = â[default]Param/Tension/â
Enable(tagPath, True)
# Traction
tagPath = â[default]Param/Traction/â
Enable(tagPath, True)
# Length
tagPath = â[default]Lengthâ
tagConfig = system.tag.getConfiguration(tagPath)
tagConfig[0][âhistoryEnabledâ] = True
system.tag.configure("", tagConfig)
#I tried just restarting the historian but it doesnât Work! 8-10-20
# Triggers the Tag Historian to restart the Tag Historian Module
restartVal = system.tag.read("[default]HistorianRestart_Tag").value
system.tag.write("[default]HistorianRestart_Tag",restartVal+1)
# Allow time for the Tag Historian to restart before proceeding 7-21-20 RP
#sleep(1)
return "True" # dont need this just for testing...
def tagHistoryDisable():
# Set each Tag âhistoryEnabledâ parameter individually to False
# Pressure
tagPath = â[default]Param/PSI/â
Enable(tagPath, False)
# ROP
tagPath = â[default]Param/ROP/â
Enable(tagPath, False)
# Weight
tagPath = â[default]Param/WT/â
Enable(tagPath, False)
# Motor 1 Temp
tagPath = â[default]Param/Motor1_Temp/â
Enable(tagPath, False)
# Motor 2 temp
tagPath = â[default]Param/Motor2_Temp/â
Enable(tagPath, False)
# Tension
tagPath = â[default]Param/Tension/â
Enable(tagPath, False)
# Traction
tagPath = â[default]Param/Traction/â
Enable(tagPath, False)
# Length
tagPath = â[default]Lengthâ
tagConfig = system.tag.getConfiguration(tagPath)
tagConfig[0][âhistoryEnabledâ] = False
system.tag.configure("", tagConfig)
#Doesnât work! 8-10-20
# Triggers the Tag Historian to restart the Tag Historian Module
restartVal = system.tag.read("[default]HistorianRestart_Tag").value
system.tag.write("[default]HistorianRestart_Tag",restartVal+1)
# Allow time for the Tag Historian to restart before proceeding 7-21-20 RP
#sleep(1)
return "False" # dont need this just for testing...