I need to compare the values coming out of the new Ignition system and an existing system.
I have a button setup trying to use system.tag.storeTagHistory but I keep getting different errors. Just wondering if this is something you can even do?
Current error:
Error forwarding data
java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to VARCHAR is unsupported.
def runAction(self, event):
# Enable print to Ignition logger.
logger = system.util.getLogger("API_POST_Logger")
#parentPath = self.parent.parent.getChild("FlexContainer_Hist_Tag_Path").getChild("TextField").props.text
parentPath = "[default]07"
logger.info(parentPath)
# Get a list of all tags in the system
results = system.tag.browseTags(parentPath=parentPath, recursive=True)
# Prepare lists for tag paths and values
tagPaths = []
values = []
# Iterate through the results to get tag paths and current values
for result in results:
tagPath = result.fullPath
currentValue = system.tag.readBlocking([tagPath])[0].value
tagPaths.append(tagPath)
values.append(currentValue)
# Store the current values in the historian
system.tag.storeTagHistory(historyprovider="MSSQLServer", tagProvider="[default]", Paths=tagPaths, values=values)
# Log success
logger.info("Successfully stored current values to historian for tags: " + str(tagPaths))
Your code looks like you're logging all tags, not just tags with history, but I think your tagProvider should just be "default" without the brackets when calling storeTagHistory.
Also, you'd be better off running your for loop like this to get all the tag paths first, then reading them all at once:
provider = 'default'
query = {
"options": {
"includeUdtMembers": True,
"includeUdtDefinitions": False
},
"condition": {
"attributes": {
"values": [
"history"
],
"requireAll": True
}
},
"returnProperties": [
"tagType",
"quality"
]
}
results = system.tag.query(provider, query)
for result in results:
tagPaths.append(result['fullPath'])
values = [tag.value for tag in system.tag.readBlocking(tagPaths)]
system.tag.storeTagHistory(historyprovider="MSSQLServer", tagprovider=provider, paths=tagPaths, values=values)
Thanks, I get all the "defaults" confused. Even when I'm using the correct one sometimes you need it in the path and sometimes you don't and so on.
I had been trying a few things and the tagType was left out of my posted example. Not sure if it is working, I'm wanting to find only the Expression tags and that is one that is not listed in the manual. If I try something that I know should not work it gives an error about that tagType not being correct but it seems to be ok with "Expression" as the type.
Possible values are OPC, MEMORY, DB, QUERY, Folder, DERIVED and UDT_INST.
I no longer get the error after removing the brackets. tagProvider="default"
Now I just need to see if it did what I need.
Also need to see where the heck this other "default" came from. I know how to get rid of old tags that still show up in the tag browse but no idea how I managed this one with the brackets.
Use the tag report tool to build out the query as needed and copy the query as JSON and use it in place of what I put. It will work better than the browse function you're currently using.
Pedant fix: values = [qval.value for qval in system.tag.readBlocking(tagPaths)]
However, the tag report function can also return values, so I'd use them instead of reading them if you care about code speed (looks like this is a once off though, so )
I wanted to get the values into the historian so the same tools can write the values out to the Azure database and they are processed the same as normal. Then I can compare to a dump from the old system from the same time.
It is just a one (or two) off and it runs really fast as is.
Anyone know where the extra bracketed object in the tab browser came from or how to get rid of if?