Skip to content

Commit

Permalink
Merge pull request #183 from ottowayi/develop
Browse files Browse the repository at this point in the history
1.2.4
  • Loading branch information
ottowayi authored Nov 5, 2021
2 parents e9e0ea4 + 4be5da7 commit 6448d41
Show file tree
Hide file tree
Showing 6 changed files with 1,146 additions and 28 deletions.
8 changes: 8 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====

Expand Down
2 changes: 1 addition & 1 deletion pycomm3/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
# SOFTWARE.
#

__version_info__ = (1, 2, 3)
__version_info__ = (1, 2, 4)
__version__ = ".".join(f"{x}" for x in __version_info__)
43 changes: 25 additions & 18 deletions pycomm3/logix_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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"]))
Expand Down
2 changes: 1 addition & 1 deletion pycomm3/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/online/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)],
},
}

Expand Down Expand Up @@ -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),
Expand All @@ -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", ""),
Expand Down
Loading

0 comments on commit 6448d41

Please sign in to comment.