How to read arrays of int or structs from the client ? |OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How to read arrays of int or structs from the client ?
Avatar
Yiming Sun
Germany
Member
Members
Forum Posts: 6
Member Since:
10/04/2021
sp_UserOfflineSmall Offline
1
02/08/2022 - 11:18
sp_Permalink sp_Print

Hello, I’m using a OPC UA Client in C# WPF Framework to read several values of variables in a PLC Project (Beckhoff) through OPC UA Server.

 

In the PLC Project, there are some variables like Array of Int, Array of Real, and Array of Structs. 

 

I’m using the source code from GitHub provided by OPC Foundation. Here are the codes. Symbols = Variables in PLC

Knowing the NodeID of a Variable, I add it to the nodesToRead

 

ReadValueIdCollection nodesToRead = new ReadValueIdCollection()
{
new ReadValueId() { NodeId = symbol.NodeId, AttributeId = Attributes.Value },
};

// Read the node attributes
m_output.WriteLine(“Reading node {0}”, symbol.SymbolName);

// Call Read Service
m_session.Read(
null,
0,
TimestampsToReturn.Both,
nodesToRead,
out DataValueCollection resultsValues,
out DiagnosticInfoCollection diagnosticInfos);

m_validateResponse(resultsValues, nodesToRead);

 

//store the value of the Node to the Symbol / Variable Class

symbols.SymbolValue = resultsValues[0].Value;

 

So for example, if I read Integer Array[3 x 6] from the PLC, it returns in resultValues only the type of this array, which is Int [3, 6]

Can someone tell me how to access the value of single value in this Array ?  like how to get the value of Array (2, 3) ? 

  

Avatar
Randy Armstrong
Admin
Forum Posts: 1580
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
02/08/2022 - 13:36
sp_Permalink sp_Print

Multidimensional Arrays are accessed via the Matrix helper class.

There should be a way to cast the Variant returned to a Matrix (look at the methods on the Variant class).

Avatar
Yiming Sun
Germany
Member
Members
Forum Posts: 6
Member Since:
10/04/2021
sp_UserOfflineSmall Offline
3
02/09/2022 - 07:39
sp_Permalink sp_Print

Randy Armstrong said
Multidimensional Arrays are accessed via the Matrix helper class.

There should be a way to cast the Variant returned to a Matrix (look at the methods on the Variant class).

  

Thank you,

could you please tell me where I can find the matrix helper class or the variant class ? Smile

Avatar
Randy Armstrong
Admin
Forum Posts: 1580
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
02/09/2022 - 09:27
sp_Permalink sp_Print sp_EditHistory

https://github.com/OPCFoundati…..Variant.cs

[DataContract(Namespace = Namespaces.OpcUaXsd)]

public class Matrix : IFormattable
Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 20
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1446
Posts: 4891