From 56024072207c9401f0f7d0328fdfc496b6e9b024 Mon Sep 17 00:00:00 2001 From: ottowayi Date: Thu, 4 Nov 2021 16:10:40 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix=20for=20parsing=20tag=20?= =?UTF-8?q?requests=20with=20multiple=20array=20indexes=20along=20the=20pa?= =?UTF-8?q?th?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pycomm3/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycomm3/util.py b/pycomm3/util.py index 9f75aab..76e99ef 100644 --- a/pycomm3/util.py +++ b/pycomm3/util.py @@ -49,7 +49,7 @@ def get_array_index(tag: str) -> Tuple[str, int]: 'tag[100]' -> ('tag', 100) """ if tag.endswith("]") and "[" in tag: - tag, _tmp = tag.split("[") + tag, _tmp = tag.rsplit("[", maxsplit=1) idx = int(_tmp[:-1]) else: idx = None From 79d3d5ad9ae6e41f9c39f09affc9076732efcd34 Mon Sep 17 00:00:00 2001 From: ottowayi Date: Fri, 5 Nov 2021 09:27:49 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fixed=20regression=20in=20BO?= =?UTF-8?q?OL=20member=20parsing=20for=20UDTs,=20should=20handle=20both=20?= =?UTF-8?q?UDTs=20and=20AOIs=20correctly=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pycomm3/logix_driver.py | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/pycomm3/logix_driver.py b/pycomm3/logix_driver.py index c5c16e9..6cd3608 100644 --- a/pycomm3/logix_driver.py +++ b/pycomm3/logix_driver.py @@ -772,8 +772,8 @@ def _parse_template_data(self, data, template): template_name, _ = name.split(";", maxsplit=1) else: member_names.append(name) - except (ValueError, UnicodeDecodeError) as err: - raise ResponseError(f"Unable to decode template or member names") from err + except ValueError as err: + raise ResponseError("Unable to decode template or member names") from err predefine = template_name is None if predefine: # predefined types put name as first member (DWORD) @@ -792,27 +792,26 @@ def _parse_template_data(self, data, template): _struct_members = [] _bit_members = {} _host_members = {} # {offset: (member name, type)} + _multibyte_hosts = {} # hosts for bits that are larger than sints for member, info in zip(member_names, member_data): - if not (member.startswith("ZZZZZZZZZZ") or member.startswith("__")): - if predefine and member == "CTL": - # assumes CTL is the only host member for predefined types - # and treat it as a private attribute - _host_members.update( + if (member.startswith("ZZZZZZZZZZ") or member.startswith("__")) or ( + predefine and member == "CTL" + ): + _host_members[info["offset"]] = (member, info["type_class"]) + if info["type_class"].size > USINT.size: + # for host members larger than sints, store what the individual bytes offsets + # would be and use them to update the bit numbers later on for the bool methods + # that way we don't have to mess with changing the offset sizes + # {offset: (member_name, offset in host member, offset in packet)} + _multibyte_hosts.update( { - (info["offset"] + i): (member, info["type_class"]) + info["offset"] + i: (member, i, info["offset"]) for i in range(info["type_class"].size) } ) - else: - data_type["attributes"].append(member) - else: - _host_members.update( - { - (info["offset"] + i): (member, info["type_class"]) - for i in range(info["type_class"].size) - } - ) + else: + data_type["attributes"].append(member) data_type["internal_tags"][member] = info if info["data_type_name"] == "BOOL": @@ -831,7 +830,15 @@ def _parse_template_data(self, data, template): elif info["offset"] in _host_members: _bit_members[member] = ( _host_members[info["offset"]][0], - (info["bit"] + (info["offset"] * 8)), + info["bit"] + ) + elif info["offset"] in _multibyte_hosts: + _, host_offset, packet_offset = _multibyte_hosts[info["offset"]] + # adjust the bit number by the byte offset within the host member + # but use the packet offset aka host member's offset to map the bit member to the host + _bit_members[member] = ( + _host_members[packet_offset][0], + info["bit"] + 8 * host_offset, ) else: _struct_members.append((info["type_class"](member), info["offset"])) From f1e2413c904ef31e7ff23d0a1b62c326cd1668c9 Mon Sep 17 00:00:00 2001 From: ottowayi Date: Fri, 5 Nov 2021 10:30:01 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20added=20more=20tests=20for=20bo?= =?UTF-8?q?ols=20inside=20UDTs=20and=20AOIs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/online/__init__.py | 24 + tests/pycomm3.L5X | 1095 +++++++++++++++++++++++++++++++++++++- 2 files changed, 1111 insertions(+), 8 deletions(-) diff --git a/tests/online/__init__.py b/tests/online/__init__.py index 4160375..d2cbc2e 100644 --- a/tests/online/__init__.py +++ b/tests/online/__init__.py @@ -158,6 +158,17 @@ _udt3_values = {"bool1": True, "sint": 0, "dint1": -1, "bool2": False, "dint2": -1} _udt3_values_empty = {"bool1": False, "sint": 0, "dint1": 0, "bool2": False, "dint2": 0} +_udt4_values_empty = { + **{f"b{i+1}": False for i in range(16)}, + **{f"bb{i+1}": False for i in range(20)}, + "int": 0, +} +_udt4_values = { + **_udt4_values_empty, + "b4": True, + "bb20": True, +} + _str82_part = "A normal built-in string type" _str82_full = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque sodales vel." @@ -197,6 +208,12 @@ "str_ary1": ["", "", "", "", ""], "udt3": _udt3_values, "udt_ary3": [_udt3_values_empty, _udt3_values_empty, _udt3_values], + "udt4": _udt4_values, + "udt_ary4": [ + _udt4_values, + _udt4_values_empty, + {**_udt4_values_empty, "b6": True, "bb17": True}, + ], } _aoi1_values = { @@ -216,6 +233,8 @@ "str_ary1": ["", "", "", "", ""], "udt3": _udt3_values_empty, "udt_ary3": [_udt3_values_empty for _ in range(3)], + "udt4": _udt4_values_empty, + "udt_ary4": [_udt4_values_empty for _ in range(3)], }, } @@ -248,6 +267,9 @@ ("_udt3.dint1", "DINT", _udt3_values["dint1"]), ("_udt3.bool2", "BOOL", _udt3_values["bool2"]), ("_udt3.dint2", "DINT", _udt3_values["dint2"]), + ("_udt4", "pycomm3_BoolsUDT", _udt4_values), + ("_udt4.b4", "BOOL", True), + ("_udt4.bb20", "BOOL", True), # bit elements of nested udts ("_nested_udt1.udt1.sint.0", "BOOL", True), ("_nested_udt1.udt1.int.1", "BOOL", False), @@ -262,6 +284,8 @@ ("_nested_udt1.udt_ary2{5}", "pycomm3_AtomicArrayUDT[5]", _nested_udt1_values["udt_ary2"]), ("_nested_udt1.udt3", "pycomm3_PaddedUDT", _nested_udt1_values["udt3"]), ("_nested_udt1.udt_ary3{3}", "pycomm3_PaddedUDT[3]", _nested_udt1_values["udt_ary3"]), + ("_nested_udt1.udt4", "pycomm3_BoolsUDT", _nested_udt1_values["udt4"]), + ("_nested_udt1.udt_ary4{3}", "pycomm3_BoolsUDT[3]", _nested_udt1_values["udt_ary4"]), # strings ("_str1", "STRING", _str82_part), ("_str2", "STRING", ""), diff --git a/tests/pycomm3.L5X b/tests/pycomm3.L5X index d070e75..4716d59 100644 --- a/tests/pycomm3.L5X +++ b/tests/pycomm3.L5X @@ -1,5 +1,5 @@  - + @@ -19,6 +19,52 @@ + + + + @@ -64,6 +112,8 @@ + + @@ -296,6 +346,8 @@ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -1139,6 +1191,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1541,7 +1757,9 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF -00 00 00 00 FF FF FF FF +00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 @@ -2384,6 +2602,170 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2777,6 +3159,8 @@ F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -3225,6 +3609,8 @@ F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -3692,6 +4078,50 @@ D0 07 00 00 34 08 00 00 98 08 00 00 FC 08 00 00 + +00 00 00 00 00 00 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 00 00 00 00 00 00 00 00 @@ -3794,7 +4224,9 @@ D0 07 00 00 34 08 00 00 98 08 00 00 FC 08 00 00 00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF -00 00 00 00 FF FF FF FF +00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 @@ -4637,6 +5069,170 @@ D0 07 00 00 34 08 00 00 98 08 00 00 FC 08 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4749,6 +5345,50 @@ F0 0A 00 00 54 0B 00 00 + +00 00 00 00 00 00 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 64 @@ -5465,6 +6105,8 @@ F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -5955,7 +6597,9 @@ FF FF FF FF FF FF FF 7F 00 00 00 00 00 00 00 80 00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF -00 00 00 00 FF FF FF FF +00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 @@ -6798,6 +7442,170 @@ FF FF FF FF FF FF FF 7F 00 00 00 00 00 00 00 80 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -7432,6 +8240,50 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 + +00 00 00 00 00 00 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 09 00 00 00 D2 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -7529,6 +8381,8 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -8019,7 +8873,9 @@ FF FF FF FF FF FF FF 7F 00 00 00 00 00 00 00 80 00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF -00 00 00 00 FF FF FF FF +00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00 00 00 00 00 00 00 00 @@ -8862,6 +9718,170 @@ FF FF FF FF FF FF FF 7F 00 00 00 00 00 00 00 80 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -9496,6 +10516,50 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 + +00 00 00 00 00 00 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5F 00 00 00 @@ -9722,16 +10786,21 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 - + - + + + + + + @@ -9771,6 +10840,11 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 + + + + + @@ -9869,7 +10943,7 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 - + @@ -9913,6 +10987,11 @@ BD BE BF 00 00 00 00 00 00 00 00 00 00 00 00 00 + + + + + From 4be5da7131dfcb8552fbc829309416edff4a30f2 Mon Sep 17 00:00:00 2001 From: ottowayi Date: Fri, 5 Nov 2021 12:18:01 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=20release=201.2.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/releases.rst | 8 ++++++++ pycomm3/_version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/releases.rst b/docs/releases.rst index a798a71..9c2c01a 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -2,6 +2,14 @@ Release History =============== +1.2.4 +===== + +LogixDriver +----------- + +- |:bug:| fixed issue for BOOL members inside structures that was introduced as part of 1.2.3 #182 + 1.2.3 ===== diff --git a/pycomm3/_version.py b/pycomm3/_version.py index 79decd5..93db12a 100644 --- a/pycomm3/_version.py +++ b/pycomm3/_version.py @@ -22,5 +22,5 @@ # SOFTWARE. # -__version_info__ = (1, 2, 3) +__version_info__ = (1, 2, 4) __version__ = ".".join(f"{x}" for x in __version_info__)