EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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  <20212022  2023  2024  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  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Python Script call from Button press, module not found
From: "Johnson, Andrew N. via Tech-talk" <tech-talk at aps.anl.gov>
To: Matt Newville <newville at cars.uchicago.edu>
Cc: EPICS tech-talk <tech-talk at aps.anl.gov>
Date: Thu, 15 Apr 2021 17:13:52 +0000
Hi Matt,

On Apr 15, 2021, at 11:55 AM, Matt Newville <newville at cars.uchicago.edu> wrote:
> 
> On Thu, Apr 15, 2021 at 11:18 AM Johnson, Andrew N. <anj at anl.gov> wrote:
>> 
>> On Apr 15, 2021, at 10:47 AM, Matt Newville wrote:
>> > 
>> > You could just write a simple plain python script that performed some action when the PV changed by button push happened.   That can be as simple as
>> > 
>> > while True:
>> >     epics.poll(0.025)
>> >     if epics.caget('button_push'):
>> >        do_something()
>> 
>> 
>> Does pyepics use a CA monitor behind the scenes to implement that epics.caget() call? If it doesn't that example would be hitting the IOC with a get at up to 40Hz, which isn’t something I’d recommend. I’m guessing it probably does which is fine when using pyepics, but translating the above code into some other scripting language and calling the caget program from Base in a fast loop like that would not be advisable.
> 
> Yes, pyepics will (by default) set up connection and monitor callbacks on every channel it defines.  That epics.poll() is really just "ca_pend_event(0.025) ; ca_pend_io(1.0)" and should not be a resource burden.  It can also just be replaced by a Python "time.sleep(0.025)”.

After writing the above I looked at the online documentation for epics.caget() which talks about the use_monitor flag but says that it defaults to False. Has that changed? If not the simple example should probably be something like:

>> > while True:
>> >     epics.poll(0.025)
>> >     if epics.caget(‘button_push’, use_monitor=True):
>> >        do_something()



>> Just wanting to make sure readers understand if there is some magic going on there!
> 
> Yes, it is not doing piles of ca_get() at 40 Hz.  It is expecting values to be updated by callbacks running in background CA threads.
> 
> In fact, that callback on the button push PV is deliberately not doing much work besides setting a flag because that *will* be called by the CA thread (in a sense "inside pend_event"), so we set the flag in the callback and then check that in the main Python thread in the main loop.  The "real work" part, which might do other CA calls and/or complex calculations should not be done in that callback.

For your more complex example I saw that, thanks. It’s when simple examples behave badly that Michael and I get concerned, because they often get used at the start of a project and grow into more more complex things without the authors understanding what effect they’re likely to have on other parts of their control systems.

Thanks,

- Andrew


-- 
Complexity comes for free, simplicity you have to work for.


Replies:
Re: Python Script call from Button press, module not found Matt Newville via Tech-talk
References:
Python Script call from Button press, module not found Manoussakis, Adamandios via Tech-talk
Re: Python Script call from Button press, module not found Kasemir, Kay via Tech-talk
RE: Python Script call from Button press, module not found Manoussakis, Adamandios via Tech-talk
Re: Python Script call from Button press, module not found Matt Newville via Tech-talk
Re: Python Script call from Button press, module not found Johnson, Andrew N. via Tech-talk
Re: Python Script call from Button press, module not found Matt Newville via Tech-talk

Navigate by Date:
Prev: Re: Python Script call from Button press, module not found Matt Newville via Tech-talk
Next: RE: Python Script call from Button press, module not found Manoussakis, Adamandios 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  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Python Script call from Button press, module not found Matt Newville via Tech-talk
Next: Re: Python Script call from Button press, module not found Matt Newville 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  <20212022  2023  2024 
ANJ, 15 Apr 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·