From c9770ad2aa5c488fec13aa287be875b371688d46 Mon Sep 17 00:00:00 2001 From: Kaushik Malapati Date: Sat, 30 Nov 2024 19:16:04 -0800 Subject: [PATCH 1/2] String arrays generate multiple pvs instead of using WaveformRecordPackage --- pytmc/pragmas.py | 2 +- pytmc/record.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytmc/pragmas.py b/pytmc/pragmas.py index 7085e3b..d2f36cc 100644 --- a/pytmc/pragmas.py +++ b/pytmc/pragmas.py @@ -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: diff --git a/pytmc/record.py b/pytmc/record.py index caaacb4..5ff9b55 100644 --- a/pytmc/record.py +++ b/pytmc/record.py @@ -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] From ebca825ec5d4ca1b33b80ed9b7c10d21e510d9e6 Mon Sep 17 00:00:00 2001 From: Kaushik Malapati Date: Thu, 5 Dec 2024 02:01:09 -0800 Subject: [PATCH 2/2] Adding string array tests --- pytmc/tests/test_xml_collector.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pytmc/tests/test_xml_collector.py b/pytmc/tests/test_xml_collector.py index 970f31a..11272a7 100644 --- a/pytmc/tests/test_xml_collector.py +++ b/pytmc/tests/test_xml_collector.py @@ -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): @@ -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): @@ -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",