Skip to content

Added list read/write for symbols#514

Open
RobertoRoos wants to merge 6 commits into
stlehmann:masterfrom
RobertoRoos:feature/symbol_list
Open

Added list read/write for symbols#514
RobertoRoos wants to merge 6 commits into
stlehmann:masterfrom
RobertoRoos:feature/symbol_list

Conversation

@RobertoRoos

Copy link
Copy Markdown
Contributor

Replacement for the faulty:

Fixes #266

This adds the option to read multiple symbols at once, or write to multiple at once.

Unfortunately this is not directly compatible with adsSumRead and adsSumWrite (assuming we don't want the redundant info lookup when using only the name).
This is because those functions are based on the SAdsSymbolInfo structs, which contain the integer dataType, instead of a ctypes like plc_type.

I've tried to move some of the logic to separate functions so they can be reused, but the new symbol read/write methods resemble the classic functions a lot.

Example script:

from pyads import Connection
from random import random

plc = Connection('127.0.0.1.1.1', 851)

with plc:

    var_names = [
        "GVL.my_double",
        "GVL.another_double",
        "GVL.my_text",
        # "GVL.my_list"
    ]

    symbols = [plc.get_symbol(var) for var in var_names]

    new_data = [random(), random(), "Hello again"]

    data_with_names = dict(zip(var_names, new_data))

    # response = plc.write_list_by_name(data_with_names)
    # print(response)

    response = plc.write_list_symbols(symbols, new_data)
    print(response)

    # data = plc.read_list_by_name(var_names)
    # print(data)

    result = plc.read_list_symbols(symbols, True)
    print(result)

    for symbol in symbols:
        print(symbol.name + ":", symbol.value)

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

Successfully merging this pull request may close these issues.

Feature: read/write by list for AdsSymbol

1 participant