dmroeder/pylogix

The return value is different when using a multi write compared to a single write for a string.

Closed this issue · 4 comments

Description of issue

When writing to a string using a Multi Write, the return value is in raw byte format.
Whereas with a single Write, the return value is a string.

Code

from pylogix import PLC

with PLC() as comm:
    comm.IPAddress = "192.168.1.9"
    
    write_data = [("myDint", 100), ("myString", "Hello")]

    # write the values
    ret = comm.Write(write_data)

    # print the status of the writes
    for r in ret:
        print(r.TagName, r.Value)

Prints:

myDint [100]
myString [[5, 0, 0, 0, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

Whereas if I just do a single write:

ret = comm.Write("myString", "Hello")
print(ret.TagName, ret.Value)

Prints:

myString Hello

Versions

  • pylogix: 0.8.11
  • python: 3.11
  • OS: Windows

For this, could you just include the original data when calling _parse_multi_write as well as the data in byte format?
And then parse accordingly.

Yeah, something along those lines. Hopefully I'll have a fix for that one today, then I'll push an update.

SideNote, booleans_fit is always True

booleans_fit = True

pylogix/pylogix/eip.py

Lines 593 to 601 in 95d6bc9

else:
# BOOLs didn't fit in the current packet, abort
booleans_fit = True
tag_count = tmp_count
break
if booleans_fit:
# if the booleans fit in this request, append them.
write_values.extend(tmp_write_values)
service_segments.extend(temp_segments)

Amalgamated into #224