How to write to a 1-dimension array?

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
Senero
Jr. Member
Jr. Member
Posts: 1
Joined: 15 Feb 2023, 10:03

How to write to a 1-dimension array?

Post by Senero »

Hi,

I am working on the .Net 6 framework.

I have a custom C# application reading and writing to a OPC Server.
It works OK so far.

However, there is now a new NodeId added with 1-dimensional array and I need to write values to all the variable inside the array groups.
I've researched the topics regarding arrays in this forum but, I don't exactly see the same case as I have.

Here is my new NodeId;
Image

I've tried this piece of code which is working OK with scalar and I've improvised it a bit in order to adapt to array case.
But, of course, if this is even the right way of doing this, I can still see two issues at a glance;

1. int[] array is not what I want. It could be maybe an object[] for allowing different typed values (how about then type casting?)
2. How can I choose array index so I can write to any array group selectively? e.g. ACS_PRODUCT_DATA[3].ACS_ORDER_NUMBER = 5

Code: Select all

      int[] testArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
      Variant valuesInArray = new Variant(testArray);
      DataValue dataValue = new DataValue();
      dataValue.Value = valuesInArray;

      nodesToWrite.Add(new WriteValue()
      {
        NodeId = NodeId.Parse(nodeId),
        Value = dataValue,
        AttributeId = Attributes.Value
      });
      List<StatusCode> results = _iopcService.Session.Write(nodesToWrite);
Any input greatly appreciated.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: How to write to a 1-dimension array?

Post by Support Team »

Hello,

The value to write is an array of structured DataTypes.

If the structured DataType is know at compile time, you can use UaModeler to generate code this DataType. This code can be used in your client application. Please see the client tutorials in UaModeler in this case.

If the structured DataType is not known at compile time, the client needs to get the structure information about the DataType from the server addressspace at runtime. The server can do this in two ways:
* DataTypeDictionary. You can use the class DataTypeManager in this case. Please see the examples in Client Getting Started and ConsoleClient.
* DataTypeDefinition attribute. There is currently no toolkit class in the sdk supporting this feature in a a generic way. We are working on it.
Best regards
Unified Automation Support Team

Post Reply