Skip to content

read_list_by_name automatically destructures arrays of length one #501

@premnetsuwan-tpeng

Description

@premnetsuwan-tpeng

PLC code:

test1 : ARRAY[1..1] OF REAL;
test2 : ARRAY[1..2] OF REAL;
test3 :REAL;

Python code:

import pyads

AMS_NET_ID = "my_ams_net_id"
plc = pyads.Connection(AMS_NET_ID, pyads.PORT_TC3PLC1)
plc.open()


test1 = plc.read_by_name("PyADSOut.test1")
test2 = plc.read_by_name("PyADSOut.test2")
test3 = plc.read_by_name("PyADSOut.test3")
variables = plc.read_list_by_name(
    [
        "PyADSOut.test1",
        "PyADSOut.test2",
        "PyADSOut.test3",
    ]
)

print(f"{test1=}")
print(f"{test2=}")
print(f"{test3=}")
print(f"{variables=}")

Terminal output

test1=[0.0]
test2=[0.0, 0.0]
test3=0.0
variables={'PyADSOut.test1': 0.0, 'PyADSOut.test2': [0.0, 0.0], 'PyADSOut.test3': 0.0}

I would expect that test1 would be [0.0] in all cases, but read_list_by_name gives back the element 0.0 instead of the array, which is different behavior from read_by_name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions