Examples of Working with the Tag List

Data Types

For UDT/AOI or built-in structure data-types, information and definitions are stored in the data_types property. This property allow you to query the PLC to determine what types of tags it may contain. For details on the contents of a data type definition view Structure Definitions.

Print out the public attributes for all structure types in the PLC:

def find_attributes():
    with LogixDriver('10.61.50.4/10') as plc:
        ...  # do nothing, we're just letting the plc initialize the tag list

    for typ in plc.data_types:
        print(f'{typ} attributes: ', plc.data_types[typ]['attributes'])
>>> find_attributes()
STRING attributes:  ['LEN', 'DATA']
TIMER attributes:  ['CTL', 'PRE', 'ACC', 'EN', 'TT', 'DN']
CONTROL attributes:  ['CTL', 'LEN', 'POS', 'EN', 'EU', 'DN', 'EM', 'ER', 'UL', 'IN', 'FD']
DateTime attributes:  ['Yr', 'Mo', 'Da', 'Hr', 'Min', 'Sec', 'uSec']
...

Tag List

Part of the requirement for reading/writing tags is knowing the tag definitions stored in the PLC so that user does not need to provide any information about the tag besides it’s name. By default, the tag list is uploaded on creation of the LogixDriver, for details reference the LogixDriver API.

Example showing how the tag list is stored:

def tag_list_equal():
    with LogixDriver('10.61.50.4/10') as plc:
        tag_list = plc.get_tag_list()
        if {tag['tag_name']: tag for tag in tag_list} == plc.tags:
            print('They are the same!')

    with LogixDriver('10.61.50.4/10', init_tags=False) as plc2:
        plc2.get_tag_list()

    if plc.tags == plc2.tags:
        print('Calling get_tag_list() does the same thing.')
    else:
        print('Calling get_tag_list() does NOT do the same.')
>>> tag_list_equal()
They are the same!
Calling get_tag_list() does the same thing.

Filtering

There are multiple properties of tags that can be used to locate and filter down the tag list. For available properties, reference Tag Structure. Examples below show some methods for filtering the tag list.

Finding all PID tags:

def find_pids():
    with LogixDriver('10.61.50.4/10') as plc:

        # PIDs are structures, the data_type attribute will be a dict with data type definition.
        # For tag types of 'atomic' the data type will a string, we need to skip those first.
        # Then we can just look for tags whose data type name matches 'PID'
        pid_tags = [
            tag
            for tag, _def in plc.tags.items()
            if _def['data_type_name'] == 'PID'
        ]

        print(pid_tags)
>>> find_pids()
['FIC100_PID', 'TIC100_PID']