Skip to content

Commit

Permalink
feat: Improve the structure of the model to more closely match am L5X…
Browse files Browse the repository at this point in the history
… file.
  • Loading branch information
hutcheb committed Jul 7, 2024
1 parent d0aaa95 commit df86656
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
30 changes: 18 additions & 12 deletions acd/l5x/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ def to_xml(self):
if isinstance(attribute_value, L5xElement):
child_list.append(attribute_value.to_xml())
elif isinstance(attribute_value, list):
pass
#for element in attribute_value:
# if isinstance(element, L5xElement):
# child_list.append(element.to_xml())
# else:
# child_list.append(f"<{element}/>")
if attribute == "tags":
new_child_list: List[str] = []
for element in attribute_value:
if isinstance(element, L5xElement):
new_child_list.append(element.to_xml())
else:
new_child_list.append(f"<{element}/>")
child_list.append(f'<{attribute.title().replace("_", "")}>{" ".join(new_child_list)}</{attribute.title().replace("_", "")}>')

else:
attribute_list.append(f'{attribute.title().replace("_", "")}="{attribute_value}"')

Expand All @@ -60,9 +63,12 @@ class DataType(L5xElement):
@dataclass
class Tag(L5xElement):
name: str
data_table_instance: int
tag_type: str
data_type: str
comments: List[Tuple[str, str]]
radix: str
external_access: str
_data_table_instance: int
_comments: List[Tuple[str, str]]


@dataclass
Expand Down Expand Up @@ -204,12 +210,12 @@ def build(self) -> Tag:
try:
r = RxGeneric.from_bytes(results[0][3])
except Exception as e:
return Tag(results[0][0], results[0][0], 0, "", [])
return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", 0, [])

if r.cip_type != 0x6B:
return Tag(results[0][0], results[0][0], 0, "", [])
return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", 0, [])
if r.main_record.data_type == 0xFFFFFFFF:
return Tag(results[0][0], results[0][0], r.main_record.data_table_instance, "", [])
return Tag(results[0][0], results[0][0], "Base", "", "Decimal", "None", r.main_record.data_table_instance, [])

self._cur.execute(
"SELECT comp_name, object_id, parent_id, record FROM comps WHERE object_id=" + str(
Expand All @@ -236,7 +242,7 @@ def build(self) -> Tag:
data_type = data_type + "[" + str(r.main_record.dimension_2) + "]"
if r.main_record.dimension_3 != 0:
data_type = data_type + "[" + str(r.main_record.dimension_3) + "]"
return Tag(name, name, r.main_record.data_table_instance, data_type, comment_results)
return Tag(name, name, "Base", data_type, "Decimal", "Read/Write", r.main_record.data_table_instance, comment_results)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(self):

setup(
name="acd-tools",
version="0.2a3",
version="0.2a4",
description="Rockwell ACD File Tools",
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
3 changes: 2 additions & 1 deletion test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def manual_test_to_xml():
ss = project.to_xml()
element = ET.XML(ss)
ET.indent(element)
print(ET.tostring(element, encoding='unicode'))
with open(os.path.join("build", "CuteLogix.L5X"), "w") as out_file:
out_file.write(ET.tostring(element, encoding='unicode'))

0 comments on commit df86656

Please sign in to comment.