I am able to use the system.opc functions to scroll through several devices and check opc tags and their values. This works easily and absolutely no problems.
But, system.opc.writeValue and system.opc.writeValues silently fails every time.
There is not enough information within the documentation to correctly use this function. If the tag type is set to BOOL and I use ‘True’, there is no change of value for the called tag. I am literally using the same device address for the read and I am for the write. So the addressing is the same yet the values do not change.
I understand that it can accept string values, but what are the BOOL or binary values that we can use?
Anyone know how to use this function properly and have any examples? I am using full string addresses:
This is just a section of the code. This script runs properly without errors, but there is no change of value.
deviceTags = []
resetDeviceTags = []
tagIndex = 0
for tag in checkTags:
deviceTags = deviceTags + ["[DEVICE"+str(DEVICE)+"]Global.DEVICE"+str(DEVICE)+"_"+tag]
resetDeviceTags = resetDeviceTags + ["[DEVICE"+str(DEVICE)+"]Global.DEVICE"+str(DEVICE)+"_"+resetTags[tagIndex]]
tagIndex += 1
try:
returnedValues = system.opc.readValues(opcServer,deviceTags)
except:
returnedValues = 0
if returnedValues != 0:
#print returnedValues
tagIndex = 0
for returnedValue in returnedValues:
if str(returnedValue.quality) == "Good":
print "Reading quality of "+str(deviceTags[tagIndex])+": "+str(returnedValue.quality)
#print "%s == %s" % (str(returnedValue.value),str(testFor[tagIndex]))
if str(returnedValue.value) == testFor[tagIndex]:
#print "[DEVICE"+str(DEVICE)+"] = "+str(returnedValue.value)
resultValue = system.opc.readValue(opcServer,resetDeviceTags[tagIndex])
watchdog = 0
while changeTo[tagIndex] != resultValue.value:
watchdog += 1
if watchdog > 500:
print "Sending command to %s timed out..." % (resetDeviceTags[tagIndex])
break
resultWrite = system.opc.writeValue(opcServer,resetDeviceTags[tagIndex],changeTo[tagIndex])
resultValue = system.opc.readValue(opcServer,resetDeviceTags[tagIndex])
if (changeTo[tagIndex] == resultValue.value)
print "Changed Values for: "+str(resetDeviceTags[tagIndex])
tagIndex += 1