Skip to content

Commit 48c688d

Browse files
authored
Fix EpicsCATransport to pass length with initial_value for string records (#262)
softioc sets the length of the initial value as the max length, so it can never be set if it is empty initially. Override with the driver set length or 256 by default.
1 parent 77a720d commit 48c688d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/fastcs/datatypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def initial_value(self) -> bool:
128128
class String(DataType[str]):
129129
"""`DataType` mapping to builtin ``str``."""
130130

131+
length: int | None = None
132+
"""Maximum length of string to display in transports"""
133+
131134
@property
132135
def dtype(self) -> type[str]:
133136
return str

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
EPICS_ALLOWED_DATATYPES = (Bool, DataType, Enum, Float, Int, String, Waveform)
35-
EPICS_WAVEFORM_LENGTH = 256
35+
DEFAULT_STRING_WAVEFORM_LENGTH = 256
3636

3737
DATATYPE_FIELD_TO_RECORD_FIELD = {
3838
"prec": "PREC",
@@ -79,6 +79,8 @@ def record_metadata_from_datatype(
7979
arguments.pop("DRVH", None)
8080

8181
match datatype:
82+
case String():
83+
arguments["length"] = datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH
8284
case Waveform():
8385
if len(datatype.shape) != 1:
8486
raise TypeError(
@@ -138,8 +140,8 @@ def cast_to_epics_type(datatype: DataType[T], value: T) -> Any:
138140
return datatype.index_of(datatype.validate(value))
139141
else: # enum backed by string record
140142
return datatype.validate(value).name
141-
case String():
142-
return value[: EPICS_WAVEFORM_LENGTH - 1]
143+
case String() as string:
144+
return value[: string.length]
143145
case datatype if issubclass(type(datatype), EPICS_ALLOWED_DATATYPES):
144146
return value
145147
case _:

0 commit comments

Comments
 (0)