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

Subject: Re: Problem concerning callback function on multiple channels by using Cachannel
From: Matt Newville <[email protected]>
To: lzf neu <[email protected]>
Cc: EPICS Tech Talk <[email protected]>
Date: Thu, 19 Jul 2018 10:54:06 -0500
Hi Zhefu,


I realize you did not ask about using pyepics, but having different callbacks with different PVs definitely works with pyepics.  I think your example would translate to


from

​ ​
epics import PV

class myDriver(Driver):
    def __init__(self):
        Driver.__init__(self)
        self.chan_left =
​ ​
PV
('caLab:okok_left'
, callback=
 self.value_callback_left)
        self.chan_right =
​ ​
PV
('caLab:okok_right'
, callback=
self.value_callback_right)

    def value_callback_left(self,
name=None, value=None, **kws
):
        value_left=
value

        print "monitor caLab:okok_left"


    def value_callback_right(self, 
name=None, value=None, **kws):

        value_right=
value

        print "monitor caLab:okok_right"


if __name__ == '__main__':
    server = SimpleServer()
    server.createPV(prefix, pvdb)
    driver = myDriver()
    while True:
        server.process(0.1)

That assumes that "server.process(0.1)"  is not blocking I/O by, for example, having a 'time.sleep()' or a call to "ca_pend_event()' somewhere.  I would imagine this situation is similar for CaChannel, though you might want to make sure it is set up for asynchronous Channel Access.   

It also assumes that the channels really connect -- you might want to double check that.
Hope that helps,

--Matt



On Thu, Jul 19, 2018 at 9:45 AM lzf neu <[email protected]> wrote:

Dear Dr. Wang and all, 


I have a problem concerning Cachannel to consult you please.


The manual says:

CaChannel.add_masked_array_event(...) can specify a callback function to be executed whenever changes occur to a PV.


For example, I have two PVs, one is 'caLab:okok_left', another one is 'caLab:okok_right', their values change continuously, I try to write the following codes to monitor them:


from CaChannel import ca, CaChannel

class myDriver(Driver):

    def __init__(self):
        Driver.__init__(self)
        self.chan_left = CaChannel('caLab:okok_left')  
        self.chan_left.searchw()
        self.chan_left.add_masked_array_event(None, None, None, self.value_callback_left)
        self.chan_right = CaChannel('caLab:okok_right')  
        self.chan_right.searchw()
        self.chan_right.add_masked_array_event(None, None, None, self.value_callback_right)

    def value_callback_left(self, epics_args_left, user_args_left):
        value_left=epics_args_left['pv_value']
        print "monitor caLab:okok_left"


    def value_callback_right(self, epics_args_right, user_args_right):
        value_right=epics_args_right['pv_value']

        print "monitor caLab:okok_right"


if __name__ == '__main__':
    server = SimpleServer()
    server.createPV(prefix, pvdb)
    driver = myDriver()
    while True:
        server.process(0.1)

However, It seems only the first PV('caLab:okok_left') is running and value_callback_left function works, the second one is blocked.

I looked up the manual and know the following codes can perform the search request at once, but I have no idea how to write the callback function for each PVs at once.:


from CaChannel import ca, CaChannel
chans = {pvname: CaChannel(pvname) for pvname in ['pv1', 'pv2', 'pv3', ...]}
for chan in chans.values():
chan.search()

Therefore, if I have two PVs or multiple PVs, how to specify callback function on two or multiple PVs at once.

Any help will be appreciated and could you please show me an example, thank you very much.


Zhefu





References:
Problem concerning callback function on multiple channels by using Cachannel lzf neu

Navigate by Date:
Prev: Problem concerning callback function on multiple channels by using Cachannel lzf neu
Next: Re: Problem concerning callback function on multiple channels by using Cachannel Wang Xiaoqiang (PSI)
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  <20182019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Problem concerning callback function on multiple channels by using Cachannel lzf neu
Next: Re: Problem concerning callback function on multiple channels by using Cachannel Wang Xiaoqiang (PSI)
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  <20182019  2020  2021  2022  2023  2024 
ANJ, 19 Jul 2018 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·