dmroeder / pylogix

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

Read/Write multiple tags when tags are array #136

Open ramezanifar opened 4 years ago

ramezanifar commented 4 years ago

Preflight checks

Type of issue

Description of issue

Hello; I was trying to read/write multiple tags while tags are arrays. Example:

tag_list = ['array1', 'array2']

where array1 is SINT[100] and array2 is SINT[100]

Now if I read the tag list in one attempt, it returns only the first index of each array:

ret = comm.Read(tag_list)
for r in ret:
   print(r.Value)

Is there a way to pass the length? I tried to sum up the length of all tags and use something like:

ret = comm.Read(tag_list, 200)

But still the same problem.

In addition to the read, I could not figure out multiple write when tags are array. Can you please give me a hint? Thank you in advance

dmroeder commented 4 years ago

First, apologies for the long delay.

Short answer, you cannot read arrays with lists of tags.

Long answer: at some point I added the ability to provide the data type with with a single tag read or a list of tags to read. This helped improve performance for people that read a lot of unique tags because it eliminates getting the data type first. So when you attempt to do something like this:

tags = [('tag1[0]', 10), ('tag2[0]', 10)]
ret = comm.Read(tags)

I'm assuming that the 10 in those cases is the data type. It would then skip getting the data type, assuming that it was "10", and get the values for tag1[0] and tag2[0]. That is why you only get the first element.

I made some changes the other day to take advantage of the multi-service message object in order to bundle getting the data multiple data types into one packet. This speeds things up quite a bit for reading unique tags.

This doesn't help you though when trying to read lists of arrays. For now, only read non-arrays in lists, read arrays individually to get the best performance. I have functioning code to read arrays with lists, but I will have to figure out 2 things: Using multi-service messages (mulit-read) with arrays larger an a single packet, and what to do about people that are currently providing the data type to bypass discovering the data type. In other words, I'll probably have to make a change that would break compatibility in to accommodate this, which I don't like to do.