Skip to content

Commit 01a4d0f

Browse files
authored
Merge pull request #3 from hz-b/dev/feature/fix-pc-update-rdbk
magnets, power converters: update readback if set value changes
2 parents 9e485c4 + 4aea03a commit 01a4d0f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/dt4acc/custom_epics/ioc/pv_setup.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ def initialize_magnet_pvs(builder, magnet):
4545
initial_value=magnet["k"] or 0,
4646
on_update=lambda val: handle_device_update(magnet_name, "K", val),
4747
)
48-
builder.aIn(f"{magnet_name}:Cm:rdbk", initial_value=val)
48+
rdbk = builder.aIn(f"{magnet_name}:Cm:rdbk", initial_value=val)
49+
async def handle_magnet_update(device_id: str, property_id: str, value: float):
50+
r = await handle_device_update(device_id=device_id, property_id=property_id, value=value)
51+
logger.info("%s:%s setting setpoint val=%s", device_id, property_id, value)
52+
rdbk.set(value)
53+
logger.info("%s:%s set readback val=%s", device_id, property_id,value)
54+
return r
55+
4956
builder.aOut(
5057
f"{magnet_name}:im:I",
5158
initial_value=0.0,
5259
# Todo: what to do if current is set, should be rather read only
5360
# on_update=lambda val: handle_device_update(f"{magnet_name}:im:I", val)
54-
on_update=lambda val: handle_device_update(
61+
on_update=lambda val: handle_magnet_update(
5562
magnet_name, "powersupply_current", val
5663
),
5764
)
@@ -103,13 +110,19 @@ def add_pc_pvs(builder, pc_name, prefix):
103110
DevicePropertyID(device_name=pc_name, property="set_current")
104111
)
105112
start_val = np.asarray(vals).mean()
113+
rdbk = builder.aOut(f"{pc_name}:rdbk", initial_value=start_val)
114+
async def handle_pc_update(device_id: str, property_id: str, value: float):
115+
logger.debug("%s:%s updating setpoint val=%s", device_id, property_id, value)
116+
r = await handle_device_update(device_id=device_id, property_id=property_id, value=value)
117+
logger.debug("%s:%s updating rdbk val=%s", device_id, property_id, value)
118+
rdbk.set(value)
119+
return r
120+
106121
builder.aOut(
107122
f"{pc_name}:set",
108123
initial_value=start_val,
109-
on_update=lambda val: handle_device_update(pc_name, "set_current", val),
124+
on_update=lambda val: handle_pc_update(pc_name, "set_current", val),
110125
)
111-
#: todo ensur that readback is updated
112-
builder.aOut(f"{pc_name}:rdbk", initial_value=start_val)
113126

114127

115128
def initialize_orbit_pvs(builder):

0 commit comments

Comments
 (0)