Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read a multi dimension array #23

Open
reyphilipp opened this issue Sep 1, 2018 · 6 comments
Open

Read a multi dimension array #23

reyphilipp opened this issue Sep 1, 2018 · 6 comments

Comments

@reyphilipp
Copy link

Hi,

How i can read, example test[0,1] ?

@cwchien
Copy link

cwchien commented Jan 21, 2019

Try readTag("test[0][1]", short(1))

If you want to read along with the second dimension, try readTag("test[0][0]", short(10))

@MFolte
Copy link

MFolte commented Apr 3, 2020

Hi,

I'm also having trouble reading from and writing to a multidimensional array.

I have a DINT array as such: dintArray2[10][10].

I am able to read all 100 array elements at once by using device.readTag("dintArray2", (short)100). In the same way I'm able to write back all 100 array elements at once.

However that's not what I want. I need to be able to write back a single element in a multidimensional array.

For a one dimensional array it's as easy as device.readTag("dintArray1[1]").
Unfortunately the doesn't work for multidimensional array like device.readTag("dintArray2[1][1]").

@yue792069154
Copy link

Unfortunately the doesn't work for multidimensional array like device.readTag("dintArray2[1][1]")

Have you solved it yet?

@cwchien
Copy link

cwchien commented Apr 25, 2023

If you want to read single element, you have to use device.readTag("dintArray2[1][1]", (short)1), the (short)1 means you want read one element start from "dintArray2[1][1]" (value at "dintArray2[1][1]").

If you want to read 5 elements, you have to use device.readTag("dintArray2[1][1]", (short)5), means read values from "dintArray2[1][1]" to "dintArray2[1][5]".

And also remember that array index start from 0, so index 1 in fact the second element.

Best Regards,
Chien

@yue792069154
Copy link

This is the program I wrote:
image

This is the tag inside the PLC
image

Unable to read, error reported as follows:
etherip.data.CipException: Status: 0x05 [Path destination unknown, The path is referencing an object class, instance or structure element that is not known or is not contained in the processing node. Path processing shall stop when a path destination unknown error is encountered.] - Extended: 0x00

@cwchien
Copy link

cwchien commented Apr 26, 2023

You can't just print CIPData because it's a structured data. You have to use access methods to "extract" it (ex. getNumber, getString...).

This is my util class to deal with Number/Boolean/String CIPDatas and compatible with multidimensional array, it's writen in Groovy but very similar with Java.
Hope it helps. :)
https://gist.github.com/cwchien/0060ff0786bbc7bd4f5955a8b92305ee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants