11import asyncio
22import enum
3+ from dataclasses import dataclass
34
45import numpy as np
56
6- from fastcs .attributes import AttrHandlerW , AttrR , AttrRW , AttrW
7- from fastcs .controller import Controller , SubController , SubControllerVector
8- from fastcs .datatypes import Bool , Enum , Float , Int , Table , Waveform
7+ from fastcs .attribute_io import AttributeIO
8+ from fastcs .attribute_io_ref import AttributeIORef
9+ from fastcs .attributes import AttrR , AttrRW , AttrW
10+ from fastcs .controller import Controller , SubControllerVector
11+ from fastcs .datatypes import Bool , Enum , Float , Int , T , Table , Waveform
912from fastcs .launch import FastCS
1013from fastcs .transport .epics .options import (
1114 EpicsIOCOptions ,
1215)
13- from fastcs .transport .epics .pva .options import EpicsPVAOptions
16+ from fastcs .transport .epics .pva .transport import EpicsPVATransport
1417from fastcs .wrappers import command , scan
1518
1619
17- class SimpleAttributeSetter (AttrHandlerW ):
18- async def put (self , attr , value ):
19- await attr .update_display_without_process (value )
20+ @dataclass
21+ class SimpleAttributeIORef (AttributeIORef ):
22+ pass
23+
24+
25+ class SimpleAttributeIO (AttributeIO [T , SimpleAttributeIORef ]):
26+ async def send (self , attr : AttrW [T , SimpleAttributeIORef ], value ):
27+ if isinstance (attr , AttrRW ):
28+ await attr .update (value )
2029
2130
2231class FEnum (enum .Enum ):
@@ -29,30 +38,39 @@ class FEnum(enum.Enum):
2938
3039class ParentController (Controller ):
3140 description = "some controller"
32- a : AttrRW = AttrRW (Int (max = 400_000 , max_alarm = 40_000 ))
33- b : AttrW = AttrW (Float (min = - 1 , min_alarm = - 0.5 ), handler = SimpleAttributeSetter ())
41+ a : AttrRW = AttrRW (
42+ Int (max = 400_000 , max_alarm = 40_000 ), io_ref = SimpleAttributeIORef ()
43+ )
44+ b : AttrW = AttrW (Float (min = - 1 , min_alarm = - 0.5 ), io_ref = SimpleAttributeIORef ())
3445
3546 table : AttrRW = AttrRW (
36- Table ([("A" , np .int32 ), ("B" , "i" ), ("C" , "?" ), ("D" , np .float64 )])
47+ Table ([("A" , np .int32 ), ("B" , "i" ), ("C" , "?" ), ("D" , np .float64 )]),
48+ io_ref = SimpleAttributeIORef (),
3749 )
3850
51+ def __init__ (self , description = None , ios = None ):
52+ super ().__init__ (description , ios )
53+
3954
40- class ChildController (SubController ):
55+ class ChildController (Controller ):
4156 fail_on_next_e = True
42- c : AttrW = AttrW (Int (), handler = SimpleAttributeSetter ())
57+ c : AttrW = AttrW (Int (), io_ref = SimpleAttributeIORef ())
58+
59+ def __init__ (self , description = None , ios = None ):
60+ super ().__init__ (description , ios )
4361
4462 @command ()
4563 async def d (self ):
4664 print ("D: RUNNING" )
4765 await asyncio .sleep (0.1 )
4866 print ("D: FINISHED" )
49- await self .j .set (self .j .get () + 1 )
67+ await self .j .update (self .j .get () + 1 )
5068
51- e : AttrR = AttrR (Bool ())
69+ e : AttrR = AttrR (Bool (), io_ref = SimpleAttributeIORef () )
5270
5371 @scan (1 )
5472 async def flip_flop (self ):
55- await self .e .set (not self .e .get ())
73+ await self .e .update (not self .e .get ())
5674
5775 f : AttrRW = AttrRW (Enum (FEnum ))
5876 g : AttrRW = AttrRW (Waveform (np .int64 , shape = (3 ,)))
@@ -68,35 +86,37 @@ async def i(self):
6886 else :
6987 self .fail_on_next_e = True
7088 print ("I: FINISHED" )
71- await self .j .set (self .j .get () + 1 )
89+ await self .j .update (self .j .get () + 1 )
7290
7391 j : AttrR = AttrR (Int ())
7492
7593
7694def run (pv_prefix = "P4P_TEST_DEVICE" ):
77- p4p_options = EpicsPVAOptions (pva_ioc = EpicsIOCOptions (pv_prefix = pv_prefix ))
78- controller = ParentController ()
79- # controller.register_sub_controller(
80- # "Child1", ChildController(description="some sub controller")
81- # )
82- # controller.register_sub_controller(
83- # "Child2", ChildController(description="another sub controller")
84- # )
85-
86- class Vector (SubControllerVector ):
87- int : AttrR = AttrR (Int ())
88-
89- sub_controller = Vector (
95+ simple_attribute_io = SimpleAttributeIO ()
96+ p4p_options = EpicsPVATransport (pva_ioc = EpicsIOCOptions (pv_prefix = pv_prefix ))
97+ controller = ParentController (ios = [simple_attribute_io ])
98+
99+ class ChildVector (SubControllerVector ):
100+ vector_attribute : AttrR = AttrR (Int ())
101+
102+ def __init__ (self , children , description = None ):
103+ super ().__init__ (children , description )
104+
105+ sub_controller = ChildVector (
90106 {
91- 1 : ChildController (description = "some sub controller" ),
92- 2 : ChildController (description = "another sub controller" ),
93- }
107+ 1 : ChildController (
108+ description = "some sub controller" , ios = [simple_attribute_io ]
109+ ),
110+ 2 : ChildController (
111+ description = "another sub controller" , ios = [simple_attribute_io ]
112+ ),
113+ },
114+ description = "some child vector" ,
94115 )
95116
96- controller .register_sub_controller ("Child" , sub_controller )
117+ controller .add_sub_controller ("Child" , sub_controller )
97118
98119 fastcs = FastCS (controller , [p4p_options ])
99- fastcs .create_gui ()
100120 fastcs .run ()
101121
102122
0 commit comments