Try this:
import time, epics
def onchange(pvname, value, **kws):
print(f'Change {pvname=}, {value=}, units={kws.get(‘units', '?')}', list(kws.keys()))
mypv = epics.PV(‘calcExample', form='ctrl')
mypv.add_callback(on change)
for _ in range(10):
time.sleep(1)
# or to get the units once:
mypv = epics.PV(‘calcExample') # the 'time' form is the default
mypv.wait_for_connection()
mypv_units = mypv.get_ctrlvars().get('units', '?’)
--Matthew Newville (newville at cars.uchicago.edu)
From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Wang, Lin via Tech-talk <tech-talk at aps.anl.gov>
Date: Thursday, June 25, 2026 at 6:57 AM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: How to ensure with_ctrlvars monitor in PyEpics if PVs are initially unavailable
Dear all,
If the PV is ready, the following PyEpics code works normally and metadata is always available in callback,
import time, epics
def cb(**kw):
print("units =", kw.get("units"))
pv = epics.PV("calcExample")
pv.wait_for_connection(timeout=5)
pv.add_callback(cb, with_ctrlvars=True)
time.sleep(10)
However, it seems that if the PV is not ready at first, the with_ctrlvars parameter will not take effect. In this case, even if the PV becomes accessible later, callback can never access metadata in subsequent updates.
So the questions: if PV metadata is intended to be available in callback no matter what status the PV is when calling add_callback(), is there any workaround? Or am I missing something?
Thanks,
Lin
- References:
- How to ensure with_ctrlvars monitor in PyEpics if PVs are initially unavailable Wang, Lin via Tech-talk
- Navigate by Date:
- Prev:
Re: EPICS support for Fastech motors Mark Rivers via Tech-talk
- Next:
RE: [EXTERNAL] Re: 2026 white paper on EPICS vs commercial SCADA software Evans, Richard K. (GRC-H000) via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
<2026>
- Navigate by Thread:
- Prev:
How to ensure with_ctrlvars monitor in PyEpics if PVs are initially unavailable Wang, Lin via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
<2026>
|