From 68cadb51fa627b6130f2188979991bee91a60e79 Mon Sep 17 00:00:00 2001 From: Gary Yendell Date: Thu, 12 Mar 2026 10:21:55 +0000 Subject: [PATCH] Fix EPICA CA string truncation This accounts for the null terminator added when storing to the record --- src/fastcs/transports/epics/ca/util.py | 8 ++++++-- tests/transports/epics/ca/test_softioc.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/fastcs/transports/epics/ca/util.py b/src/fastcs/transports/epics/ca/util.py index 7a7b8347..b5892a47 100644 --- a/src/fastcs/transports/epics/ca/util.py +++ b/src/fastcs/transports/epics/ca/util.py @@ -83,7 +83,9 @@ def _make_in_record(pv: str, attribute: AttrR) -> RecordWrapper: case String(): record = builder.longStringIn( pv, - length=attribute.datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH, + length=(attribute.datatype.length + 1) + if attribute.datatype.length + else DEFAULT_STRING_WAVEFORM_LENGTH + 1, **common_fields, ) case Enum(): @@ -157,7 +159,9 @@ def _make_out_record(pv: str, attribute: AttrW, on_update: Callable) -> RecordWr case String(): record = builder.longStringOut( pv, - length=attribute.datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH, + length=(attribute.datatype.length + 1) + if attribute.datatype.length + else DEFAULT_STRING_WAVEFORM_LENGTH + 1, **common_fields, ) case Enum(): diff --git a/tests/transports/epics/ca/test_softioc.py b/tests/transports/epics/ca/test_softioc.py index 0bf571d3..d695abab 100644 --- a/tests/transports/epics/ca/test_softioc.py +++ b/tests/transports/epics/ca/test_softioc.py @@ -72,7 +72,12 @@ async def test_create_and_link_read_pv(mocker: MockerFixture): ( AttrR(String()), "longStringIn", - {"length": 256, "DESC": None, "initial_value": ""}, + {"length": 257, "DESC": None, "initial_value": ""}, + ), + ( + AttrR(String(length=10)), + "longStringIn", + {"length": 11, "DESC": None, "initial_value": ""}, ), ( AttrR(Enum(ColourEnum)), @@ -197,6 +202,16 @@ class LongEnum(enum.Enum): "initial_value": 0, }, ), + ( + AttrW(String()), + "longStringOut", + {"length": 257, "DESC": None, "initial_value": ""}, + ), + ( + AttrW(String(length=10)), + "longStringOut", + {"length": 11, "DESC": None, "initial_value": ""}, + ), ), ) def test_make_output_record(