How to constitute array of variable?

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

Moderator: uasdkcpp

Post Reply
zzimiya8610
Jr. Member
Jr. Member
Posts: 1
Joined: 06 Mar 2024, 07:44

How to constitute array of variable?

Post by zzimiya8610 »

Hi! I'm developing server using C++ SDK (v1.7.4).
I'd like to add array of variable, but i can't get a result in UaExpert.

I create a UaNodesetXmlParserUaNode using the pre-created xml file and add it to the UaServerApplication.
For example, I've written UaVariable as below. But i can't read and write all of values (i can read just one value({0})

How can i constitute array of variable if i want to add array of bytes? Please check my question and reply.
Actually I can't get ArrayDimensions from UaVariant in ReadValues()
  • Example of XML
<UAVariable DataType="Byte" NodeId="ns=1;s=LSPLC.GlobalVariable.OPC_INPUT" BrowseName="1:OPC_INPUT" UserAccessLevel="3" AccessLevel="3" ValueRank="1" ArrayDimensions="7">
<DisplayName>OPC_INPUT</DisplayName>
<Description></Description>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="False">ns=1;s=LSPLC.GlobalVariable</Reference>
</References>
<Extensions>
<Extension>
<DeviceInformation Device="A" Address="4194236" Type="2" Size="1"/>
</Extension>
</Extensions>
</UAVariable>
  • Result of UaExpert
Value : Byte Array[1]
[0] : 0
ValueRank : 1 (OneDimension)
ArrayDimensions : UInt32 Array[1]
[0] : 7

Utkrist
Hero Member
Hero Member
Posts: 22
Joined: 15 May 2023, 09:50

Re: How to constitute array of variable?

Post by Utkrist »

Hi,

I'm not a staff member, so take my answer with a grain of salt. I think you should change valueRank to -2. This means that you variable can be of 'Any' dimension.

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

Re: How to constitute array of variable?

Post by Support Team »

Hi,

it is (unfortunatly) little different than that.

The ArrayDimensions attribute specifies the maximum number of elements for each dimension not the current size. If you don't set the values in the XML file the value will be empty or initialized with some default value. So you either need to specifiy the default / starting value in the XML file or set it in the code.

see example XML file uanodesetimport.xml coming with the C++ DemoServer:

Code: Select all

    <UAVariable DataType="Byte" ValueRank="1" NodeId="ns=1;s=Demo.CTT.AllProfiles.Arrays.Byte" ArrayDimensions="10" BrowseName="1:Byte" UserAccessLevel="99" AccessLevel="99">
        <DisplayName>Byte</DisplayName>
        <References>
            <Reference ReferenceType="HasTypeDefinition">i=63</Reference>
            <Reference ReferenceType="Organizes" IsForward="false">ns=1;s=Demo.CTT.AllProfiles.Arrays</Reference>
        </References>
        <Value>
            <uax:ListOfByte>
                <uax:Byte>1</uax:Byte>
                <uax:Byte>2</uax:Byte>
                <uax:Byte>3</uax:Byte>
                <uax:Byte>4</uax:Byte>
                <uax:Byte>5</uax:Byte>
                <uax:Byte>6</uax:Byte>
                <uax:Byte>7</uax:Byte>
                <uax:Byte>8</uax:Byte>
            </uax:ListOfByte>
        </Value>
    </UAVariable>
Best regards
Unified Automation Support Team

Post Reply