[Bug] system.opc.readValues() misses some values until system.opc.readValue() is used on them

I have some code that reads a list of OPC values using system.opc.readValues(), and noticed that often some values were returning as None. As soon as I would read the same path using the OPC Quick Client, suddenly the value would start showing up using system.opc.readValues(). This made me wonder if iterating through each path individually with system.opc.readValue() would work, and indeed it does, so I now have a check for None that causes the individual iteration to kick in if the batch read doesn't work:

def toolingUpdateFanuc(thorough=False):
	fos = getFasOpcServers()
	for machine in fos.keys():
		# REDACTED (populate tCounts and tPresets)
		counts = []
		if thorough:
			for i in range(numCounts):
				counts.append(system.opc.readValue(server, tCounts[i]))
			for i in range(numCounts):
				counts.append(system.opc.readValue(server, tPresets[i]))
		else:
			counts = system.opc.readValues(server, tCounts + tPresets)	# This doesn't always successfully read all values, hence the need for 'thorough'
		rawVals = []
		for i in range(numCounts):
			if counts[i].value is not None and counts[i + numCounts].value is not None:
				rawVals.append(tStations[i] + ' = ' + str(int(float(counts[i].value))) + ', ' + str(int(float(counts[i + numCounts].value))))
			else:
				if not thorough:	# Count and/or preset are None, so retry as 'thorough'
					toolingUpdateFanuc(True)
					return
				raise Exception(str(tStations[i]) + ' = ' + str(counts[i].value) + ', ' + str(counts[i + numCounts].value))
		system.tag.writeBlocking([machine + '/' + machine + '/_OPC/Tooling/Raw/Counts'], [rawVals])

This isn't necessarily a bug.

It sounds like whatever server/driver you're reading from batches read items into requests and some combinations include invalid addresses or addresses that otherwise cause the request to fail.

Ha, if this is a fanuc OPC server then I take it back, it probably is a bug... in that server.

3 Likes

Ha, if this is a fanuc OPC server

Yes, yes it is...

Well, if you disable security on that OPC connection and get a Wireshark capture then we can see for sure what's happening.

I have other more pressing items on my plate at the moment, and since my workaround seems to address the issue I need to move on to them, but hopefully I'll get a chance to revisit this since it isn't an ideal solution...