Issues with system.writeValue(s)

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
			returnedValues = system.opc.readValues(opcServer,deviceTags)
			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])
							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

Maybe you should take a step back and make sure a simple write works. You should also probably check the return value of the write calls to see if they are failing.

def writeAndCheck(itemPath, value):
	import system
	opcServer = 'Ignition OPC-UA Server'

	quality = system.opc.writeValue(opcServer, itemPath, value) 
	if not quality.isGood():
		print 'oh noes! writing %s to %s failed: %s' % (value, itemPath, quality)

writeAndCheck('[Logix]BASIC_BOOL', 1) 
writeAndCheck('[Logix]BASIC_DINT', 1234) 
writeAndCheck('[Logix]BASIC_INT', 5678) 
writeAndCheck('[Logix]BASIC_LINT', 99999999999) 
writeAndCheck('[Logix]BASIC_REAL', 3.14) 
writeAndCheck('[Logix]BASIC_STRING', 'some string value')

I could have sworn that I tested these methods individually as to attempt to get it to work, but I must have been wrong. I must have over complicated because your function allows it to clean my methods up. This is working now. Thanks.

I’d like to use this simple function that @Kevin.Herron wrote above. Can I call it from a Gateway event/tag change script?

Is the project library the best place for it? Would I need to assign my project to the “Gateway Scripting Project” entry on the gateway?