10:49, EEST
December 6, 2018
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); } }
15:30, EEST
December 21, 2011
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.
9:01, EET
December 6, 2018
15:44, EET
December 21, 2011
11:10, EET
December 6, 2018
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?
12:41, EET
December 21, 2011
15:18, EET
December 6, 2018
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
15:28, EET
December 21, 2011
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.
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, biancacraft16Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1