Scripting - system.opc.readValue - Issue with struct

I'm on 8.1.20

Don't know when issue appear, but the script below was working well before and now got issue. We haven't use it since some months, but really need this work again.

The script read an array of object by using system.opc.readValue, ofter that I loop into the readed array to get values.

	
	opc_info = _Functions.getOPCinfo(value["provider"] + "cell/state_cell")
	opc_server = opc_info["server"]
	opc_path = opc_info["opc_path"] + ".check_event_log_array"
		
	check_event_log_array = system.opc.readValue(opc_server, opc_path).getValue()
	
	for i in range(value["first"], value["first"] + value["count"]):
		index = i % value["capacity"]
		entity = system.util.jsonDecode(str(check_event_log_array[index]))

		alert_level = entity["severity"]
		check_code = entity["code"]
		entity_id = entity["entity_id"]
		caused_by_user = entity["caused_by_user"]
		created_on = entity["created_on"]

Posting any details about the issue would be helpful.
In particular, what error(s) are being thrown, the stacktrace, line numbers being indicated as the problem, etc. Check your gateway logs if you're not sure where to start looking. Also, where are you executing this script?

1 Like

When I trie to read the array from system.opc.realValue it return null value

[null, Bad("Bad_AttributeIdInvalid: The attribute is not supported for the specified Node."), Mon Nov 21 13:36:26 EST 2022 (1669055786610)]

What server is this? What is the NodeId (OPC Item Path)?

This is coming from the server... it probably means something like you're trying to read a value from an object that isn't a VariableNode.

My variable is an array of object...
image

I'm not when it stopped to works exactly but with 8.1.18 and higher it doesn't work anymore

opc_path => nsu=urn:BeckhoffAutomation:Ua:PLC;s=MAIN.cell.state_cell.check_event_log_array

Navigate to this Node using something like UaExpert and see what its NodeClass and other properties are. Provide a screenshot of the attributes pane while viewing this Node.

image

Ok... so that's an Object.

Your script never could have worked unless somebody changed the server model recently.

Is there a way to read an object with system.opc.readValue ?

No, ObjectNodes don't have a value.

In this case it looks like it's being used to organize references to each of the individual elements. If those are VariableNodes you can read the value of each of them.