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 | 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 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True) |
From: | "Marco A. Barra Montevechi Filho via Tech-talk" <tech-talk at aps.anl.gov> |
To: | Mark Rivers <rivers at cars.uchicago.edu>, Matthew Newville <newville at cars.uchicago.edu> |
Cc: | SWC <swc at lnls.br>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov> |
Date: | Tue, 17 Jan 2023 18:26:20 +0000 |
>However, if the motor record writes
multiple values to a field (and does a callback) in rapid succession you are not guaranteed to receive callbacks for all of the values. Im not sure if i understood this so i made some scripts to test. I made a script called test.py:
import epics,
sys,
time
desired_value =
sys.argv[1]
def check_value(**kwargs):
print("a")
a =
epics.Motor("MGN:B:E873A:DIAG:X:m1")
b =
epics.PV("MGN:B:E873A:DIAG:X:m1.CNEN")
b.add_callback(check_value)
a.put("CNEN",desired_value) and in my terminal: for i in {0..50}; do echo "b"; ./test.py $((1-$a)); sleep 0.1; done What i got was several "a"s and "b"s but with much more "b"s: b a
b
a
b
b
b
a
(etc...)So i supposed this is not because im not getting the callback, but because my script is terminating before i have time to receive the callback and execute the check_value function. So i added sleep(0.1) after a.put("CNEN", desired_value) and now what i get when doing for i in {0..50}; do echo "b"; ./test.py $((1-$a)); sleep 0.1; done is several "a"s and "b"s but now with more "a"s than "b"s: b a
a
b
a
a
(etc...) So im guessing i not only have time to receive the callback but im also receiving two sometimes. Is this line way of reasoning correct? Thanks in advance, Marco From: Mark Rivers <rivers at cars.uchicago.edu>
Sent: 17 January 2023 14:27 To: Marco A. Barra Montevechi Filho <marco.filho at lnls.br>; Matthew Newville <newville at cars.uchicago.edu> Cc: SWC <swc at lnls.br>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; mooney at anl.gov <mooney at anl.gov> Subject: Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True) >
Is this behavior the same with the callbacks (i mean at python level like the add_callback in the PV objects)? Is this why i sometimes get two, one or no callback from record in identical situations in a kinda unpredictable manner?
No,
I don't think that should affect callbacks. The motor record does callbacks even while it is moving.
However, if the motor record writes multiple values to a field (and does a callback) in rapid succession you are not guaranteed to receive callbacks for all of the values. There is no queuing in the Channel Access server, so you are only guaranteed to get
the last value of the field. That can explain behavior where you sometimes get a callback on an intermediate value, and sometimes you don't.
Mark
From: Marco A. Barra Montevechi Filho <marco.filho at lnls.br>
Sent: Tuesday, January 17, 2023 11:20 AM To: Mark Rivers <rivers at cars.uchicago.edu>; Matthew Newville <newville at cars.uchicago.edu> Cc: SWC <swc at lnls.br>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; mooney at anl.gov <mooney at anl.gov> Subject: Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True) That explains a lot!
Is this behavior the same with the callbacks (i mean at python level like the add_callback in the PV objects)? Is this why i sometimes get two, one or no callback from record in identical situations in a kinda unpredictable manner? If yes, what is the best way of checking the field (not the record) for updates? The best i cant think is something like: start_time=time.time() while VALUE!=desired_value: VALUE=epics.caget(BLAH) time.sleep(0.1) if time.time()-start_time>timeout: raise SomeException But this could considerably slow my scan. Is there a better way? Thanks, Marco From: Mark Rivers <rivers at cars.uchicago.edu>
Sent: 17 January 2023 14:11 To: Matthew Newville <newville at cars.uchicago.edu>; Marco A. Barra Montevechi Filho <marco.filho at lnls.br> Cc: SWC <swc at lnls.br>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; mooney at anl.gov <mooney at anl.gov> Subject: Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True) Hi Marco,
I think there may be a complication with the motor record, and other complex records like mca,
scaler, etc. Using Python put(wait=True) means you are using ca_put_callback() in the underlying Channel Access C code. ca_put_callback() completes when the record calls recGblFwdLink(). For those complex records recGblFwdLink() is called when the record
is "done". For the motor record that means that a move is complete, for the mca and scaler record it means acquisition is complete. I think this means that if a move is in progress when writing to CNEN then that write will only complete when the move is
complete, so it could take a long time.
Tim Mooney may correct me if my understanding is wrong.
Mark
From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Marco A. Barra Montevechi Filho via Tech-talk <tech-talk at aps.anl.gov>
Sent: Tuesday, January 17, 2023 10:53 AM To: Matthew Newville <newville at cars.uchicago.edu> Cc: SWC <swc at lnls.br>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True)
Thanks, Matt.
In my tests, put("CNEN",value,wait=True) returns in much less than 10 seconds, so i dont think this is the case. Something interesting: i had the same problem with VELO field so im guessing problem is with my understanding about how the IOC works in general, not an actual communication with hardware problem. Best regards, Marco From: Matt Newville <newville at cars.uchicago.edu>
Sent: 17 January 2023 13:30 To: Marco A. Barra Montevechi Filho <marco.filho at lnls.br> Cc: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; SWC <swc at lnls.br> Subject: Re: Weird behaviour in wait=True when using epics.Motor.get(something,something,wait=True) To follow up on Torsten's comment, the default timeout for a `epics.Motor.put()` is 10 seconds. The behavior you are seeing could be because the processing of setting CNEN takes more
than that 10 seconds.
Giving a longer timeout to the `put()` might clarify what is happening.
On Mon, Jan 16, 2023 at 3:27 PM Marco A. Barra Montevechi Filho via Tech-talk <tech-talk at aps.anl.gov> wrote:
|