dmroeder / pylogix

Read/Write data from Allen Bradley Compact/Control Logix PLC's
Apache License 2.0
599 stars 182 forks source link

reading multidimensional array #91

Closed gnail13 closed 4 years ago

gnail13 commented 4 years ago

Hi all,

I have a project that I need to retrive a two-dimensional array size of [1000][7]. How can I read it? Thanks in advance.

Lan

dmroeder commented 4 years ago

You use the same syntax as in RSLogix/Logix Designer:

MyTag[0,0]

gnail13 commented 4 years ago

Can I use indirect addressing like MyTag[i,j] to access the array other than tag.Read(MyTag[0,0], 100)?

gnail13 commented 4 years ago

In other words can I traves the array with for loop? So I can read the data on first dimension MyTag[i,0].

dmroeder commented 4 years ago

You could do something like:

for i in range(10):
    tag_name = 'MyTag[{},0]'.format(i)
    ret = comm.Read(tag_name, 100)

Is that what you were thinking?

gnail13 commented 4 years ago

I am not sure that's the result I wants but I would try it. Thank you.

dmroeder commented 4 years ago

First iteration would get you 100 values starting at Mytag[0,0] (MyTag[0,0-99]) Next iteration would get you 100 values starting at Mytag[1,0] (MyTag[1,0-99]) and so on

Edit: If you can't get the result you want, describe in some more details exactly what you want to read and I'll give a more specific suggestion

gnail13 commented 4 years ago

Thank you dmroeder. That's what I need.

AlePanto commented 1 year ago

I am having similar issues:

Need to read the entire TD_Array DINT[10,7]

'''What is wrong with the code?'''

from pylogix import PLC

with PLC() as comm: comm.IPAddress = '192.168.1.15' ret = comm.Read('TD_Array[10,7]' ) #what do I nee to specify? print(ret.Value)

'''Thank you for the help'''

dmroeder commented 1 year ago

Install the latest version (0.8.8). I broke something with multi dimension arrays.

https://github.com/dmroeder/pylogix/commit/0070aba09f705e541ec57cb33017289ec26c5bd1

pip install --upgrade pylogix

AlePanto commented 1 year ago

Nevermind!!!! Iit works, Thank YOU!!!!!!!