Skip to content

Commit

Permalink
Merge pull request #332 from KaushikMalapati/stringarray
Browse files Browse the repository at this point in the history
Support for arrays of strings
  • Loading branch information
ZLLentz authored Dec 5, 2024
2 parents 5c65a06 + a2dd7d3 commit 626f312
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pytmc/pragmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def get_all_options(subitems, handler, pragmas):
return []

if item.array_info and (
item.data_type.is_complex_type or item.data_type.is_enum
item.data_type.is_complex_type or item.data_type.is_enum or item.data_type.is_string
):
options = get_all_options(subitems, handle_array_complex, pragmas)
else:
Expand Down
4 changes: 2 additions & 2 deletions pytmc/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ def from_chain(*args, chain, **kwargs):
spec = RecordPackage
elif data_type.is_enum:
spec = EnumRecordPackage
elif data_type.is_array or chain.last.array_info:
spec = WaveformRecordPackage
elif data_type.is_string:
spec = StringRecordPackage
elif data_type.is_array or chain.last.array_info:
spec = WaveformRecordPackage
else:
try:
spec = DATA_TYPES[data_type.name]
Expand Down
30 changes: 30 additions & 0 deletions pytmc/tests/test_xml_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def chain():
("LREAL", False, FloatRecordPackage),
("LREAL", True, WaveformRecordPackage),
("STRING", False, StringRecordPackage),
("STRING", True, StringRecordPackage),
],
)
def test_record_package_from_chain(chain, tc_type, is_array, final_type, monkeypatch):
Expand Down Expand Up @@ -144,6 +145,8 @@ def test_record_package_from_chain(chain, tc_type, is_array, final_type, monkeyp
("ENUM", "io", True, "asynInt16ArrayOut"),
("STRING", "i", False, "asynInt8ArrayIn"),
("STRING", "io", False, "asynInt8ArrayOut"),
("STRING", "i", True, "asynInt8ArrayIn"),
("STRING", "io", True, "asynInt8ArrayOut"),
],
)
def test_dtype(chain, tc_type, io, is_array, final_DTYP):
Expand Down Expand Up @@ -606,6 +609,33 @@ def test_enum_array():
assert enum01.field_defaults["ONST"] == "TWO"


def test_string_array():
array = make_mock_twincatitem(
name="Main.string_array",
data_type=make_mock_type("MY_STRING", is_string=True),
pragma="pv: STRINGS",
array_info=(2, 5),
)

records = {
record.pvname: record for record in pragmas.record_packages_from_symbol(array)
}

assert set(records) == {
"STRINGS:02",
"STRINGS:03",
"STRINGS:04",
"STRINGS:05",
}

print(records)
string02 = records["STRINGS:02"]
assert isinstance(string02, StringRecordPackage)
assert string02.field_defaults["FTVL"] == "CHAR"
assert string02.field_defaults["APST"] == "On Change"
assert string02.field_defaults["MPST"] == "On Change"


def test_unroll_formatting():
array = make_mock_twincatitem(
name="Main.enum_array",
Expand Down

0 comments on commit 626f312

Please sign in to comment.