modified cycafe callbacks

This commit is contained in:
2021-06-15 16:18:13 +02:00
parent eaf1167a81
commit 22f3cfa655
14 changed files with 45296 additions and 34142 deletions
+14871 -17332
View File
File diff suppressed because it is too large Load Diff
-8
View File
@@ -24,16 +24,8 @@ __PYX_EXTERN_C void cy_ctrl_event_handler_wrapper(void *, unsigned int, std::str
__PYX_EXTERN_C void cy_event_handler_wrapper(void *, unsigned int, std::string);
__PYX_EXTERN_C void cy_handle_handler_wrapper(void *, unsigned int);
__PYX_EXTERN_C void cy_connect_handler_wrapper(void *, unsigned int, std::string, int);
__PYX_EXTERN_C void py_cb_wrapper(PVDataHolder, unsigned int, std::string);
__PYX_EXTERN_C void py_cb_ctrl_wrapper(PVCtrlHolder, unsigned int, std::string);
__PYX_EXTERN_C void py_cb_handle_wrapper(unsigned int);
__PYX_EXTERN_C void py_cb_handle_monid_wrapper(unsigned int, unsigned long);
__PYX_EXTERN_C void cy_cb_handle_get_wrapper(void *, unsigned int);
__PYX_EXTERN_C void py_cb_handle_get_wrapper(unsigned int);
__PYX_EXTERN_C void cy_cb_handle_put_wrapper(void *, unsigned int);
__PYX_EXTERN_C void py_cb_handle_put_wrapper(unsigned int);
__PYX_EXTERN_C void py_cb_handle_open_wrapper(unsigned int, int);
__PYX_EXTERN_C void py_cb_handle_connect_wrapper(unsigned int, std::string, int);
#endif /* !__PYX_HAVE_API__PyCafe */
+14490 -15115
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -7,7 +7,6 @@ cdef int PYCAFE_PRINT_NONE = 0
cdef int PYCAFE_PRINT_LEVEL = PYCAFE_PRINT_NONE
#ctypedef shared_ptr[vector[double]] vdouble_ptr
#ctypedef shared_ptr[vector[float]] vfloat_ptr
+148 -1262
View File
File diff suppressed because it is too large Load Diff
+10 -180
View File
@@ -20,12 +20,10 @@ cdef public void cy_data_event_handler_wrapper(void * callback,
string pvname,
PVDataHolder pvd) with gil:
global py_cb
global py_cb
#print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(1)= Handle/PVNAME :", handle, pvname)
cdef pvdata data = PVDataHolderToStruct(pvd)
#data.show()
#data.show()
py_cb = <object>(<void *> callback)
#print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(2)= Handle/PVNAME :", handle, pvname)
cdef HandleHelper hh
@@ -34,42 +32,10 @@ cdef public void cy_data_event_handler_wrapper(void * callback,
#monDictGlobal[mpid](handle, pvname, data)
<object>py_cb(handle, pvname, data)
if monDictGlobal[mpid] != <object>py_cb:
print( monDictGlobal[mpid])
print( <object>py_cb)
'''
if pvname == b"SARCL01-MQUA100:I-READ":
data.show()
print(pvname, handle)
if hmd is not None:
for cbobjt, v in hmd.items():
if v == handle:
#print("fire")
if pvname == b"SARCL01-MQUA100:I-READ":
print("handle", v, "cbobjt", cbobjt)
#####cbobjt(handle, pvname, data)
monDictGlobal[mpid](handle,pvname,data)
#print("fired")
'''
'''
global handleMonDictGlobal
if handleMonDictGlobal is not None:
for cbobjt, v in handleMonDictGlobal.items():
print("handle", v, "cbobjt", cbobjt)
if v == handle:
cbobjt(handle, pvname, data)
'''
'''
if callback:
cbobjt=<object> (<void *> callback)
print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(3)= Handle/PVNAME :", handle, pvname)
cbobjt(handle, pvname, data)
print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(4)= Handle/PVNAME :", handle, pvname)
'''
#if monDictGlobal[mpid] != <object>py_cb:
# print( monDictGlobal[mpid])
# print( <object>py_cb)
with nogil:
return
@@ -86,7 +52,7 @@ cdef public void cy_ctrl_event_handler_wrapper(void * callback,
with nogil:
return
#cdef public void cy_event_handler_wrapper(void *callback, int *args, string pvname) with gil:
cdef public void cy_event_handler_wrapper(void * callback,
unsigned int handle,
string pvname) with gil:
@@ -117,163 +83,27 @@ cdef public void cy_connect_handler_wrapper(void * callback,
#print(" callback is ", <object> callback)
if callback:
#print(" callback is not None ")
cbobjt=<object> callback
cbobjt(handle, pvname, status)
#print(" cy_connect_handler_wrapper ====+++CONNECT++++++++++ SUCCESS")
#else:
# if str(pvname) in openDictGlobal.keys():
# cbobjt = openDictGlobal[pvname]
# cbobjt(handle, pvname, status)
with nogil:
return
cdef public void py_cb_wrapper(PVDataHolder pvd, unsigned int handle, string pvname) with gil:
#print(" py_cb_wrapper ====================================================+++++++++++++++PVDATA++++++= Handle/PVNAME :", handle, pvname)
cdef pvdata pv1 = PVDataHolderToStruct(pvd)
'''
cdef string val
_c_cafe.getCacheString(handle, val)
#print(val, " ", pv1.value[0])
cdef HandleHelper hh
cdef vector[void *] widgetV
widgetV.reserve(2)
widgetList = []
status = hh.getWidgets(handle, widgetV)
for i in range(0, widgetV.size()):
cbobjt = < object > widgetV[i]
cbobjt(pv1, handle, pvname)
widgetList.append( < object > widgetV[i])
#print(widgetList)
'''
'''
global handleMonDictGlobal
if handleMonDictGlobal is not None:
for cbobjt, v in handleMonDictGlobal.items():
print("handle", v, "cbobjt", cbobjt)
if v == handle:
cbobjt(pv1, handle, pvname)
'''
with nogil:
return
cdef public void py_cb_ctrl_wrapper(PVCtrlHolder pvc, unsigned int handle, string pvname) with gil:
#print(" py_cb_ctrl_wrapper ====================================================+++++++++++++++++CTRL+++++= Handle/PVNAME :", handle, pvname)
cdef pvctrl c1 = PVCtrlHolderToStruct(pvc)
'''
global handleMonDictGlobal
cdef object cbobjt = None
for cbobjt, v in handleMonDictGlobal.items():
if v == handle:
cbobjt(c1, handle, pvname)
'''
with nogil:
return
cdef public void py_cb_handle_wrapper(unsigned int handle) with gil:
print(" py_cb_handle_wrapper ====================================================+++++++++++++++++HANDLE+++++= Handle :", handle)
py_cb_handle(handle)
with nogil:
return
# Default
cdef public void py_cb_handle_monid_wrapper(unsigned int handle, unsigned long monid) with gil:
print(" py_cb_handle_monid_wrapper ====================================================+++++++++++++MONID++++++++++= Handle:", handle)
'''
cdef string val
_c_cafe.getCacheString(handle, val)
print(val, " is val")
'''
# if monDictGlobal.has_key(monid):
global monDictGlobal
if monid in monDictGlobal.keys():
cbobjt = monDictGlobal[monid]
cbobjt(handle)
else:
print("CALLBACK NOT FOUND FOR handle/monid", handle, monid)
with nogil:
return
cdef public void cy_cb_handle_get_wrapper(void * callback, unsigned int handle) with gil:
print(" py_cb_handle_get_wrapper ====================================================+++++++++++++GET++++++++++= Handle:", handle)
print(" py_cb_handle_get_wrapper+++++++++++++GET++++++++++= Handle:", handle)
cbobjt=<object> (<void *> callback)
cbobjt(handle)
with nogil:
return
cdef public void py_cb_handle_get_wrapper(unsigned int handle) with gil:
print(" py_cb_handle_get_wrapper ====================================================+++++++++++++GET++++++++++= Handle:", handle)
# py_cb_handle_get(handle)
global getDictGlobal
if handle in getDictGlobal.keys():
cbobjt = getDictGlobal[handle]
cbobjt(handle)
else:
print("GET CALLBACK NOT FOUND FOR handle", handle)
with nogil:
return
cdef public void cy_cb_handle_put_wrapper(void * callback, unsigned int handle) with gil:
print(" py_cb_handle_put_wrapper ====================================================+++++++++++++PUT++++++++++= Handle:", handle)
#print(" py_cb_handle_put_wrapper+++++++++++++PUT++++++++++= Handle:", handle)
cbobjt=<object> (<void *> callback)
cbobjt(handle)
with nogil:
return
cdef public void py_cb_handle_put_wrapper(unsigned int handle) with gil:
#print(" py_cb_handle_put_wrapper ====================================================+++++++++++++PUT++++++++++= Handle:", handle)
# py_cb_handle_put(handle)
global putDictGlobal
if handle in putDictGlobal.keys():
cbobjt = putDictGlobal[handle]
cbobjt(handle)
else:
print("PUT CALLBACK NOT FOUND FOR handle", handle)
with nogil:
return
cdef public void py_cb_handle_open_wrapper(unsigned int handle, int status) with gil:
# status reports ICAFE_CS_CONN (602) or ICAFE_CS_DISCONN (604)
print(" py_cb_handle_open_wrapper ====================================================+++++++++++++OPEN++++++++++= Handle/Status:", handle, status)
py_cb_handle_open(handle, status)
with nogil:
return
cdef public void py_cb_handle_connect_wrapper(unsigned int handle,
string pvname,
int status) with gil:
print(" py_cb_handle_connect_wrapper ===========================+++CONNECT++++++++++= Handle/PV/Status:", handle, pvname, status)
#py_cb_handle_connect(handle, pvname, status)
global openDictGlobal
for k, y in openDictGlobal.items():
print(k, y)
# if openDictGlobal.has_key(pvname):
if str(pvname) in openDictGlobal.keys():
cbobjt = openDictGlobal[pvname]
cbobjt(handle, pvname, status)
with nogil:
return
# ***********public***************
+110
View File
@@ -0,0 +1,110 @@
cdef object py_cb_handle = None
cdef object py_cb_handle_open = None
cdef object cbobjt = None
# ***********public or api***************
# For when with pvdata
cdef public void cy_monitor_handler_wrapper(void * callback) with gil:
cbobjt=<object> (<void *> callback)
print("CALLED")
cbobjt()
with nogil:
return
cdef public void cy_data_event_handler_wrapper(void * callback,
unsigned int handle,
string pvname,
PVDataHolder pvd) with gil:
global py_cb
#print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(1)= Handle/PVNAME :", handle, pvname)
cdef pvdata data = PVDataHolderToStruct(pvd)
#data.show()
py_cb = <object>(<void *> callback)
#print(" cy_data_event_handler_wrapper=====+++++++++++++++PVDATA++++++(2)= Handle/PVNAME :", handle, pvname)
cdef HandleHelper hh
mpid = hh.getUsrArgsAsUInt(handle)
#print("monitorId", mpid)
#monDictGlobal[mpid](handle, pvname, data)
<object>py_cb(handle, pvname, data)
#if monDictGlobal[mpid] != <object>py_cb:
# print( monDictGlobal[mpid])
# print( <object>py_cb)
with nogil:
return
cdef public void cy_ctrl_event_handler_wrapper(void * callback,
unsigned int handle,
string pvname,
PVCtrlHolder pvc) with gil:
#print(" cy_data_event_handler_wrapper=====+++++++++++++++PVCTRL++++++= Handle/PVNAME :", handle, pvname)
cdef pvctrl data = PVCtrlHolderToStruct(pvc)
cbobjt=<object> (<void *> callback)
cbobjt(handle, pvname, data)
with nogil:
return
cdef public void cy_event_handler_wrapper(void * callback,
unsigned int handle,
string pvname) with gil:
#print(" cy_event_handler_wrapper=====+++++++++++++++HANDLEPV++++++= Handle/PVNAME :", handle, pvname)
#(<object>args[0])(<int>args[1], <string>args[2])
cbobjt=<object> callback
#cbobjt=<object>args[0]
cbobjt(handle, pvname)
#cbobjt=<object>(<int>args[0], pvname)
with nogil:
return
cdef public void cy_handle_handler_wrapper(void * callback,
unsigned int handle) with gil:
#print(" cy_handle_handler_wrapper=====+++++++++++++++HANDLEPV++++++= Handle:", handle)
cbobjt=<object> callback
cbobjt(handle)
with nogil:
return
cdef public void cy_connect_handler_wrapper(void * callback,
unsigned int handle,
string pvname,
int status) with gil:
#print(" cy_connect_handler_wrapper ====+++CONNECT++++++++++= Handle/PV/Status:", handle, pvname, status)
#print(" callback is ", <object> callback)
if callback:
cbobjt=<object> callback
cbobjt(handle, pvname, status)
with nogil:
return
cdef public void cy_cb_handle_get_wrapper(void * callback, unsigned int handle) with gil:
print(" py_cb_handle_get_wrapper+++++++++++++GET++++++++++= Handle:", handle)
cbobjt=<object> (<void *> callback)
cbobjt(handle)
with nogil:
return
cdef public void cy_cb_handle_put_wrapper(void * callback, unsigned int handle) with gil:
#print(" py_cb_handle_put_wrapper+++++++++++++PUT++++++++++= Handle:", handle)
cbobjt=<object> (<void *> callback)
cbobjt(handle)
with nogil:
return
# ***********public***************
+64 -227
View File
@@ -41,25 +41,13 @@ cimport PyCafe as ccafe
# from libcpp.string cimport string
#Cython.Compiler.Options.annotate = True
_pymodule = "PyCafe.pyx" # os.path.basename(__file__)
_pymodule = "PyCafe.pyx"
_pymodule_parts = _pymodule.split(".")
_appname = _pymodule_parts[0]
_python_version = sys.version_info #[0:4]
cdef object py_cb
cdef dict openCallbackDictGlobal = {}
cdef dict hmd = {}
cdef dict handleMonDictGlobal = {}
cdef dict monDictGlobal = {}
cdef dict openDictGlobal = {}
cdef dict getDictGlobal = {}
cdef dict putDictGlobal = {}
#cdef ccafe.CAFE * _c_cafe
#_c_cafe = new ccafe.CAFE()
include "PyCafeDefs_sf.pxi"
@@ -93,7 +81,6 @@ def verify_handlepv(func):
handlePV = args[0]
cdef unsigned int handle = 0
#Accept if pv/handle is in list of length one
if isinstance(handlePV, list):
if len(handlePV) == 1:
@@ -245,33 +232,19 @@ cdef class CyCafe:
###########################################################################
def CAFE_version(self):
return CAFE_VERSION
def EPICS_version(self):
return EPICS_VERSION
@verify_handlepv
def setPyConnectCallbackFn(self, handlePV, cb: object = None):
if cb is None:
return
pv_name = handlePV
#global openCallbackDictGlobal
#openCallbackDictGlobal[cb] = handlePV
#september 21 2021
global openDictGlobal
openDictGlobal[pv_name] = cb
#handle = self.hh.getHandleFromPV(pv_name)
pv_name = handlePV
self.hh.setPyConnectCallbackFn(handlePV, <void *>cb)
#self._c_cafe.channelCreatePolicy.setPyCallbackFlag(True)
#self._c_cafe.channelCreatePolicy.setPyConnectHandler(<void *>cb)
#open
#false
def setPyCallbackConnect(self, pv: str = None, cb: object = None):
if None in (pv, cb):
return
global openDictGlobal
openDictGlobal[pv] = cb
##self.hh.setPyConnectCallbackFn(handle, <void *>cb)
############################################################################
def init(self):
@@ -298,15 +271,7 @@ cdef class CyCafe:
"{} {} \n{}\n{}".format(
self._exception_text, _METHOD,
"ECA_ALLOCMEM error in initializing ca context ",
self.cs.info(ECA_ALLOCMEM)))
'''
_cafeException = CafeException(
_type='CafeError', _source=_METHOD,
_error_code=ECA_ALLOCMEM,
_error_text=self.cs.code(ECA_ALLOCMEM),
_error_info=self.cs.info(ECA_ALLOCMEM))
raise _cafeException
'''
self.cs.info(ECA_ALLOCMEM)))
raise Exception("{} {} \n{}".format(self._exception_text, _METHOD, e))
@@ -454,8 +419,9 @@ cdef class CyCafe:
"of type <class 'str'> or <class 'bytes'>")))
try:
if cb is not None:
for i in range(0, len(pvV)):
self.setPyCallbackConnect(pvV[i], cb)
##for i in range(0, len(pvV)):
##self.setPyCallbackConnect(pvV[i], cb)
#self.setPyConnectCallbackFn(pvV[i], cb)
self._c_cafe.channelCreatePolicy.setPyCallbackFlag(True)
self._c_cafe.channelCreatePolicy.setPyConnectHandler(<void *>cb)
@@ -504,7 +470,7 @@ cdef class CyCafe:
cdef char * pvStr = pv
if cb is not None:
self.setPyCallbackConnect(pv, cb)
####self.setPyCallbackConnect(pv, cb)
self._c_cafe.channelCreatePolicy.setPyCallbackFlag(True)
self._c_cafe.channelCreatePolicy.setPyConnectHandler(<void *>cb)
try:
@@ -822,8 +788,7 @@ cdef class CyCafe:
("First Input argument should be of type <class 'int'> "
"if handle, else <class 'str'> if PV")))
global getDictGlobal
cdef ChannelRequestPolicy crp
self.ph.getChannelRequestPolicyGet(handlePV, crp)
if when:
@@ -832,8 +797,7 @@ cdef class CyCafe:
crp.setWaitKind(wait)
if method:
crp.setMethodKind(method)
if cb is not None:
getDictGlobal[handle] = cb
if cb is not None:
crp.setPyHandlerGet(<void *> cb) # forces when=WITH_CALLBACK_USER_SUPPLIED
self.ph.setChannelRequestPolicyGet(handlePV, crp)
@@ -892,9 +856,8 @@ cdef class CyCafe:
"First input argument should be of type <class 'int'> if handle, \
else <class 'str'> if PV"))
global getDictGlobal
if cb is not None:
getDictGlobal[handle] = cb
if cb is not None:
crp.setPyHandlerGet(<void *>cb) # forces when=WITH_CALLBACK_USER_SUPPLIED
else:
crp.setMethodKind(WITH_CALLBACK_DEFAULT)
@@ -920,10 +883,8 @@ cdef class CyCafe:
self._exception_text, _METHOD,
"First input argument, should be of type <class 'int'> if handle, \
else <class 'str'> if PV"))
global putDictGlobal
if cb is not None:
putDictGlobal[handle] = cb
if cb is not None:
crp.setPyHandlerPut(<void *>cb) # forces when=WITH_CALLBACK_USER_SUPPLIED
else:
crp.setMethodKind(WITH_CALLBACK_DEFAULT)
@@ -4057,7 +4018,7 @@ First input argument, should be a 'list' of of type <class 'int'> if handles or
_val = None
pvdict[self._c_cafe.getPVFromHandle(handleList[i])] = _val
return pvdict
return pvdict, statusOverall, status
# int alarmStatus=None, int alarmSev=None):
##################################################################################
@@ -5185,9 +5146,6 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
_error_info="First input argument, should be of type <class 'int'> if group handle, else <class 'str'> if group name")
raise _cafeException
global monDictGlobal
global handleMonDictGlobal
if dbr:
if dbr not in [DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL]:
print(
@@ -5197,7 +5155,7 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
print("Assuming DBR_TIME")
dbr = DBR_TIME
# Legacy
#global py_cb
cdef vector[MonitorPolicy] mpV
cdef unsigned long mpid
@@ -5224,6 +5182,11 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
sig = inspect.signature(cb)
# a=inspect.getargspec(cb)
mp.setUserArgs(< void * > mpid)
mp.setNoCyCallbackParameters(len(sig.parameters))
mp.setPyCyHandler(<void *> cb)
print('============//1//')
print('SIGNATURE:')
print(str(sig))
@@ -5232,27 +5195,7 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
print('len1', len(sig.parameters.values()))
print('len2', len(sig.parameters))
print('monitor id', mpid)
mp[i].setUserArgs( < void*> mpid)
if len(sig.parameters) == 1:
monDictGlobal[mpid] = cb
mp[i].setPyHandler()
elif len(sig.parameters) == 2:
mp[i].setPyCyHandler(<void *> cb)
elif len(sig.parameters) == 3:
handleMonDictGlobal[cb] = handleList[i]
mp[i].setPyCyHandlerData(<void *> cb)
else:
_cafeException = CafeException(_type='CafeError', _source=_METHOD,
_error_info="The signature of the monitor callback function is not supported. \
Supported fns are: \
1) callback(handle) or 2) callback(pvdata, handle, pv_name) ")
raise _cafeException
mpV.push_back(mp[i])
cdef vector[int] vStatus
@@ -5291,8 +5234,6 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
_error_info="First input argument, should be of type <class 'int'> if group handle, else <class 'str'> if group name")
raise _cafeException
global monDictGlobal
global handleMonDictGlobal
if dbr:
if dbr not in [DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL]:
@@ -5307,8 +5248,7 @@ First input argument, should be of type <class 'int'> if handle, else <class 'st
raise Exception("EXCEPTION RAISED IN PyCafe def groupMonitorStartWithCBList. \n\
Input cb should be of type<list> and give the list of cb objects")
# April 2020 Legacy
#global py_cb
cdef vector[MonitorPolicy] mpV
cdef unsigned long mpid
@@ -5343,7 +5283,11 @@ No of group members doe not match the length of callback object list")
# For setUserArgs pass the address of the variable.
if cb[i]:
sig = inspect.signature(cb[i])
sig = inspect.signature(cb[i])
mp[i].setUserArgs(< void * > mpid) # (<unsigned long *> ptr_mpid)[0])
mp[i].setNoCyCallbackParameters(len(sig.parameters))
mp[i].setPyCyHandler(<void *> cb[i])
print('============')
print('SIGNATURE//2//:')
@@ -5354,26 +5298,7 @@ No of group members doe not match the length of callback object list")
print('len2', len(sig.parameters))
print('monitorid', mpid) # (<unsigned int *> ptr_mpid)[0])
mp[i].setUserArgs( < void * > mpid) # (<unsigned long *> ptr_mpid)[0])
if len(sig.parameters) == 1:
monDictGlobal[mpid] = cb[i]
mp[i].setPyHandler()
elif len(sig.parameters) == 2:
mp[i].setPyCyHandler(<void *> cb[i])
elif len(sig.parameters) == 3:
handleMonDictGlobal[cb[i]] = handleList[i]
mp[i].setPyCyHandlerData(<void *> cb[i])
else:
_cafeException = CafeException(_type='CafeError', _source=_METHOD,
_error_info="The signature of the monitor callback function is not supported. \
Supported fns are: \
1) callback(handle) or 2) callback(pvdata, handle, pv_name) ")
raise _cafeException
mpV.push_back(mp[i])
cdef vector[int] vStatus
@@ -6117,64 +6042,20 @@ No of group members doe not match the length of callback object list")
mp.setDataType(self.channelInfo.getDataType())
mp.setCafeDbrType(DBR_TIME)
global monDictGlobal
global handleMonDictGlobal
global py_cb
global hmd
py_cb = cb
if cb is not None:
#Cement to a global dictionary
hmd[cb] = handle ##otherwise cb gets ovewritten when casting to an object
monDictGlobal[mpid] = cb
#print(hmd)
hmd[cb] = mpid ##otherwise cb gets ovewritten when casting to an object
sig = inspect.signature(cb)
'''
print('SIGNATURE//3//:')
print(str(sig))
for param in sig.parameters.values():
print('Parameter:', param, type(param))
print('len1', len(sig.parameters.values()))
print('len2', len(sig.parameters))
print('monitorid', mpid)
'''
# The corresponding setPyHandler has to be set!!
mp.setUserArgs(< void * > mpid)
mp.setNoCyCallbackParameters(len(sig.parameters))
mp.setPyCyHandler(<void *> cb)
'''
if len(sig.parameters) == 1:
#monDictGlobal[mpid] = cb
mp.setPyCyHandlerHandle(<void *> cb) #handle
##mp.setPyHandler()
# print (<long>mp.getUserArgs())
elif len(sig.parameters) == 2:
mp.setPyCyHandler(<void *> cb) #handle, pvname, pvdata
#mp.setPyHandler()
#mp.setCyCallback(<void *> cb)
elif len(sig.parameters) == 3:
#py_cb=cb
#self.hh.addWidget(handle, <void *> cb)
##print(py_cb)
mp.setPyCyHandlerData(<void *> ( py_cb)) #handle, pvname, pvdata
#handleMonDictGlobal[cb] = handle
#mp.setPyHandlerData()
#mp.setCyCallback(<void *> cb)
else:
_cafeException = CafeException(
_type='CafeError', _source=_METHOD,
_error_info="The signature of the monitor callback function \
given by the user is not supported. Valid fns are: \
1) callback(handle) or 2) callback(pvdata, handle, pv_name) ")
raise _cafeException
'''
with nogil:
status = self._c_cafe.monitorStart(handle, mp)
@@ -6212,79 +6093,40 @@ No of group members doe not match the length of callback object list")
raise _cafeException
cdef int status
cdef unsigned int mpidUI
cdef unsigned int mpid_no_coercion
global monDictGlobal
#global handleMonDictGlobal
global hmd
if mpid:
mpid_no_coercion = mpid
if isinstance(mpid, (int, long)):
mpidUI = mpid
mpid_no_coercion = mpid
with nogil:
status = self._c_cafe.monitorStopWithID(handle, mpidUI)
time.sleep(0.02)
#if (status == ICAFE_NORMAL):
#pass
#print (monDictGlobal)
# DELETE ENTRY ONLY IF IT EXISTS!
# if monDictGlobal.has_key(mpidUI):
# Sep 2020 - try without del for testing!
##if mpidUI in monDictGlobal.keys():
##print("deleted monID/1/ ", mpidUI, monDictGlobal[mpidUI])
##del monDictGlobal[mpidUI]
status = self._c_cafe.monitorStopWithID(handle, mpid_no_coercion)
time.sleep(0.001)
l = None
if mpid not in list(hmd.values()):
pass #happens when is direct mode in table widget
else:
l = list(hmd.keys())[list(hmd.values()).index(mpid)]
if l is not None:
del hmd[l]
else:
raise Exception("EXCEPTION RAISED IN PyCafe def monitorStop. \n \
monitorPolicy ID (mpid) should be of type <class 'int'>")
else:
mids = self.hh.getMonitorIDs(handle)
with nogil:
status = self._c_cafe.monitorStop(handle)
time.sleep(0.01)
_ncount = 0
for key, value in hmd.items():
if value == handle:
_ncount += 1
for i in range (0, _ncount):
try:
l = list(hmd.keys())[list(hmd.values()).index(handle)]
if l is not None:
if mpid in monDictGlobal.keys():
###print("deleted monID/1/ ", mpid, monDictGlobal[mpid])
#######JCdel monDictGlobal[mpid]
if l == monDictGlobal[mpid]:
del hmd[l]
del monDictGlobal[mpid]
except ValueError:
print("List does not contain handle {0}".format(handle))
#{k:v for k,v in hmd.items() if v != handle}
##for a, v in hmd.items():
##print(a, v)
##print ("DEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELLLLLLLETE")
# Find handle with monitor ID and STOP thst one monitor!
if (status == ICAFE_NORMAL):
# print "size", self.hh.getNmonitor(handle)
mpidUIV = self.hh.getMonitorIDs(handle)
'''
for i in range(0, mpidUIV.size()):
print("Deleting here too i from monid/4/", i, mpidUIV[i])
# if monDictGlobal.has_key(mpidUIV[i]):
if mpidUIV[i] in monDictGlobal.keys():
del monDictGlobal[mpidUIV[i]]
print("Deleting here too/5/", mpidUIV[i])
'''
time.sleep(0.001)
for monid in mids:
if monid not in list(hmd.values()):
continue
l = list(hmd.keys())[list(hmd.values()).index(monid)]
if l is not None:
del hmd[l]
if status != ICAFE_NORMAL:
if PYCAFE_PRINT_LEVEL >= PYCAFE_PRINT_LOW:
if handle == 0:
@@ -6293,25 +6135,21 @@ No of group members doe not match the length of callback object list")
self._c_cafe.printStatus(handle, status)
return status
# 3
############################################################################
def monitorStopAll(self):
cdef str _METHOD = "monitorStopAll()"
global monDictGlobal
global handleMonDictGlobal
cdef int status
with nogil:
status = self._c_cafe.monitorStopAll()
# give plenty of time for monitors to stop!
time.sleep(0.2)
monDictGlobal.clear()
handleMonDictGlobal.clear()
hmd.clear()
if status != ICAFE_NORMAL:
if PYCAFE_PRINT_LEVEL >= PYCAFE_PRINT_LOW:
@@ -6341,7 +6179,6 @@ No of group members doe not match the length of callback object list")
else <class 'str'> if PV")
raise _cafeException
# CHECK FOR ALL DATA TYPES!
cdef unsigned short valType = CAFE_STRING
+7708
View File
File diff suppressed because it is too large Load Diff
+7679
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -943,15 +943,15 @@ values, s, sl = cafe.getGroup(groupHandle2) # by group handle
print(values)
if s != cyca.ICAFE_NORMAL:
cafe.printStatusIfError(pvlistAll, sl)
else:
# change some values:
values[0] = values[0] + 0.234
values[1] = values[1] + 0.456
values[8] = "monitor"
# change some values:
values[0] = values[0] + 0.234
values[1] = values[1] + 0.456
values[8] = "monitor"
s, sl = cafe.setGroup(groupHandle2, values)
if s != cyca.ICAFE_NORMAL:
cafe.printStatusIfError(pvlistAll, sl)
s, sl = cafe.setGroup(groupHandle2, values)
if s != cyca.ICAFE_NORMAL:
cafe.printStatusIfError(pvlistAll, sl)
newValues, s, sl = cafe.getGroup(groupHandle2) # by group handle
print(newValues[0], newValues[1])
+182
View File
@@ -0,0 +1,182 @@
51a52,60
> cdef dict openCallbackDictGlobal = {}
> cdef dict hmd = {}
> cdef dict handleMonDictGlobal = {}
> cdef dict monDictGlobal = {}
> cdef dict openDictGlobal = {}
> #cdef dict getDictGlobal = {}
> #cdef dict putDictGlobal = {}
>
>
245c254,257
< pv_name = handlePV
---
> pv_name = handlePV
> global openDictGlobal
> openDictGlobal[pv_name] = cb
> print("HANDLE ===========================================================", handlePV)
247a260,269
> #Used internally
> def setPyCallbackConnect(self, pv: str = None, cb: object = None):
> if None in (pv, cb):
> return
> global openDictGlobal
> openDictGlobal[pv] = cb
> #handle=self.hh.getHandleFromPV(pv)
> #print("HANDLE ===========================================================", handle)
> #self.hh.setPyConnectCallbackFn(handle, <void *>cb)
>
274c296,304
< self.cs.info(ECA_ALLOCMEM)))
---
> self.cs.info(ECA_ALLOCMEM)))
> '''
> _cafeException = CafeException(
> _type='CafeError', _source=_METHOD,
> _error_code=ECA_ALLOCMEM,
> _error_text=self.cs.code(ECA_ALLOCMEM),
> _error_info=self.cs.info(ECA_ALLOCMEM))
> raise _cafeException
> '''
791c821,822
<
---
> ###R###global getDictGlobal
>
800c831,832
< if cb is not None:
---
> if cb is not None:
> ###R###getDictGlobal[handle] = cb
859,860c891,893
<
< if cb is not None:
---
> ###R###global getDictGlobal
> if cb is not None:
> ###R###getDictGlobal[handle] = cb
886,887c919,922
<
< if cb is not None:
---
>
> ###R###global putDictGlobal
> if cb is not None:
> ###R###putDictGlobal[handle] = cb
4021c4056
< return pvdict, statusOverall, status
---
> return pvdict
5150c5185
< #global handleMonDictGlobal
---
> global handleMonDictGlobal
5188,5193d5222
< mp.setUserArgs(< void * > mpid)
< mp.setNoCyCallbackParameters(len(sig.parameters))
< mp.setPyCyHandler(<void *> cb)
<
<
<
5203,5204c5232,5233
<
< '''
---
> mp[i].setUserArgs( < void*> mpid)
>
5213c5242
< ##handleMonDictGlobal[cb] = handleList[i]
---
> handleMonDictGlobal[cb] = handleList[i]
5222c5251
< '''
---
>
5261,5262c5290,5291
< #global monDictGlobal
< #global handleMonDictGlobal
---
> global monDictGlobal
> global handleMonDictGlobal
5313,5317c5342
< sig = inspect.signature(cb[i])
<
< mp[i].setUserArgs(< void * > mpid) # (<unsigned long *> ptr_mpid)[0])
< mp[i].setNoCyCallbackParameters(len(sig.parameters))
< mp[i].setPyCyHandler(<void *> cb[i])
---
> sig = inspect.signature(cb[i])
5328,5329c5353,5354
<
< '''
---
> mp[i].setUserArgs( < void * > mpid) # (<unsigned long *> ptr_mpid)[0])
>
5338c5363
< #handleMonDictGlobal[cb[i]] = handleList[i]
---
> handleMonDictGlobal[cb[i]] = handleList[i]
5347c5372
< '''
---
>
6091,6092c6116,6117
< #global monDictGlobal
< #global handleMonDictGlobal
---
> global monDictGlobal
> global handleMonDictGlobal
6094c6119
< #global hmd
---
> global hmd
6099,6100c6124,6125
< ##hmd[cb] = handle ##otherwise cb gets ovewritten when casting to an object
< ##monDictGlobal[mpid] = cb
---
> hmd[cb] = handle ##otherwise cb gets ovewritten when casting to an object
> monDictGlobal[mpid] = cb
6188c6213
< ##global monDictGlobal
---
> global monDictGlobal
6190c6215
< ##global hmd
---
> global hmd
6218,6219c6243,6244
< time.sleep(0.002)
< '''
---
> time.sleep(0.01)
>
6245,6246c6270,6271
< '''
< ##if (status == ICAFE_NORMAL):
---
>
> if (status == ICAFE_NORMAL):
6249c6274
< ##mpidUIV = self.hh.getMonitorIDs(handle)
---
> mpidUIV = self.hh.getMonitorIDs(handle)
6251c6276
< '''
---
> '''
6258c6283
< '''
---
> '''
6274,6275c6299,6300
< #global monDictGlobal
< #global handleMonDictGlobal
---
> global monDictGlobal
> global handleMonDictGlobal
6284,6285c6309,6310
< #monDictGlobal.clear()
< #handleMonDictGlobal.clear()
---
> monDictGlobal.clear()
> handleMonDictGlobal.clear()
+13 -4
View File
@@ -7,6 +7,10 @@ default_options['emit_linenums'] = True
from Cython.Build import cythonize
from numpy import get_include
_CAFE_VERSION='1.14.1'
_EPICS_VERSION='3.14.12'
setup(
ext_modules = cythonize([Extension('PyCafe',['PyCafe.pyx'],
language="c++",
@@ -15,13 +19,15 @@ setup(
os.environ['EPICS'] + '/base/include/os/Linux',
'/opt/gfa/cafe/boost/boost_1_61_0/include',
'/opt/gfa/cafe/boost/boost_1_61_0/include/boost',
'/opt/gfa/cafe/cpp/cafe-1.13.0-sf-py37-gcc-7.3.0/include',
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/include',
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/include',
'/opt/gfa/zmq/curl-7.54.1/include',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/include',
'.', get_include()],
library_dirs=[ os.environ['EPICS'] + '/base/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-1.13.0-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/lib',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/libs/linux-gcc-6.3.0',
'/opt/gfa/zmq/curl-7.54.1/lib',
@@ -31,7 +37,8 @@ setup(
],
runtime_library_dirs=[
os.environ['EPICS'] + '/base/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-1.13.0-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/lib',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/libs/linux-gcc-6.3.0',
'/opt/gfa/zmq/curl-7.54.1/lib',
@@ -46,6 +53,8 @@ setup(
'py2_import': False, 'warn.unreachable': False,
'remove_unreachable': False},
compile_time_env={'PY_VERSION_HEX':sys.hexversion,
'PY_EXT_C': True, 'BS_CAFE': True }
'PY_EXT_C': True, 'BS_CAFE': True,
'CAFE_VERSION': _CAFE_VERSION,
'EPICS_VERSION': _EPICS_VERSION}
)
)
+13 -5
View File
@@ -7,6 +7,9 @@ default_options['emit_linenums'] = True
from Cython.Build import cythonize
from numpy import get_include
_CAFE_VERSION='1.14.1'
_EPICS_VERSION='3.14.12'
setup(
ext_modules = cythonize([Extension('PyCafe',['PyCafe.pyx'],
language="c++",
@@ -15,13 +18,15 @@ setup(
os.environ['EPICS'] + '/base/include/os/Linux',
'/opt/gfa/cafe/boost/boost_1_61_0/include',
'/opt/gfa/cafe/boost/boost_1_61_0/include/boost',
'/opt/gfa/cafe/cpp/cafe-1.14.0-sf-py37-gcc-7.3.0/include',
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/include',
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/include',
'/opt/gfa/zmq/curl-7.54.1/include',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/include',
'.', get_include()],
library_dirs=[ os.environ['EPICS'] + '/base/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-1.14.0-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/lib',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/libs/linux-gcc-6.3.0',
'/opt/gfa/zmq/curl-7.54.1/lib',
@@ -31,7 +36,8 @@ setup(
],
runtime_library_dirs=[
os.environ['EPICS'] + '/base/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-1.14.0-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/cafe/cpp/cafe-' + _CAFE_VERSION +
'-sf-py37-gcc-7.3.0/lib/' + os.environ['EPICS_HOST_ARCH'],
'/opt/gfa/zmq/zeromq-4.2.3-gcc-6.3.0/lib',
'/opt/gfa/zmsglog/json/jsoncpp-src-0.6.0-rc2/libs/linux-gcc-6.3.0',
'/opt/gfa/zmq/curl-7.54.1/lib',
@@ -39,13 +45,15 @@ setup(
os.environ['PSI_PREFIX'] + '/Programming/gcc/7.3.0/lib64',
os.environ['PSI_PREFIX'] + '/Programming/gcc/7.3.0/lib'
],
libraries=['ca','Com','dl','cafe'])
libraries=['Qt5Core', 'Qt5Xml', 'ca','Com','dl','cafe'])
], annotate=True,
compiler_directives={'embedsignature': False, 'language_level': 3,
'c_string_type': 'str', 'c_string_encoding' : 'ascii',
'py2_import': False, 'warn.unreachable': False,
'remove_unreachable': False},
compile_time_env={'PY_VERSION_HEX':sys.hexversion,
'PY_EXT_C': True, 'BS_CAFE': True }
'PY_EXT_C': True, 'BS_CAFE': True ,
'CAFE_VERSION': _CAFE_VERSION,
'EPICS_VERSION': _EPICS_VERSION}
)
)