I have an application I'm working on that has the possibility of functioning in 2 modes.
1 mode is a local PC-only mode. the second mode is communicating with a PLC. initially, I planned on having a gateway script that would look at a configuration variable and update PLC tags if we are running in that mode (and the tags exist in the PLC). However, I've found that I can change the type of the tag from a memory to an OPC tag using the system.tag.configure function. I have it working, mostly, but I'm running into a single issue. It isn't actually updating the tag with the correct variables.
This is the code I'm using to update the tag variables. It works fine but the tag parameters don't actually seem to refresh. If I go into the tag and physically select the Value Source all of a sudden it will refresh itself and connect.
This image is of it in the memory configuration
This image is of it right after I've changed the configuration to OPC. You can see the Value Source has changed, but the properties didn't update. I'm even writing to the additional properties to get them to change... but they don't show up.
As soon as I physically select OPC it will activate the additional properties and take off without me having to actually change anything.
Do any wizards out there have any spectacular ideas on how to refresh or restart the tags? This isn't a high change system. Only on initial configuration would it ever change.
#get the configuration Type from the tag value
staID=502308102
PLCName='TestPLC'
configType=system.tag.readBlocking('[default]uAuth/U'+str(staID)+'/PCStation')[0].value
print configType
parentPath = "[default]uAuth"
plcTagList=['badgeNum','clockNum','Function','FunctionResult','LastToken','StaID','token','uFlags','uLevel','uName','uSponsorID','uSponsorName']
# Get the current configurations
configs = system.tag.getConfiguration(parentPath+'/U'+str(staID), True)
# Iterate over the results
for item in configs:
# Through the results, search each dictionary
for key, value in item.iteritems():
if key == 'tags':
for tagConfig in value:
if tagConfig["name"] in plcTagList:
if configType == 0:
# set the tags to OPC Tags
tagConfig['valueSource'] = 'OPC'
tagConfig['opcserver'] = 'Ignition OPC UA Server'
tagConfig['opcItemPath'] = 'ns=1;s=[TestPLC]{InstanceName}.API.'+str(tagConfig["name"])
if configType == 1:
# set the tags to OPC Tags
tagConfig['valueSource'] = 'memory'
system.tag.writeBlocking('[default]uAuth/U'+str(staID)+'/PCStationLast', configType)
#write the tag configurations to the tags
system.tag.configure(parentPath, configs, "o")