Skip to content

Commit 0954c4d

Browse files
committed
WIP - Add Waveform
1 parent b0ff1f8 commit 0954c4d

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/fastcs/datatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def initial_value(self) -> np.ndarray:
182182
return np.zeros(self.shape, dtype=self.array_dtype)
183183

184184
def validate(self, value: np.ndarray) -> np.ndarray:
185-
_value = super().validate(value)
185+
_value = super().validate(np.asarray(value).astype(self.array_dtype))
186186

187187
if self.array_dtype != _value.dtype:
188188
raise ValueError(

src/fastcs/demo/controllers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from dataclasses import KW_ONLY, dataclass
55
from typing import TypeVar
66

7+
import numpy as np
8+
79
from fastcs.attribute_io import AttributeIO
810
from fastcs.attribute_io_ref import AttributeIORef
911
from fastcs.attributes import AttrR, AttrRW, AttrW
1012
from fastcs.connections import IPConnection, IPConnectionSettings
1113
from fastcs.controller import Controller
12-
from fastcs.datatypes import Enum, Float, Int
14+
from fastcs.datatypes import Enum, Float, Int, Waveform
1315
from fastcs.wrappers import command, scan
1416

1517
NumberT = TypeVar("NumberT", int, float)
@@ -68,6 +70,7 @@ async def update(
6870
class TemperatureController(Controller):
6971
ramp_rate = AttrRW(Float(), io_ref=TemperatureControllerAttributeIORef(name="R"))
7072
power = AttrR(Float(), io_ref=TemperatureControllerAttributeIORef(name="P"))
73+
voltages = AttrR(Waveform(np.int32, shape=(4,)))
7174

7275
def __init__(self, settings: TemperatureControllerSettings) -> None:
7376
self.connection = IPConnection()
@@ -103,6 +106,9 @@ async def update_voltages(self):
103106
voltages = json.loads(
104107
(await self.connection.send_query(f"{query}\r\n")).strip("\r\n")
105108
)
109+
110+
await self.voltages.update(voltages)
111+
106112
for index, controller in enumerate(self._ramp_controllers):
107113
self.log_event(
108114
"Update voltages",

src/fastcs/transport/epics/gui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pvi._format.dls import DLSFormatter # type: ignore
22
from pvi.device import (
33
LED,
4+
ArrayTrace,
45
ButtonPanel,
56
CheckBox,
67
ComboBox,
@@ -68,7 +69,7 @@ def _get_read_widget(self, fastcs_datatype: DataType) -> ReadWidgetUnion | None:
6869
case Enum():
6970
return TextRead(format=TextFormat.string)
7071
case Waveform():
71-
return None
72+
return ArrayTrace(axis="x")
7273
case datatype:
7374
raise FastCSError(f"Unsupported type {type(datatype)}: {datatype}")
7475

src/fastcs/transport/graphql/graphql.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99

1010
from fastcs.attributes import AttrR, AttrRW, AttrW, T
1111
from fastcs.controller_api import ControllerAPI
12+
from fastcs.datatypes import Waveform
1213
from fastcs.exceptions import FastCSError
1314
from fastcs.logging import intercept_std_logger
15+
from fastcs.logging import logger as _logger
1416

1517
from .options import GraphQLServerOptions
1618

19+
logger = _logger.bind(logger_name=__name__)
20+
1721

1822
class GraphQLServer:
1923
"""A GraphQL server which handles a controller"""
@@ -60,6 +64,13 @@ def __init__(self, controller_api: ControllerAPI):
6064
def _process_attributes(self, api: ControllerAPI):
6165
"""Create queries and mutations from api attributes."""
6266
for attr_name, attribute in api.attributes.items():
67+
if isinstance(attribute.datatype, Waveform):
68+
logger.warning(
69+
"Waveform attributes are not supported in GraphQL transport",
70+
attribute=attribute,
71+
)
72+
continue
73+
6374
match attribute:
6475
# mutation for server changes https://graphql.org/learn/queries/
6576
case AttrRW():

tests/transport/epics/ca/test_gui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
from pvi.device import (
44
LED,
5+
ArrayTrace,
56
ButtonPanel,
67
ComboBox,
78
Group,
@@ -39,7 +40,7 @@ def test_get_pv(controller_api):
3940
(Float(), TextRead()),
4041
(String(), TextRead(format=TextFormat.string)),
4142
(Enum(ColourEnum), TextRead(format=TextFormat.string)),
42-
# (Waveform(array_dtype=np.int32), None),
43+
(Waveform(array_dtype=np.int32), ArrayTrace(axis="x")),
4344
],
4445
)
4546
def test_get_attribute_component_r(datatype, widget, controller_api):

0 commit comments

Comments
 (0)