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