Experimental Physics and Industrial Control System
Hi Zhefu,
Your code almost works. You only need to add a call to “self.chan_right.flush_io()” at the end so that the subscription is sent to the IOC.
Best
Xiaoqiang
> On 19 Jul 2018, at 16:45, 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:
Re: Problem concerning callback function on multiple channels by using Cachannel Matt Newville
- Next:
Base R3.14.12.8-rc1 Published Andrew Johnson
- 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
- Navigate by Thread:
- Prev:
Re: Problem concerning callback function on multiple channels by using Cachannel Matt Newville
- 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
<2018>
2019
2020
2021
2022
2023
2024