Writing arrays of generic structs #2265
-
I'm fairly new to OPC UA so I might be going about this completely the wrong way. I have to write generic data that is not known at compile time to a SPS. So far I managed to write all simple data types as well as arrays of simple type and single structs. I can't seem to find a way to get the necessary data to create a WriteValue for an array of structs, though. For structs I'm converting the data to a byte array and get the StructureDefinition from the node to create and ExtensionObject to use for the WriteValue. My code looks like this:
The structs can be created dynamically in the software (to match the structure on the SPS). I was hoping to just be able to create a byte array starting with the number of structs, followed by concatenated byte arrays of the structs. Where am I going wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
OK, I managed to get a step closer to the solution but I still get BadTypeMismatch errors even though the Value of my WriteValue looks exactly like the Value of the ReadValue when I read the array of structs from the PLC.
I tried to set the data type of the node I write into but TypeId is readonly. Any help would be really appreciated. |
Beta Was this translation helpful? Give feedback.
Finally found a way. I'm reading the structure information of the first element and use this to tell the OPC UA server how to interpret the data I send.
`var innerNode = GetNodeId(path+"[0]");
Dictionary<uint, DataValue> nodeAttributes = ReadNodeAttributes(nodeId.ToString());
DataTypeNode dataTypeNode = (DataTypeNode)ReadNode(nodeAttributes[Attributes.DataType].ToString());