Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/fastcs/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def initial_value(self) -> bool:
class String(DataType[str]):
"""`DataType` mapping to builtin ``str``."""

length: int | None = None
"""Maximum length of string to display in transports"""

@property
def dtype(self) -> type[str]:
return str
Expand Down
8 changes: 5 additions & 3 deletions src/fastcs/transport/epics/ca/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


EPICS_ALLOWED_DATATYPES = (Bool, DataType, Enum, Float, Int, String, Waveform)
EPICS_WAVEFORM_LENGTH = 256
DEFAULT_STRING_WAVEFORM_LENGTH = 256

DATATYPE_FIELD_TO_RECORD_FIELD = {
"prec": "PREC",
Expand Down Expand Up @@ -79,6 +79,8 @@ def record_metadata_from_datatype(
arguments.pop("DRVH", None)

match datatype:
case String():
arguments["length"] = datatype.length or DEFAULT_STRING_WAVEFORM_LENGTH
case Waveform():
if len(datatype.shape) != 1:
raise TypeError(
Expand Down Expand Up @@ -138,8 +140,8 @@ def cast_to_epics_type(datatype: DataType[T], value: T) -> Any:
return datatype.index_of(datatype.validate(value))
else: # enum backed by string record
return datatype.validate(value).name
case String():
return value[: EPICS_WAVEFORM_LENGTH - 1]
case String() as string:
return value[: string.length]
case datatype if issubclass(type(datatype), EPICS_ALLOWED_DATATYPES):
return value
case _:
Expand Down