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])