On Thu, Apr 15, 2021 at 12:13 PM Johnson, Andrew N. <
anj at anl.gov> wrote:
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()
Yes, you are correct that the simple "caget()" function does issue a full ca_get() by default, not relying on monitor callbacks. We definitely encourage people to create python PV objects as these are monitored for both value changes and connection events, and can get at control values such as enumeration strings when needed.
I know we changed the "caget()" function from relying on monitors by default to issuing a full ca_get() by default awhile back. If this is known to be causing too much network traffic, I think it would be reasonable to consider changing that back to "use monitors by default".
>> Just wanting to make sure readers understand if there is some magic going on there!
Yes, good point. I highly recommend that long-running processes really use "epics.PV()".