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: 914
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: 914
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: 914
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: 914
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: 267

Currently Online:
13 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 111

pramanj: 86

ibrahim: 74

kapsl: 57

gjevremovic: 49

Xavier: 42

TimK: 41

fred: 41

Fransua33: 39

rocket science: 36

Member Stats:

Guest Posters: 0

Members: 1590

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1192

Posts: 5057

Newest Members:

warnerfleming, Raymond23Freex, Charles1UsadY, Robertvem, albertinaduff53, wilbertrignall, Rogerbeedo, letamunn4183992, Lizazooda, Hectorner

Moderators: Jouni Aro: 914, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 695, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 24, Teppo Uimonen: 21, Markus Johansson: 36, Niklas Nurminen: 0, Matti Siponen: 161, Lusetti: 0

Administrators: admin: 1