Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
MultiDimensionArrayUtils.demuxArray not able to handle multi dimension array
October 29, 2021
10:49, EEST
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 18
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Following code returns java.lang.ArrayIndexOutOfBoundsException.
Could you please tell us if this is a known bug and How can we demux multi dimension array using prosys-opc-java-sdk ?

 public static void main(String[] args) {
        int src[][] = new int[][]{{1, 2, 3}, {2, 3, 4}};
        int dims = MultiDimensionArrayUtils.getArrayLengths(src);
        MultiDimensionArrayUtils.demuxArray(src, dims);
     }
 }
October 29, 2021
15:30, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

You have a couple of things wrong here. First, getArrayLengths returns an array of dimensions. Second, you actually want to ‘mux’ your array, instead fo ‘demux’.

  /**
   * Multiplex multi-dimension array (x[][][]) to single-dimension array (x[]).
   *
   * @param src multi-dimension array
   * @param dims an array of int.
   * @return single-dimension array
   */
  public static Object muxArray(Object src, int[] dims)

  /**
   * Demux single-dimension array (x[]) to a multi-dimension array (x[][][]).
   *
   * @param src single-dimension array
   * @param dims an array of int.
   * @return multi-dimension array
   */
  public static Object demuxArray(Object src, int[] dims)

So, try this:

  @Test
  public void testDemuxArray2() {
    int src[][] = new int[][] {{1, 2, 3}, {2, 3, 4}};
    int[] dims = MultiDimensionArrayUtils.getArrayLengths(src);
    MultiDimensionArrayUtils.muxArray(src, dims);
  }

But – what are you actually trying to do? If you just wish to deliver arrays via OPC UA variables, you don’t need to multiplex them yourself – the SDK will do this automatically for you.

PS. ‘<pre>’-tags help with keeping the outline of code.

November 2, 2021
9:01, EET
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 18
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Thanks, Jouni Aro for the detailed explanation.
Could you please tell in what scenario/use case we need to convert multi-dimension arrays to single dimension arrays?

November 2, 2021
15:44, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Usually you don’t need to use it yourself, since the SDK uses it internally, whenever needed.

That’s why I asked that what are you actually trying to do?

November 3, 2021
11:10, EET
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 18
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

We are trying to convert primitive type multi-dimension array to respective wrapper type multi-dimension array. We thought that the demux method does it.
We are actually not sure if it is a valid scenario to expect a primitive type array from the OPC UA server. Could you please tell us if we need to consider the use case or it is guaranteed that the OPC UA server never sends a primitive type array?

November 5, 2021
12:41, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes, you don’t need to that yourself, and you can expect that you always receive the multidimensional arrays demuxed for you.

November 5, 2021
15:18, EET
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 18
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Hi Jouni Aro,

Thank you for the information.
I didn’t get one thing. Earlier you mentioned that mux is used to convert multi-dimension array to a single dimension and demux is for the other way around.
But in the last comment you mentioned “you always receive the multidimensional arrays demuxed for you” , does this mean I will always get Object/wrapper type array.
and the dimension of the array will not change right ?

Thanks,
Dipankar

November 5, 2021
15:28, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes the OPC UA Stack uses the mix and demux internally. But if your server puts a three dimensional array in a Variant, it comes out as a three dimensional array in a Variant in the client.

So the mixing is just used to transfer data over wire in OPC UA, but when you use the SDK and Stack, you don’t need to care about that.

November 7, 2021
15:12, EET
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 18
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

@Jouni Aro , Thanks for the information.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 735

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1523

Posts: 6449

Newest Members:

rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1