Hello,
Customer wants to read a two-dimensional array using PVI.
I have tried and found the two-dimensional array will automatically change to a a dimensional array on the C# side:
Using this code we can read all data of a 3x3 array:
The definitaion on AS side:
But we can not reading like this:
Is that a way that we can read data as the original 3x3 format?
Thanks!
Hello Shenyang Zhou,
I think the simplest solution would be to rearrange the 1 dimension array back to a two dimension array in C#. Since the array size is fixed in AS, the array dimension is known factor.
Taking example here, where you have a 3x3 array, you know for sure that each indivildual array has a size of 3. with this information you can try the following (taking parts of you code)
for (int i = 0; i < array.getLenght(0); i++)
{
int j = i / 3; //A integer division, will only chnage value when i become next multiple of 3
int k = i % 3; //module value of the i to 3, the value will change cyclically going from 0 to 2.
Console.WriteLine($"Value[{j},{k}] = {array.getValue(i)}")
}
Like this the one dimensional array will splited into a 2 dimensional one.
On the other hand, you can also use array of arrays instead of multi dimensional arrays. In place of USINT[0…2,0…2], you can use USINT[3][3], and then send each USINT[i] as separated variable to C# programm, and then pile them there separately.
Regards
1 Like
It seems good, Thanks Wenbo!