Skip to content

Commit ba10651

Browse files
committed
Fix EPICA CA string truncation
This accounts for the null terminator added when storing to the record
1 parent afcbf45 commit ba10651

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/fastcs/transports/epics/ca/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def _make_in_record(pv: str, attribute: AttrR) -> RecordWrapper:
8383
case String():
8484
record = builder.longStringIn(
8585
pv,
86-
length=attribute.datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH,
86+
length=(attribute.datatype.length + 1)
87+
if attribute.datatype.length
88+
else DEFAULT_STRING_WAVEFORM_LENGTH + 1,
8789
**common_fields,
8890
)
8991
case Enum():
@@ -157,7 +159,9 @@ def _make_out_record(pv: str, attribute: AttrW, on_update: Callable) -> RecordWr
157159
case String():
158160
record = builder.longStringOut(
159161
pv,
160-
length=attribute.datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH,
162+
length=(attribute.datatype.length + 1)
163+
if attribute.datatype.length
164+
else DEFAULT_STRING_WAVEFORM_LENGTH + 1,
161165
**common_fields,
162166
)
163167
case Enum():

tests/transports/epics/ca/test_softioc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def test_create_and_link_read_pv(mocker: MockerFixture):
7272
(
7373
AttrR(String()),
7474
"longStringIn",
75-
{"length": 256, "DESC": None, "initial_value": ""},
75+
{"length": 257, "DESC": None, "initial_value": ""},
7676
),
7777
(
7878
AttrR(Enum(ColourEnum)),

0 commit comments

Comments
 (0)