Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for arrays of strings #332

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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