Skip to content

Commit 20bac0b

Browse files
committed
Various fixes from the PR
1 parent c13d7aa commit 20bac0b

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/pandablocks_ioc/_tables.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ def __init__(
308308
value,
309309
)
310310

311-
putorder_index = 1
312-
313-
for field_name, field_record_container in self.table_fields_records.items():
311+
for i, (field_name, field_record_container) in enumerate(
312+
self.table_fields_records.items()
313+
):
314314
field_details = field_record_container.field
315315

316316
full_name = table_name + ":" + field_name
@@ -333,14 +333,14 @@ def __init__(
333333
field_pva_info = {
334334
"+type": "plain",
335335
"+channel": "VAL",
336-
"+putorder": putorder_index,
336+
"+putorder": i + 1,
337337
"+trigger": "",
338338
}
339339

340340
pva_info = {f"value.{field_name.lower()}": field_pva_info}
341341

342342
# For the last column in the table
343-
if putorder_index == len(self.table_fields_records):
343+
if i == len(self.table_fields_records) - 1:
344344
# Trigger a monitor update
345345
field_pva_info["+trigger"] = "*"
346346
# Add metadata
@@ -351,8 +351,6 @@ def __init__(
351351
{pva_table_name: pva_info},
352352
)
353353

354-
putorder_index += 1
355-
356354
field_record_container.record_info = RecordInfo(lambda x: x, None, False)
357355

358356
field_record_container.record_info.add_record(field_record)
@@ -456,7 +454,9 @@ def __init__(
456454
OUT=PP(mode_record),
457455
)
458456
# Edit mode done first, Submit mode done last
459-
putorder = 0 if action == TableModeEnum.EDIT else putorder_index
457+
putorder = (
458+
0 if action == TableModeEnum.EDIT else len(self.table_fields_records)
459+
)
460460
action_record.add_info(
461461
"Q:group",
462462
{

src/pandablocks_ioc/_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def device_and_record_to_panda_name(field_name: EpicsName) -> PandAName:
3939
convention."""
4040

4141
if field_name.endswith(":LABEL"):
42-
# Device is a metadata_label field
42+
# Field is the label for the block, which is stored in the special
43+
# *METADATA area
4344

4445
block_name = field_name.split(":")[-2]
4546
if not block_name[-1].isdigit():

src/pandablocks_ioc/ioc.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def _create_softioc(
9595
except OSError:
9696
logging.exception("Unable to connect to PandA")
9797
raise
98-
(all_records, all_values_dict, panda_dict) = await create_records(
98+
(all_records, all_values_dict, block_info_dict) = await create_records(
9999
client, dispatcher, record_prefix
100100
)
101101

@@ -104,7 +104,7 @@ async def _create_softioc(
104104
raise RuntimeError("Unexpected state - softioc task already exists")
105105

106106
create_softioc_task = asyncio.create_task(
107-
update(client, all_records, 0.1, all_values_dict, panda_dict)
107+
update(client, all_records, 0.1, all_values_dict, block_info_dict)
108108
)
109109

110110
create_softioc_task.add_done_callback(_when_finished)
@@ -188,13 +188,13 @@ async def introspect_panda(
188188

189189

190190
def _create_dicts_from_changes(
191-
changes: Changes, block_info: Dict[str, BlockInfo]
191+
changes: Changes, block_info_dict: Dict[str, BlockInfo]
192192
) -> Tuple[Dict[str, Dict[EpicsName, RecordValue]], Dict[EpicsName, RecordValue]]:
193193
"""Take the `Changes` object and convert it into two dictionaries.
194194
195195
Args:
196196
changes: The `Changes` object as returned by `GetChanges`
197-
block_info: Information from the initial `GetBlockInfo` request,
197+
block_info_dict: Information from the initial `GetBlockInfo` request,
198198
used to check the `number` of blocks for parsing metadata
199199
200200
Returns:
@@ -222,10 +222,10 @@ def _store_values(
222222
"LABEL_"
223223
):
224224
_, block_name_number = field_name.split("_", maxsplit=1)
225-
if block_name_number in block_info:
226-
number_of_blocks = block_info[block_name_number].number
225+
if block_name_number in block_info_dict:
226+
number_of_blocks = block_info_dict[block_name_number].number
227227
else:
228-
number_of_blocks = block_info[block_name_number[:-1]].number
228+
number_of_blocks = block_info_dict[block_name_number[:-1]].number
229229

230230
# The block is fixed with metadata
231231
# "*METADATA.LABEL_SEQ2": "NewSeqMetadataLabel",
@@ -1694,7 +1694,7 @@ def create_block_records(
16941694

16951695
# The record uses the default _RecordUpdater.update to update the value
16961696
# on the panda
1697-
record_dict[key] = self._create_record_info(
1697+
record_dict[EpicsName(key)] = self._create_record_info(
16981698
key,
16991699
None,
17001700
builder.longStringOut,
@@ -1741,7 +1741,7 @@ async def create_records(
17411741
EpicsName,
17421742
RecordValue,
17431743
],
1744-
Dict[str, _BlockAndFieldInfo],
1744+
Dict[str, BlockInfo],
17451745
]:
17461746
"""Query the PandA and create the relevant records based on the information
17471747
returned"""
@@ -1816,15 +1816,16 @@ async def create_records(
18161816

18171817
record_factory.initialise(dispatcher)
18181818

1819-
return (all_records, all_values_dict, panda_dict)
1819+
block_info_dict = {key: value.block_info for key, value in panda_dict.items()}
1820+
return (all_records, all_values_dict, block_info_dict)
18201821

18211822

18221823
async def update(
18231824
client: AsyncioClient,
18241825
all_records: Dict[EpicsName, RecordInfo],
18251826
poll_period: float,
18261827
all_values_dict: Dict[EpicsName, RecordValue],
1827-
block_info: Dict[str, BlockInfo],
1828+
block_info_dict: Dict[str, BlockInfo],
18281829
):
18291830
"""Query the PandA at regular intervals for any changed fields, and update
18301831
the records accordingly
@@ -1867,7 +1868,9 @@ async def update(
18671868
# Clear any alarm state as we've received a new update from PandA
18681869
set_all_records_severity(all_records, alarm.NO_ALARM, alarm.UDF_ALARM)
18691870

1870-
_, new_all_values_dict = _create_dicts_from_changes(changes, block_info)
1871+
_, new_all_values_dict = _create_dicts_from_changes(
1872+
changes, block_info_dict
1873+
)
18711874

18721875
# Apply the new values to the existing dict, so various updater classes
18731876
# will have access to the latest values.

0 commit comments

Comments
 (0)