Skip to content

Commit

Permalink
Merge pull request #12 from DiamondLightSource/string-datatype
Browse files Browse the repository at this point in the history
String DataType
  • Loading branch information
GDYendell authored Nov 6, 2023
2 parents 00f04e1 + f804e8a commit f5dec71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/fastcs/backends/epics/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
SignalRW,
SignalW,
SignalX,
TextFormat,
TextRead,
TextWrite,
Tree,
WriteWidget,
)

from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
from fastcs.datatypes import Bool, DataType, Float, Int
from fastcs.datatypes import Bool, DataType, Float, Int, String
from fastcs.exceptions import FastCSException
from fastcs.mapping import Mapping

Expand Down Expand Up @@ -62,6 +63,8 @@ def _get_read_widget(datatype: DataType) -> ReadWidget:
return LED()
case Int() | Float():
return TextRead()
case String():
return TextRead(format=TextFormat.string)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand All @@ -72,6 +75,8 @@ def _get_write_widget(datatype: DataType) -> WriteWidget:
return CheckBox()
case Int() | Float():
return TextWrite()
case String():
return TextWrite(format=TextFormat.string)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down
8 changes: 7 additions & 1 deletion src/fastcs/backends/epics/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fastcs.attributes import AttrR, AttrRW, AttrW
from fastcs.backend import Backend
from fastcs.datatypes import Bool, DataType, Float, Int
from fastcs.datatypes import Bool, DataType, Float, Int, String
from fastcs.exceptions import FastCSException
from fastcs.mapping import Mapping

Expand All @@ -25,6 +25,8 @@ def _get_input_record(pv_name: str, datatype: DataType) -> RecordWrapper:
return builder.longIn(pv_name)
case Float(prec):
return builder.aIn(pv_name, PREC=prec)
case String():
return builder.longStringIn(pv_name)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down Expand Up @@ -54,6 +56,10 @@ def _get_output_record(pv_name: str, datatype: DataType, on_update: Callable) ->
return builder.aOut(
pv_name, always_update=True, on_update=on_update, PREC=prec
)
case String():
return builder.longStringOut(
pv_name, always_update=True, on_update=on_update
)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down
9 changes: 8 additions & 1 deletion src/fastcs/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from typing import Awaitable, Callable, Generic, TypeVar

T = TypeVar("T", int, float, bool)
T = TypeVar("T", int, float, bool, str)
ATTRIBUTE_TYPES: tuple[type] = T.__constraints__ # type: ignore


Expand Down Expand Up @@ -42,3 +42,10 @@ class Bool(DataType[bool]):
@property
def dtype(self) -> type[bool]:
return bool


@dataclass(frozen=True)
class String(DataType[str]):
@property
def dtype(self) -> type[str]:
return str

0 comments on commit f5dec71

Please sign in to comment.