EPICS Home

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  <20192020  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  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: pyepics callback
From: Matt Newville via Tech-talk <[email protected]>
To: Alfio Rizzo <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Mon, 9 Sep 2019 10:50:21 -0500
Hi Alfio,



On Mon, Sep 9, 2019 at 10:08 AM Alfio Rizzo via Tech-talk <[email protected]> wrote:

Hi

I made a simple python script to get the updated value of my PV

with a simple callback function :

 

import epics

import time

 

def onChanges(**kw):

    print ('PV Changed! ', kw["pvname"], kw["value"], kw["units"], time.ctime())

 

mypv = epics.PV("TCU6:RF")

mypv.add_callback(onChanges)

 

while True:

    pass

   

 

The issue is that the unit is shown as None even if it defined in the .db

 

PV Changed!  TCU6:RF -39.69 None Mon Sep  9 15:03:58 2019

PV Changed!  TCU6:RF -39.73 None Mon Sep  9 15:03:59 2019

PV Changed!  TCU6:RF -39.71 None Mon Sep  9 15:04:00 2019

PV Changed!  TCU6:RF -39.7 None Mon Sep  9 15:04:01 2019

PV Changed!  TCU6:RF -39.67 None Mon Sep  9 15:04:02 2019

 

 

But if I add this line on the script before to add the callback

 

……

mypv.units

mypv.add_callback(onChanges)

……

 

Then when I restart the script it shows the unit correctly

 

 

PV Changed!  TCU6:RF -39.79 dBm Mon Sep  9 15:04:31 2019

PV Changed!  TCU6:RF -39.71 dBm Mon Sep  9 15:04:32 2019

PV Changed!  TCU6:RF -39.69 dBm Mon Sep  9 15:04:33 2019

 

 

Is this a bug/feature or I am doing something wrong ?


Hm, I think this is mostly a timing issue, but we could try to make this better.  Basically, in the first variation, the PV never asked for its CTRL fields, so it does not know what they are.  When you ask for the units (or any other CTRL fields), it goes and fetches all of them (once) and includes those in the monitor callback.

So doing 

    mypv = epics.PV(pvname)
    mypv.get_ctrlvars()
    mypyv.add_callback(onChanges)

is probably the best way to get the units into your callback. 

If you expect that the units might actually change, you should create the PV with `form='ctrl'` as Eric suggested. 

Hope that helps,

--Matt

PNG image


References:
pyepics callback Alfio Rizzo via Tech-talk

Navigate by Date:
Prev: Re: use CA Client in Xilinx MicroBlaze system Johnson, Andrew N. via Tech-talk
Next: Driver for Smargon gniometer Randall Cayford 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  <20192020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: pyepics callback Eric Norum via Tech-talk
Next: Driver for Smargon gniometer Randall Cayford 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  <20192020  2021  2022  2023  2024