pcdshub / pytmc

Generate EPICS IOCs and records from TwinCAT projects - along with many TwinCAT project tools
https://pcdshub.github.io/pytmc/
Other
9 stars 9 forks source link

Add support for arrays of strings #327

Open ZLLentz opened 2 weeks ago

ZLLentz commented 2 weeks ago

Currently, if you place a pytmc pragma on an array of strings, it will error out with:

ERROR:pytmc.bin.template:Failed to create EPICS records
Traceback (most recent call last):
File "c:\repos\pytmc\pytmc\bin\template.py", line 374, in get_plc_record_packages
packages, exceptions = db_process(
File "c:\repos\pytmc\pytmc\bin\db.py", line 154, in process
record_names = [
File "c:\repos\pytmc\pytmc\bin\db.py", line 158, in
for single_record in record_package.records
File "c:\repos\pytmc\pytmc\record.py", line 619, in records
records = [self.generate_input_record()]
File "c:\repos\pytmc\pytmc\record.py", line 955, in generate_input_record
record = super().generate_input_record()
File "c:\repos\pytmc\pytmc\record.py", line 511, in generate_input_record
record.fields["DTYP"] = self.dtyp
File "c:\repos\pytmc\pytmc\record.py", line 952, in dtyp
return data_types[self.chain.data_type.name]
KeyError: 'STRING'

This is because it is entering the WaveformRecordPackage and trying to create a waveforms of strings, which is intentionally not supported.

However, it would be better if these were handled more like arrays of structs and created a separate string PV for each array element.

See the option assembly code at https://github.com/pcdshub/pytmc/blob/2c4f4121cd109d2d2cee9bdcc357d792ddca01f7/pytmc/pragmas.py#L322-L327 for how this is handled for structured arrays.

ZLLentz commented 2 weeks ago

This came up while discussing https://github.com/pcdshub/lcls-twincat-sample-delivery/pull/2