commit 2bfc805907a53408215753091294aa5de0c825c8 Author: chrin Date: Tue Sep 19 11:59:20 2017 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13478ba --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build +python-3.5/*.cpp +python-3.5/*.so +python-3.5/*.*~ +python-3.5/SL6-x86_64 diff --git a/PyCafe.pxd b/PyCafe.pxd new file mode 100644 index 0000000..67452ad --- /dev/null +++ b/PyCafe.pxd @@ -0,0 +1,1141 @@ +# file: PyCafe.pxd + +#from cpython.ref cimport PyObject +from libcpp.string cimport string +from libcpp.vector cimport vector +from libcpp.map cimport map +from libcpp.pair cimport pair + +cimport cython + +#import numpy as np + +cimport numpy as cnp + +cdef extern from "Python.h": + ctypedef enum PyGILState_STATE: + PyGILState_LOCKED=0 + PyGILState_UNLOCKED=1 + + void PyEval_InitThreads() + void Py_Initialize() + PyGILState_STATE PyGILState_Ensure() + void PyGILState_Release(PyGILState_STATE) + +cdef extern from "boost/multi_index_container.hpp" namespace "boost": + cdef cppclass multi_index_container: + pass + +cdef extern from "boost/smart_ptr/shared_ptr.hpp" namespace "boost": + cdef cppclass shared_ptr[T]: + shared_ptr() + shared_ptr(T *p) + shared_ptr(const shared_ptr&) + long use_count() + T operator*() + + +cdef extern from "" namespace "std": + cdef cppclass multimap[T, U]: + cppclass iterator: + pair[T, U]& operator*() nogil + iterator operator++() nogil + iterator operator--() nogil + bint operator==(iterator) nogil + bint operator!=(iterator) nogil + multimap() nogil except + + U& operator[](T&) nogil + iterator begin() nogil + iterator end() nogil + pair[iterator, bint] insert(pair[T, U]) nogil + iterator find(T&) nogil + + +cdef extern from "cadef.h": + + ctypedef long chtype + ctypedef oldSubscription * evid + + cdef struct oldSubscription: + pass + + cdef struct oldChannelNotify: + pass + + cdef struct event_handler_args: + oldChannelNotify chid + long type + int count + const void *dbr + int status + void * usr + pass + + + cdef: + int ca_flush_io() + int ca_poll() + + +cdef extern from "caeventmask.h": + #ctypedef enum DBE_TYPE: + # DBE_VALUE=1 + # DBE_LOG=2 + # DBE_ARCHIVE=DBE_LOG + # DBE_ALARM=4 + # DBE_PROPERTY=8 + unsigned int DBE_VALUE + unsigned int DBE_LOG + unsigned int DBE_ARCHIVE + unsigned int DBE_ALARM + unsigned int DBE_PROPERTY + + + +cdef extern from "time.h": + cdef struct tm: + int tm_sec #seconds after the minute 0-61* + int tm_min #minutes after the hour 0-59 + int tm_hour #hours since midnight 0-23 + int tm_mday #day of the month 1-31 + int tm_mon #months since January 0-11 + int tm_year #years since 1900 + int tm_wday #days since Sunday 0-6 + int tm_yday #days since January 1 0-365 + int tm_isdst #Daylight Saving Time flag + +cdef extern from "epicsTime.h": + cdef struct epicsTimeStamp: + unsigned int secPastEpoch # seconds since 0000 Jan 1, 1990 + unsigned int nsec + cdef cppclass epicsTime: + epicsTime (const epicsTimeStamp &) + cdef struct local_tm_nano_sec: + tm ansi_tm + unsigned long nSec + +cdef extern from "db_access.h": + unsigned int DBR_STRING #returns a NULL terminated string + unsigned int DBR_SHORT #returns an unsigned short + unsigned int DBR_INT #returns an unsigned short + unsigned int DBR_FLOAT #returns an IEEE floating point value + unsigned int DBR_ENUM #returns an unsigned short which is the enum item + unsigned int DBR_CHAR #returns an unsigned char + unsigned int DBR_LONG #returns an unsigned long + unsigned int DBR_DOUBLE #returns a double precision floating point number + unsigned int DBR_STS_STRING #returns a string status structure (dbr_sts_string) + unsigned int DBR_STS_SHORT #returns a short status structure (dbr_sts_short) + unsigned int DBR_STS_INT #returns a short status structure (dbr_sts_int) + unsigned int DBR_STS_FLOAT #returns a float status structure (dbr_sts_float) + unsigned int DBR_STS_ENUM #returns an enum status structure (dbr_sts_enum) + unsigned int DBR_STS_CHAR #returns a char status structure (dbr_sts_char) + unsigned int DBR_STS_LONG #returns a long status structure (dbr_sts_long) + unsigned int DBR_STS_DOUBLE #returns a double status structure (dbr_sts_double) + unsigned int DBR_TIME_STRING #returns a string time structure (dbr_time_string) + unsigned int DBR_TIME_SHORT #returns a short time structure (dbr_time_short) + unsigned int DBR_TIME_INT #returns a short time structure (dbr_time_short) + unsigned int DBR_TIME_FLOAT #returns a float time structure (dbr_time_float) + unsigned int DBR_TIME_ENUM #returns an enum time structure (dbr_time_enum) + unsigned int DBR_TIME_CHAR #returns a char time structure (dbr_time_char) + unsigned int DBR_TIME_LONG #returns a long time structure (dbr_time_long) + unsigned int DBR_TIME_DOUBLE #returns a double time structure (dbr_time_double) + unsigned int DBR_GR_STRING #returns a graphic string structure (dbr_gr_string) + unsigned int DBR_GR_SHORT #returns a graphic short structure (dbr_gr_short) + unsigned int DBR_GR_INT #returns a graphic short structure (dbr_gr_int) + unsigned int DBR_GR_FLOAT #returns a graphic float structure (dbr_gr_float) + unsigned int DBR_GR_ENUM #returns a graphic enum structure (dbr_gr_enum) + unsigned int DBR_GR_CHAR #returns a graphic char structure (dbr_gr_char) + unsigned int DBR_GR_LONG #returns a graphic long structure (dbr_gr_long) + unsigned int DBR_GR_DOUBLE #returns a graphic double structure (dbr_gr_double) + unsigned int DBR_CTRL_STRING #returns a control string structure (dbr_ctrl_int) + unsigned int DBR_CTRL_SHORT #returns a control short structure (dbr_ctrl_short) + unsigned int DBR_CTRL_INT #returns a control short structure (dbr_ctrl_int) + unsigned int DBR_CTRL_FLOAT #returns a control float structure (dbr_ctrl_float) + unsigned int DBR_CTRL_ENUM #returns a control enum structure (dbr_ctrl_enum) + unsigned int DBR_CTRL_CHAR #returns a control char structure (dbr_ctrl_char) + unsigned int DBR_CTRL_LONG #returns a control long structure (dbr_ctrl_long) + unsigned int DBR_CTRL_DOUBLE #returns a control double structure (dbr_ctrl_double) + + ctypedef char[40] dbr_string_t + ctypedef short dbr_short_t + ctypedef float dbr_float_t + ctypedef unsigned short dbr_enum_t + ctypedef unsigned char dbr_char_t + ctypedef int dbr_long_t + ctypedef double dbr_double_t + + cdef struct dbr_sts_string: + pass + cdef struct dbr_sts_short: + pass + cdef struct dbr_sts_int: + pass + cdef struct dbr_sts_float: + dbr_float_t value + dbr_short_t status + pass + cdef struct dbr_sts_enum: + pass + cdef struct dbr_sts_char: + pass + cdef struct dbr_sts_long: + pass + cdef struct dbr_sts_double: + pass + + cdef struct dbr_time_string: + pass + cdef struct dbr_time_short: + pass + cdef struct dbr_time_int: + pass + cdef struct dbr_time_float: + dbr_float_t value + dbr_short_t status + dbr_short_t severity + epicsTimeStamp stamp + pass + cdef struct dbr_time_enum: + pass + cdef struct dbr_time_char: + pass + cdef struct dbr_time_long: + pass + cdef struct dbr_time_double: + pass + + cdef struct dbr_gr_string: + pass + cdef struct dbr_gr_short: + pass + cdef struct dbr_gr_int: + pass + cdef struct dbr_gr_float: + dbr_float_t value + dbr_short_t status + pass + cdef struct dbr_gr_enum: + pass + cdef struct dbr_gr_char: + pass + cdef struct dbr_gr_long: + pass + cdef struct dbr_gr_double: + pass + + cdef struct dbr_ctrl_string: + pass + cdef struct dbr_ctrl_short: + pass + cdef struct dbr_ctrl_int: + pass + cdef struct dbr_ctrl_float: + dbr_float_t value + dbr_short_t status + pass + cdef struct dbr_ctrl_enum: + pass + cdef struct dbr_ctrl_char: + pass + cdef struct dbr_ctrl_long: + pass + cdef struct dbr_ctrl_double: + pass + +cdef extern from "caerr.h": + unsigned int ECA_NORMAL + unsigned int ECA_ALLOCMEM + unsigned int ECA_TOLARGE + unsigned int ECA_TIMEOUT + unsigned int ECA_BADTYPE + unsigned int ECA_INTERNAL + unsigned int ECA_GETFAIL + unsigned int ECA_PUTFAIL + unsigned int ECA_BADCOUNT + unsigned int ECA_BADSTR + unsigned int ECA_DISCONN + unsigned int ECA_DBLCHNL + unsigned int ECA_EVDISALLOW + unsigned int ECA_BADMONID + unsigned int ECA_BADMASK + unsigned int ECA_IODONE + unsigned int ECA_IOINPROGRESS + unsigned int ECA_BADSYNCGRP + unsigned int ECA_PUTCBINPROG + unsigned int ECA_NORDACCESS + unsigned int ECA_NOWTACCESS + unsigned int ECA_ANACHRONISM + unsigned int ECA_NOSEARCHADDR + unsigned int ECA_NOCONVERT + unsigned int ECA_BADCHID + unsigned int ECA_BADFUNCPTR + unsigned int ECA_ISATTACHED + unsigned int ECA_UNAVAILINSERV + unsigned int ECA_CHANDESTROY + unsigned int ECA_BADPRIORITY + unsigned int ECA_NOTTHREADED + unsigned int ECA_16KARRAYCLIENT + unsigned int ECA_CONNSEQTMO + unsigned int ECA_UNRESPTMO + +cdef extern from "caopCodes.h": + cdef cppclass CAOPCodes: + pass + string message(int) + int enumIs(string) + show() + + +cdef extern from "defines.h": + const short PVNAME_SIZE + + +cdef extern from "cafeDataType.h": + ctypedef enum CAFE_DATATYPE: + CAFE_TYPENOTCONN =-1 + CAFE_STRING = 0 + CAFE_SHORT = 1 + CAFE_INT = CAFE_SHORT + CAFE_FLOAT = 2 + CAFE_ENUM = 3 + CAFE_USHORT = CAFE_ENUM + CAFE_CHAR = 4 + CAFE_LONG = 5 + CAFE_DOUBLE = 6 + CAFE_NO_ACCESS = 7 + CAFE_INVALID_DATATYPE = 8 + CAFE_NOT_REQUESTED = 100 + CAFE_NOT_SHOWN = 101 + + ctypedef union CAFE_DATATYPE_UNION: + dbr_string_t str + dbr_short_t s + dbr_float_t f + dbr_enum_t us #unsigned short us; + dbr_char_t ch #unsigned char ch; + dbr_long_t l #int l; + dbr_double_t d + + ctypedef CAFE_DATATYPE_UNION * CAFE_DATATYPE_UNION_SEQ + + cdef cppclass CAFEDataTypeCode: + pass + string message(int) + int enumIs(string) + show() + +cdef extern from "cafeEnum.h": + ctypedef enum DBR_TYPE: + DBR_PRIMITIVE + DBR_PLAIN=DBR_PRIMITIVE + DBR_STS + DBR_TIME + DBR_GR + DBR_CTRL + DBR_PUT # DBR_PUT_ACKT and DBR_PUT_ACKS Write only - used from global alarm acknowledge. + DBR_STSACK # is DBR_STSACK_STRING + DBR_CLASS # is DBR_CLASS_NAME, + DBR_NONE # should not occur, but used internally within cafeVectors.h + + ctypedef enum ChannelFlushSendBufferPolicyKind: + WITH_FLUSH_IO + WITH_PEND_IO + WITH_PEND_EVENT + WITH_POLL + + ctypedef enum ChannelWhenToFlushSendBufferPolicyKind: + FLUSH_AUTOMATIC=0 + FLUSH_NOW=FLUSH_AUTOMATIC + FLUSH_AFTER_EACH_CHANNEL_CREATION=FLUSH_NOW + FLUSH_AFTER_EACH_CHANNEL_SUBSCRIPTION=FLUSH_NOW + FLUSH_AFTER_EACH_MESSAGE=FLUSH_NOW + FLUSH_AFTER_EACH_GROUP_CREATION=FLUSH_NOW + FLUSH_DESIGNATED_TO_CLIENT + + ctypedef enum ChannelGetCacheWaitPolicyKind: + GET_CACHE_NO_CHECK=0 + GET_CACHE_NO_WAIT + GET_CACHE_NOW =GET_CACHE_NO_WAIT + GET_CACHE_WAIT + + ctypedef enum ChannelGetActionWhenMonitorPolicyKind: + GET_FROM_CACHE + GET_FROM_IOC + + ctypedef enum ChannelRequestPolicyKind: + WITHOUT_CALLBACK + WITH_CALLBACK_DEFAULT + WITH_CALLBACK_USER_SUPPLIED + + ctypedef enum ChannelRequestDataTypePolicyKind: + NATIVE_DATATYPE + LOWEST_DATATYPE # The smaller in byte size of type requested and native datatype + + ctypedef enum ChannelWaitForResponsePolicyKind: + BLOCKING=0 + WAIT=BLOCKING + NON_BLOCKING=1 + NO_WAIT=NON_BLOCKING + + ctypedef enum StatusMessageKind: + NO_MESSAGE + PRE_REQUEST + FROM_REQUEST + FROM_PEND + FROM_CALLBACK + FROM_MESSAGE + + ctypedef enum CallbackProgressKind: + NOT_INITIATED + PENDING + COMPLETE + + + +cdef extern from "exceptions.h": + ctypedef struct CAFEException_pv: + char pv [60] #PVNAME_SIZE + char pvAlias[60] #PVNAME_SIZE + unsigned int handle + CAFE_DATATYPE dataTypeNative + const char * dataTypeNativeText + int statusCode + const char * statusCodeText + const char * statusMessage + const char * source + unsigned int ln + pass + + ctypedef struct CAFEException_group: + char groupName [60] #[PVNAME_SIZE]; + unsigned int groupHandle + int statusCode + const char * statusCodeText + const char * statusMessage + const char * source + unsigned int ln + pass + + cdef cppclass CAFEException_open: + CAFEException_pv pvEx + pass + const char* what() + + cdef cppclass CAFEException_groupOpen: + CAFEException_group groupEx + pass + const char* what() + +cdef extern from "channelRegalia.h": + cdef cppclass ChannelRegalia: + pass + oldChannelNotify * getChannelID() + bint getConnectFlag() + const char * getHostName() + string getHostNameAsString() + int getDataType() + const char * getClassName() + string getClassNameAsString() + unsigned short getAccessRead() + unsigned short getAccessWrite() + unsigned short getReadAccess() + unsigned short getWriteAccess() + unsigned int getNelem() + int getConnectionState() + int getCafeConnectionState() + string getConnectionStateAsString() + string getCafeConnectionStateAsString() + +cdef extern from "handleHelper.h": + ctypedef struct etsDate: + int year + int mon + int day + int hour + int min + int sec + unsigned long nsec + pass + + ctypedef struct etsNorm: + unsigned int secPastEpoch + unsigned int nsec + pass + + cdef cppclass HandleHelper: + etsDate _etsDate + etsNorm _etsNorm + + HandleHolder() + + int checkConsistency(unsigned int) + + string getStringFromEnum(unsigned int, unsigned short) + short getEnumFromString(unsigned int, string) + + const char * getPVFromHandle (unsigned int) + unsigned int getHandleFromPV(const char *) + unsigned int getGroupHandleFromGroupName(const char *) + unsigned int getHandleFromPVWithinGroup(const char *, unsigned int) + vector[unsigned int] getHandlesFromWithinGroupV(unsigned int) + int getChannelRegalia(unsigned int, ChannelRegalia) + + unsigned int getUsrArgsAsUInt(unsigned int) + chtype getDataTypeCB(unsigned int) + chtype getDbrDataTypeCB(unsigned int) + DBR_TYPE getCafeDbrTypeCB(unsigned int) + + int getStatus (unsigned int) + int getAlarmStatusSeverity(unsigned int, short[2]) + int [] getTimeStamp(unsigned int, epicsTimeStamp &ts) + + unsigned int setCafeDbrTypeV(vector[unsigned int], DBR_TYPE) + unsigned int setCafeDbrType(unsigned int, DBR_TYPE) + unsigned int getCafeDbrType(unsigned int, DBR_TYPE &) + unsigned int setNelem(unsigned int, unsigned int) + unsigned int setNelemToNative(unsigned int) + unsigned int setNelemToRetrieveFromCache (unsigned int, unsigned int) + unsigned int setNelemToRetrieveFromCtrlCache (unsigned int, unsigned int) + unsigned int getNelemToRetrieveFromCache (unsigned int) + unsigned int getNelemToRetrieveFromCtrlCache (unsigned int) + + unsigned int setNelemCtrl (unsigned int, unsigned int); + unsigned int getNelemRequestCtrl (unsigned); + unsigned int getNelemClientCtrl (unsigned); + + unsigned int getNelemClient (unsigned int) + unsigned int getNelemNative (unsigned int) + unsigned int getNelemRequest (unsigned int) + + unsigned int getNmonitor (unsigned int) + vector[unsigned int] getMonitorIDs(unsigned int) + + int getDataTypeNative (unsigned int, long) + int getDataTypeRequest(unsigned int, long) + + etsNorm getEpicsTimeStampAsUInt32(unsigned int) + etsDate getEpicsTimeStampAsDate(unsigned int) + + int printHandlesV(vector[unsigned int]) + + unsigned int getDisconnectedHandles (vector[unsigned int] &, vector[string] &) + unsigned int getHandles (vector[unsigned int] &, vector[string] &) + unsigned int getHandleStates (vector[unsigned int] &, vector[string] &, vector[unsigned short] &) + + int getMonitorPolicyVector(unsigned int, vector[MonitorPolicy] &); + + +cdef extern from "policies.h": + + ctypedef void (*pCallback) (event_handler_args) + + cdef cppclass MonitorPolicy: + + MonitorPolicy() + unsigned int getMonitorID() + void setMask(unsigned int) + void setDataType(chtype) + void setCafeDbrType(DBR_TYPE) + void setHandler(pCallback) + void setDefaultHandler() + void setPyHandler() + void setPyHandlerData() + void setUserArgs(void *) + unsigned int getMask() + unsigned int getNelem() + unsigned int getUserArgs() + DBR_TYPE getCafeDbrType() + unsigned int getDataType() + unsigned int getDbrDataType() + bint maskHasDBE_PROPERTY() + bint maskHasDBE_VALUE() + bint maskHasDBE_LOG() + bint maskHasDBE_ALARM() + + cdef cppclass ChannelOpenPolicy: + ChannelOpenPolicy() + void setWhenToFlushSendBuffer(ChannelWhenToFlushSendBufferPolicyKind) + ChannelWhenToFlushSendBufferPolicyKind getWhenToFlushSendBuffer() + void setFlushSendBufferKind(ChannelFlushSendBufferPolicyKind) + void flushSendBufferNow() + double setTimeout(double) + double getTimeout() + double setDefaultTimeout(double) + double getDefaultTimeout() + double setTimeoutToDefault() + + cdef cppclass ChannelRequestPolicy: + ChannelRequestPolicy() + ChannelWhenToFlushSendBufferPolicyKind getWhenToFlushSendBuffer() + ChannelWaitForResponsePolicyKind getWaitKind() + ChannelRequestPolicyKind getMethodKind() + pCallback getHandler() + int getCallbackStatus() + void setHandler(pCallback h) + void setPyHandlerGet() + void setPyHandlerPut() + void setMethodKind(ChannelRequestPolicyKind) + void setWhenToFlushSendBuffer(ChannelWhenToFlushSendBufferPolicyKind) + void setWaitKind(ChannelWaitForResponsePolicyKind) + void setCallbackStatus (int) + void setPolicy(ChannelWhenToFlushSendBufferPolicyKind,ChannelWaitForResponsePolicyKind,ChannelRequestPolicyKind) + + cdef cppclass ChannelRequestDataTypePolicy: + ChannelRequestDataTypePolicy() + ChannelRequestDataTypePolicy(ChannelRequestDataTypePolicyKind) + ChannelRequestDataTypePolicyKind requestKind + void setRequestKind(ChannelRequestDataTypePolicyKind) + ChannelRequestDataTypePolicyKind getRequestKind() + + + cdef cppclass ChannelTimeoutPolicy: + ChannelTimeoutPolicy() + bint getSelfGoverningTimeout() + void setSelfGoverningTimeout(bool) + double getTimeout() + double getDeltaTimeout() + unsigned short getNtries() + double setTimeout(double) + double setDeltaTimeout(double) + unsigned short setNtries(unsigned short) + + + cdef cppclass ChannelGetCacheWaitPolicy: + ChannelGetCacheWaitPolicy() + ChannelGetCacheWaitPolicy(ChannelGetCacheWaitPolicyKind) + ChannelGetCacheWaitPolicyKind whenKind + void setWaitKind(ChannelGetCacheWaitPolicyKind) + ChannelGetCacheWaitPolicyKind getWhenKind() + + cdef cppclass ChannelGetActionWhenMonitorPolicy: + ChannelGetActionWhenMonitorPolicy() + ChannelGetActionWhenMonitorPolicy(ChannelGetActionWhenMonitorPolicyKind) + ChannelGetActionWhenMonitorPolicyKind actionKind + void setActionKind(ChannelGetActionWhenMonitorPolicyKind) + ChannelGetActionWhenMonitorPolicyKind getActionKind() + + +cdef extern from "policyHelper.h": + cdef cppclass PolicyHelper: + + int getChannelGetCacheWaitPolicy (unsigned int, ChannelGetCacheWaitPolicy &) + int setChannelGetCacheWaitPolicy (unsigned int, ChannelGetCacheWaitPolicy) + int setChannelGetCacheWaitPolicyAllHandles (ChannelGetCacheWaitPolicy) + int getChannelGetActionWhenMonitorPolicy(unsigned int, ChannelGetActionWhenMonitorPolicy &) + int setChannelGetActionWhenMonitorPolicy(unsigned int, ChannelGetActionWhenMonitorPolicy ) + int setChannelGetActionWhenMonitorPolicyAllHandles (ChannelGetActionWhenMonitorPolicy) + + int getChannelRequestDataTypePolicy(unsigned int, ChannelRequestDataTypePolicy &) + int setChannelRequestDataTypePolicy(unsigned int, ChannelRequestDataTypePolicy) + int setChannelRequestDataTypePolicyAllHandles(ChannelRequestDataTypePolicy) + + int getChannelRequestPolicyGet (unsigned int , ChannelRequestPolicy &) + int setChannelRequestPolicyGet (unsigned int , ChannelRequestPolicy) + int setChannelRequestPolicyGetAllHandles (ChannelRequestPolicy) + + int getChannelRequestPolicyPut (unsigned int, ChannelRequestPolicy &) + int setChannelRequestPolicyPut (unsigned int , ChannelRequestPolicy) + int setChannelRequestPolicyPutAllHandles (ChannelRequestPolicy) + + int getChannelTimeoutPolicyGet (unsigned int, ChannelTimeoutPolicy &) + int setChannelTimeoutPolicyGet (unsigned int, ChannelTimeoutPolicy) + + int getChannelTimeoutPolicyPut (unsigned int, ChannelTimeoutPolicy &) + int setChannelTimeoutPolicyPut (unsigned int, ChannelTimeoutPolicy) + + int getTimeout(unsigned int, double &) + int getTimeout(unsigned int, double &, double &) + int getTimeoutMin(double &, double &) + int getTimeoutMax(double &, double &) + int setTimeout(unsigned int, double) + int setTimeout(unsigned int, double, double) + int setTimeout(double) + int setTimeout(double, double) + int setSelfGoverningTimeout(bint) + int getSGTimeout (unsigned int, double &, double &) + int getSGTimeout (unsigned int, double &) + int getSGTimeoutMin (double, double &) + int getSGTimeoutMax (double, double &) + int setSGTimeout (unsigned int, double, double) + int setSGTimeout (unsigned int, double) + int setSGTimeout (double, double) + int setSGTimeout (double) + int setSGSelfGoverningTimeout(bint) + +#cdef extern from "hashConduit.h": +# ctypedef multi_index_container<> cafeConduit_set +# ctypedef cafeConduit_set cafeConduit_set_by_handle +# ctypedef multi_index_container.iterator it_handle + + +cdef extern from "statusCodes.h": + cdef int ICAFE_STATUS_BASE = 600 + cdef int ICAFE_STATUS_CS = ICAFE_STATUS_BASE + cdef int ICAFE_STATUS_CFT = 700 + cdef int ICAFE_STATUS_CA_OP = 800 + cdef int ICAFE_STATUS_ERROR = 1000 + cdef int ICAFE_FILE_ERROR = 1100 + cdef int ICAFE_SUCCESS = ECA_NORMAL + cdef int ICAFE_NORMAL = ECA_NORMAL + + ctypedef enum CAFE_CS_STATE: + ICAFE_CS_NEVER_CONN=600 + ICAFE_CS_PREV_CONN + ICAFE_CS_CONN + ICAFE_CS_CLOSED + ICAFE_CS_DISCONN + ICAFE_CS_UNKNOWN + + ctypedef enum CAFE_CFT_STATE: + ICAFE_TYPENOTCONN=700 + ICAFE_RULE_FALSE + ICAFE_BADCOUNT + ICAFE_CALLBACK_NOT_YET_INVOKED + ICAFE_WAITING_FOR_PREV_CALLBACK + ICAFE_CACHE_EMPTY + ICAFE_CHANNEL_BLOCKING_POLICY_CONFLICT + ICAFE_MONITOR_DELAYED_AS_CONN_DOWN + ICAFE_HAS_MONITOR_GET_DONE_FROM_CACHE + ICAFE_SET_AND_GET_MISMATCH + + ctypedef enum CAFE_CC_STATE: + ICAFE_CA_OP_GET=800 + ICAFE_CA_OP_PUT + ICAFE_CA_OP_CREATE_CHANNEL + ICAFE_CA_OP_ADD_EVENT + ICAFE_CA_OP_CLEAR_EVENT + ICAFE_CA_OP_OTHER + ICAFE_CA_OP_CONN_UP + ICAFE_CA_OP_CONN_DOWN + + ctypedef enum CAFE_FILE_ERROR: + ECAFE_LOAD_COLLECTION=1100 + ECAFE_LOAD_GROUP + + ctypedef enum CAFE_ERROR_STATE: + ECAFE_NODATA=1000 + ECAFE_INVALID_TYPE + ECAFE_BADCOUNT + ECAFE_BADSTR + ECAFE_BADTYPE + ECAFE_NO_CONVERT + ECAFE_NULLCONTEXT + ECAFE_NULLCHID + ECAFE_NULLEVID + ECAFE_UNKNOWN_COLLECTION + ECAFE_EMPTY_COLLECTION + ECAFE_COLLECTION_PREV_DEF + ECAFE_COLLECTION_INVALID_MEMBER + ECAFE_RULE_FALSE + ECAFE_UNKNOWN_GROUP + ECAFE_EMPTY_GROUP + ECAFE_GROUP_PREV_DEF + ECAFE_INVALID_HANDLE + ECAFE_INVALID_GROUP_HANDLE + ECAFE_NORDACCESS + ECAFE_NOWTACCESS + ECAFE_TIMEOUT + ECAFE_CANNOT_OPEN_FILE + ECAFE_INVALID_SWITCH_CASE + ECAFE_PVALIAS_PREV_DEF + ECAFE_PVALIAS_INVALID + ECAFE_PVNAME_PREV_DEF_AS_PVALIAS + ECAFE_DEVICE_ATTRIB_NOT_FOUND + ECAFE_HASH_UNIQUEID_EXISTS + ECAFE_WRONG_CA_CONTEXT + ECAFE_INVALID_CAFENUM_POLICY_TYPE + ECAFE_MAX_MONITORS_PER_CHAN_EXCEEDED + ECAFE_INVALID_ENUM_INDEX + ECAFE_PVGROUP_GROUPHANDLE_MISMATCH + ECAFE_TIMEOUT_SET_AND_MATCH + ECAFE_HANDLE_MISMATCH_SET_AND_MATCH + + cdef cppclass CAFEStatusSeverity: + CAFEStatusSeverity() + string message (int) + + cdef cppclass CAFEStatusInfo: + CAFEStatusInfo() + string message (int) + + cdef cppclass CAFEStatusCode: + CAFEStatusCode() + string message (int) + int enumIs(string) + + cdef cppclass CAFEStatus: + CAFEStatus() + string code(int) + string info(int) + string message(int) + void report(int) + +''' +cdef extern from "cafeService.h": + + cdef cppclass DBPMData: + double getValue() + epicsTimeStamp getEpicsTimeStamp() + int getStatus() + + cdef cppclass DBPMKeeper: + DBPMKeeper() + #DBPMKeeper(vector[string], vector[unsigned int], multimap[float, string]) + DBPMKeeper(vector[string], vector[unsigned int], vector[string], vector[float]) + vector[unsigned int] getHandle() + vector[string] getPV() + vector[string] getDevice() + + vector[double] getS() + vector[DBPMData] getX() + vector[DBPMData] getY() + vector[DBPMData] getQ() + vector[DBPMData] getEnergy() + + + vector[double] getOffsetX() + vector[double] getOffsetY() + + bint getIsAllXOK() + bint getIsAllYOK() + bint getIsAllQOK() + bint getIsAllEnergyOK() + bint getIsAllOK () + bint setBS(bint) + bint resetBS() + void closeBS() + int getStatus() +''' + +cdef extern from "PVDataHolder.h": + + cdef cppclass PVDataHolder: + etsDate _etsDate + etsNorm _etsNorm + + PVDataHolder() + PVDataHolder(unsigned int) + #shared_ptr [CAFE_DATATYPE_UNION []] val; + #shared_ptr[double []] getDouble() + #shared_ptr[float []] getFloat() + #shared_ptr[int []] getInt() + #shared_ptr[string []] getString() + + #shared_ptr[vector [double]] getAsVDouble() + #shared_ptr[vector [float]] getAsVFloat() + #shared_ptr[vector [int]] getAsVInt() + #shared_ptr[vector [string]] getAsVString() + + char * getAsDbr_string_t() + char * getAsDbr_string_t(unsigned int) + string getAsString() + string getAsString(unsigned int) + double getAsDouble() + double getAsDouble(unsigned int) + float getAsFloat() + float getAsFloat(unsigned int) + short getAsShort() + short getAsShort(unsigned int) + unsigned short getAsUShort() + unsigned short getAsUShort(unsigned int) + unsigned char getAsChar() + unsigned char getAsChar(unsigned int) + int getAsLong() + int getAsLong(unsigned int) + int getAsLongLong() + int getAsLongLong(unsigned int) + + string getWFAsString() + string concatToString() + + + unsigned int getUserNo() + + unsigned int getNelem() + int setNelem(unsigned int) + void setRule(bint) + bint getRule() + void setHasAlarm(bint) + void setHasTS(bint) + bint getHasAlarm() + bint getHasTS() + + int setString(string) + int setDouble(double) + int setInt(int) + int setVString(vector[string]) + int setVDouble(vector[double]) + int setVInt(vector[int]) + + int getAlarmStatus() + int getAlarmSeverity() + int getStatus() + + etsNorm getEpicsTimeStampAsUInt32() + etsDate getEpicsTimeStampAsDate() + + unsigned int getDataType() + char * getPV() + char * getPVName() + void valReset() + + +cdef extern from "PVCtrlHolder.h": + + cdef cppclass PVCtrlHolder: + + PVCtrlHolder() + PVCtrlHolder(unsigned int) + + short getPrecision() + const char * getUnits() + string getUnitsAsString() + short getNoEnumStrings() + vector[string] getEnumStrings() + double getUpperDispLimit_AsDouble() + double getLowerDispLimit_AsDouble() + double getUpperAlarmLimit_AsDouble() + double getUpperWarningLimit_AsDouble() + double getLowerWarningLimit_AsDouble() + double getLowerAlarmLimit_AsDouble() + double getUpperCtrlLimit_AsDouble() + double getLowerCtrlLimit_AsDouble() + + float getFloat(unsigned int) + + string getAsString() + string getAsString(unsigned int) + + char* getAsDbr_string_t() + char* getAsDbr_string_t(unsigned int) + double getAsDouble() + double getAsDouble(unsigned int) + float getAsFloat() + float getAsFloat(unsigned int) + short getAsShort() + short getAsShort(unsigned int) + unsigned short getAsUShort() + unsigned short getAsUShort(unsigned int) + unsigned char getAsChar() + unsigned char getAsChar(unsigned int) + int getAsLong() + int getAsLong(unsigned int) + int getAsLongLong() + int getAsLongLong(unsigned int) + + unsigned int getNelem() + int setNelem(unsigned int) + + int getAlarmStatus() + int getAlarmSeverity() + int getStatus() + + unsigned int getDataType() + + +cdef extern from "PVGroup.h": + + cdef cppclass PVGroup: + PVGroup() + PVDataHolder * getPVData() + unsigned int getNPV() + string getNameAsString() + unsigned int getGroupHandle() + int getStatusGroup() + void setPVData(PVDataHolder *) + void show() + void showMax(unsigned int) + void showMaxMax(unsigned int, unsigned int) + pass + + +cdef extern from "cafe.h": + + cdef cppclass CAFE: + + ChannelOpenPolicy channelOpenPolicy + ChannelOpenPolicy channelOpenGroupPolicy + ChannelOpenPolicy channelMonitorPolicy + #ChannelRequestPolicy channelRequestPolicyGet + #ChannelRequestPolicy channelRequestPolicyPut + + PolicyHelper getPolicyHelper() + HandleHelper getHandleHelper() + + int _ca_pend_io(double) nogil + int _ca_pend_event(double) nogil + int _ca_flush_io() nogil + int _ca_poll() nogil + + int init() + int open(char *, unsigned int &) except + + int openV(vector[string], vector[unsigned int] &) except + + int closeHandlesV(vector[unsigned int]) nogil + int close(unsigned int) nogil + int closeChannels() nogil + + bint allChannelsConnected() + bint isChannelConnected(unsigned int) + int printDisconnectedHandles() + int printHandle(unsigned int) + int printHandles() + + bint isEnum(unsigned int) + bint isValid(unsigned int) + + void printStatusMessage(int) + void printStatus(unsigned int, int) + + int attachContextByPVName(const char *) + int attachContextByHandle(unsigned int) + + unsigned int getNelemClient (unsigned int) + unsigned int getNelemNative (unsigned int) + unsigned int getNelemRequest(unsigned int) + + const char * getPVFromHandle (unsigned int) + unsigned int getHandleFromPV (const char *) + + void loadSFGroups(string) + + int getChannelInfo(unsigned int, ChannelRegalia) + + CAFEStatus getCafeStatus() + CAFEStatusSeverity getCafeStatusSeverity() + + PVDataHolder * getPVData(vector[unsigned int]) + + vector[string] getFromGlobalChannelList(vector[string]) + + string getChannelIDAsString(chid) + + int getWFAsString(unsigned int, string &) nogil + int getWFAsStringCache(unsigned int, string &) + + int getNonBlocking(unsigned int) nogil + int getCacheFloatArray(unsigned int, float *) + int getCacheDoubleArray(unsigned int, double *) + int getCacheShortArray(unsigned int, short *) + int getCacheLongArray(unsigned int, int *) + int getCacheStringArray(unsigned int, string *) + int getCacheDbrStringArray(unsigned int, dbr_string_t[]) + int getCacheDouble(unsigned int, double &) + int getCacheLong(unsigned int, int &) + int getCacheString(unsigned int, string &) + + int getDouble(unsigned int, double &) nogil + int getLong(unsigned int, int &) nogil + int getString(unsigned int, string &) nogil + int getStringTS(unsigned int, string &, short &, short&, epicsTimeStamp&) nogil + + int getCharArray(unsigned int, char []) nogil + int getShortArray(unsigned int, short []) nogil + int getUShortArray(unsigned int, unsigned short[]) nogil + int getDoubleArray(unsigned int, double []) nogil + int getFloatArray(unsigned int, float []) nogil + int getLongArray(unsigned int, int[]) nogil + int getStringArray(unsigned int, string[]) nogil + int getDbrStringArray(unsigned int, dbr_string_t[]) nogil + + int get(unsigned int, PVDataHolder &) nogil + int getCtrl(unsigned int, PVCtrlHolder &) nogil + int getCtrlCache(unsigned int, PVCtrlHolder &) nogil + + int getPVArray(vector[unsigned int], PVDataHolder *) nogil + int getCachePVArray(vector[unsigned int], PVDataHolder *) + int getCachePVArrayNoWait(vector[unsigned int], PVDataHolder *) + + int getV(vector[unsigned int], vector[int]) nogil + int getCacheVStr(vector[unsigned int], vector[string], vector[int]) nogil + int getCacheVLong(vector[unsigned int], vector[dbr_long_t], vector[int]) nogil + int getCacheVDouble(vector[unsigned int], vector[double], vector[int]) nogil + + int waitForBundledEvents(vector[unsigned int], vector[int]) nogil + int waitForGetEvent(unsigned int) nogil + + int monitorStart(unsigned int, MonitorPolicy &) nogil + int monitorStopAll() nogil + int monitorStop(unsigned int) nogil + int monitorStopWithID(unsigned int, unsigned int) nogil + int getCache(unsigned int, PVDataHolder &) + + + + MonitorPolicy * createMonitorPolicyArray(const unsigned int) + int groupMonitorStart(unsigned int, vector[int]&, vector[MonitorPolicy] & ) nogil + int groupMonitorStop (unsigned int, vector[int]&) nogil + int groupDefine(char *, vector[const char *]) + int groupOpen(char *, unsigned int &) nogil except + + int groupClose(unsigned int &) nogil except + + int groupAttach(unsigned int, PVGroup &) nogil + int groupGet(unsigned int, PVGroup &) nogil + int groupGetCache(unsigned int, PVGroup &) nogil + int groupSet(unsigned int, PVGroup &) nogil + + int groupMemberList(const char *, vector[string] &) + + int loadCollectionsFromXML(const char *) nogil + int loadGroupsFromXML(const char *) nogil + int devicePositionMap(const char *, map[float, string]&) + int devicePositionV(const char *, vector[string]& , vector[float] &) + + int restoreFromXML(const char * snapshotFile) nogil; + int snapshot2XML (PVGroup pg) nogil; + void openGroupXMLFile(string fileName) nogil; + void closeGroupXMLFile(string fileName) nogil; + int group2XML (const char * grpName, string fileName) nogil; + + int groupList (vector[string] &) + + int printStatusIfError(vector[unsigned int], vector[int]) + + int setStringArray(unsigned int, char **) nogil + int setCharArray(unsigned int, unsigned char *) nogil + int setLongArray(unsigned int, int *) nogil + int setDoubleArray(unsigned int, double *) nogil + + int setPVArray(vector[unsigned int], PVDataHolder *) nogil + + int setVString(unsigned int, vector[string]) nogil + int setVChar(unsigned int, vector[unsigned char]) nogil + int setVShort(unsigned int, vector[short]) nogil + int setVUShort(unsigned int, vector[unsigned short]) nogil + int setVLong(unsigned int, vector[dbr_long_t]) nogil + int setVFloat (unsigned int, vector[float]) nogil + int setVDouble(unsigned int, vector[double]) nogil + + int setVVString(vector[unsigned int], vector[string], vector[int]&) nogil + int setVVChar(vector[unsigned int], vector[unsigned char], vector[int]&) nogil + int setVVLong(vector[unsigned int], vector[int], vector[int]&) nogil + int setVVDouble(vector[unsigned int], vector[double], vector[int]&) nogil + + int setString(unsigned int, string) nogil + int setChar(unsigned int, unsigned char) nogil + int setShort(unsigned int, short) nogil + int setUShort(unsigned int, unsigned short) nogil + int setLong(unsigned int, int) nogil + int setLongLong(unsigned int, long long) nogil + int setFloat (unsigned int, float) nogil + int setDouble(unsigned int, double) nogil + + int setAndMatch(const unsigned int, double, const unsigned int, double tolerance, double timeout, bint printFlag) nogil + int setAndMatchMany(vector[unsigned int], vector[double], vector[unsigned int], double tolerance, double timeout, bint printFlag) nogil + + int match(double, const unsigned int, double tolerance, double timeout, bint printFlag) nogil + int matchMany(vector[double], vector[unsigned int], double tolerance, double timeout, bint printFlag) nogil + + + #int readDBPMOffsets(DBPMKeeper) + #int getDBPM(DBPMKeeper &) nogil + #int prepareDBPM(vector[string] &, vector[unsigned int] &, vector[string] &, vector[float] &) nogil + + + + int setNelemToOne(const unsigned int) + int setNelemToPrevious(const unsigned int, const unsigned int) + int setNelemToRetrieveFromCacheToOne(const unsigned int) + int setNelemToRetrieveFromCacheToPrevious(const unsigned int, const unsigned int) + int getNelemToRetrieveFromCache(const unsigned int) + int terminate() nogil + + pass diff --git a/PyCafe.pyd b/PyCafe.pyd new file mode 100644 index 0000000..95b451f Binary files /dev/null and b/PyCafe.pyd differ diff --git a/PyCafe.pyx b/PyCafe.pyx new file mode 100644 index 0000000..2e82da9 --- /dev/null +++ b/PyCafe.pyx @@ -0,0 +1,6045 @@ +#distutils: language = c++ +# file: PyCafe.pyx + +cimport PyCafe as ccafe +import numpy as np +cimport numpy as cnp + + +from cpython cimport array + +import array +from cython.view cimport array as cvarray + +from libc.stdlib cimport malloc, free +from cython.operator cimport dereference as deref, preincrement as inc +from cython cimport view +import ctypes +import time +import timeit + +import os +import cython +import inspect +import sys + +#from libcpp.string cimport string + +import Cython.Compiler.Options +Cython.Compiler.Options.annotate=True + +include "PyCafeDefs.pxi" + +cdef dict monDictGlobal={} + + +################################################################################## +cdef class CyCafe: + + cdef: + ccafe.CAFE *_c_cafe + double valFloat #cython float64 + string valStr + int valInt + #double * valFloatArray #cython float64 + #int * valIntArray + #dbr_string_t * valStringArray + + vector[string] vStr + vector[double] vFloat #cython float64 + vector[dbr_long_t] vInt + HandleHelper hh + PolicyHelper ph + CAFEException_pv expv + CAFEException_open exopen + CAFEStatus cs + CAFEStatusSeverity css + ####PyGILState_STATE gstate + tuple pythonVersion + + bint haveExceptions + ChannelRegalia channelInfo + #list moncbList + #list monidList + #dict monDict + + str exString + + cdef vector[string] bpmList + vector[unsigned int] bpmHandles + #multimap[float, string] floatStringMap + #map[float, string] bpmPosDev + vector[float] bpmPos + vector[string] bpmDev + ###DBPMData dbpmData + ###DBPMKeeper dbpm + ###bint dbpmInitialized + + def __cinit__(self): + self._c_cafe = new ccafe.CAFE() + if self._c_cafe is NULL: + raise MemoryError() + + ###self.dbpmInitialized=False + + self.cs =self._c_cafe.getCafeStatus() + ##self.css=self._c_cafe_getCafeStatusSeverity() + + self.pythonVersion=sys.version_info[0:4] + + self.haveExceptions=True + + self.exString="EXCEPTION RAISED IN PyCafe.pyx:" + #self.moncbList =[] + #self.monidList=[] + #self.monDict={} + + #Required with gil for callbacks + #However seems to work without this call + ####Py_Initialize() + ####PyEval_InitThreads() + + + def __dealloc__(self): + del self._c_cafe + + + ################################################################################## + def init(self): + return self._c_cafe.init() + ################################################################################## + + def withExceptions(self, bint exceptions=True): + self.haveExceptions=exceptions + return self.haveExceptions + + #def getMonidList(self): + # return self.monidList + + #def getMoncbList(self): + # return self.moncbList + + #def getMonDict(self): + # return self.monDict + + ################################################################################## + def open(self, pv): + cdef str _METHOD_="open(pv)" + + cdef vector[string] pvV + cdef vector[unsigned int] handleV + cdef bytes py_string + + if isinstance(pv, (list)): + for i in range(0, len(pv)): + if isinstance(pv[i], unicode): + py_string = (pv[i]).encode('UTF-8') + pvV.push_back( py_string ) + elif isinstance(pv[i], bytes): + pvV.push_back( (pv[i]).encode('utf8') ) + else: + print ("Unknown type in {}".format(_METHOD_)) + try: + status=self._c_cafe.openV(pvV, handleV) + except RuntimeError as e: + if isinstance (e.args, tuple): + if 'CAFEException' in (e.args[0]): + _cyCafeException = CyCafeException(_type='cafe', _source=_METHOD_, \ + _ec=ECA_ALLOCMEM, _et=self.cs.code(ECA_ALLOCMEM), _ei=self.cs.info(ECA_ALLOCMEM)) + raise Exception(_cyCafeException) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, e.what())) + + return handleV + + elif not isinstance(pv, (bytes,str)): + + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "Input argument, pv, should be ")) + + cdef unsigned int handle=0 + + try: + status=self._c_cafe.open(pv, handle) + except RuntimeError as e: + if isinstance (e.args, tuple): + if 'CAFEException' in (e.args[0]): + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, _handle=handle, _pv=pv, \ + _ec=ECA_ALLOCMEM, _et=self.cs.code(ECA_ALLOCMEM), _ei=self.cs.info(ECA_ALLOCMEM)) + raise Exception(_cyCafeException) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, e.what())) + + #print ("******************** HANDLE *******", handle); + + return handle + + ################################################################################## + def openNoWait(self): + self._c_cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + self._c_cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT) + return + + def openPrepare(self): + self._c_cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + self._c_cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT) + return + + def openGroupPrepare(self): + self._c_cafe.channelOpenGroupPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + self._c_cafe.channelOpenGroupPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT) + return + + def setOpenDefaultPendTime(self, double timeout): + return self._c_cafe.channelOpenPolicy.setDefaultTimeout(timeout) + + def getOpenDefaultPendTime(self): + return self._c_cafe.channelOpenPolicy.getDefaultTimeout() + + + ################################################################################## + def openNow(self): + self._c_cafe.channelOpenPolicy.flushSendBufferNow() + self._c_cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW) + self._c_cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + return + + ################################################################################## + def openNowAndWait(self, double timeout): + self._c_cafe.channelOpenPolicy.setTimeout(timeout) + self._c_cafe.channelOpenPolicy.flushSendBufferNow() + #reset + self._c_cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW) + self._c_cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + self._c_cafe.channelOpenPolicy.setTimeoutToDefault() + return + + ################################################################################## + + ################################################################################## + def openGroupNowAndWait(self, double timeout): + self._c_cafe.channelOpenGroupPolicy.setTimeout(timeout) + self._c_cafe.channelOpenGroupPolicy.flushSendBufferNow() + #reset + self._c_cafe.channelOpenGroupPolicy.setWhenToFlushSendBuffer(FLUSH_NOW) + self._c_cafe.channelOpenGroupPolicy.setFlushSendBufferKind(WITH_PEND_EVENT) + self._c_cafe.channelOpenGroupPolicy.setTimeoutToDefault() + return + + ################################################################################## + + def openMonitorPrepare(self): + self._c_cafe.channelMonitorPolicy.setFlushSendBufferKind(WITH_FLUSH_IO) + self._c_cafe.channelMonitorPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT) + return + + + ################################################################################## + def openMonitorNow(self): + self._c_cafe.channelMonitorPolicy.flushSendBufferNow() + #reset + self._c_cafe.channelMonitorPolicy.setWhenToFlushSendBuffer(FLUSH_NOW) + self._c_cafe.channelMonitorPolicy.setFlushSendBufferKind(WITH_FLUSH_IO) + time.sleep(0.1) + return + + ################################################################################## + + + ################################################################################## + def getMonitorWhenToFlushSendBuffer(self): + return self._c_cafe.channelMonitorPolicy.getWhenToFlushSendBuffer() + + + ################################################################################## + + + ################################################################################## + def openMonitorNowAndWait(self, double timeout): + self._c_cafe.channelMonitorPolicy.setTimeout(timeout) + self._c_cafe.channelMonitorPolicy.flushSendBufferNow() + time.sleep(timeout) + #reset + self._c_cafe.channelMonitorPolicy.setWhenToFlushSendBuffer(FLUSH_NOW) + self._c_cafe.channelMonitorPolicy.setFlushSendBufferKind(WITH_FLUSH_IO) + return + + ################################################################################## + + def ca_pend_event(self, double timeout): + self._c_cafe._ca_pend_event(timeout) + return + + def ca_pend_io(self, timeout): + self._c_cafe._ca_pend_io(timeout) + return + + def ca_poll(self): + self._c_cafe._ca_poll() + return + + def ca_flush_io(self): + self._c_cafe._ca_flush_io() + return + + ################################################################################## + def setChannelRequestPolicyGet(self, handlePV, ChannelWhenToFlushSendBufferPolicyKind when, \ + ChannelWaitForResponsePolicyKind wait, ChannelRequestPolicyKind method, \ + object cb=None): + cdef str _METHOD_="setChannelRequestPolicyGet" + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First Input argument should be if handle, else if PV")) + + global py_cb_handle_get + + cdef ChannelRequestPolicy cp + self.ph.getChannelRequestPolicyGet(handlePV, cp) + if when: + cp.setWhenToFlushSendBuffer(when) + if wait: + cp.setWaitKind(wait) + if method: + cp.setMethodKind(method) + if cb: + py_cb_handle_get=cb + cp.setPyHandlerGet() #forces when=WITH_CALLBACK_USER_SUPPLIED + + self.ph.setChannelRequestPolicyGet(handlePV, cp) + return + ################################################################################## + + ################################################################################## + def setCallbackGet(self, handlePV, object cb=None): + + cdef str _METHOD_="setCallbackGet" + + cdef ChannelRequestPolicy cp + self.ph.getChannelRequestPolicyGet(handlePV, cp) + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + global py_cb_handle_get + if cb: + py_cb_handle_get=cb + cp.setPyHandlerGet() #forces when=WITH_CALLBACK_USER_SUPPLIED + else: + cp.setMethodKind(WITH_CALLBACK_DEFAULT) + + self.ph.setChannelRequestPolicyGet(handlePV, cp) + return + ################################################################################## + + + ################################################################################## + def setCallbackPut(self, handlePV, object cb=None): + + cdef str _METHOD_="setCallbackPut" + + cdef ChannelRequestPolicy cp + self.ph.getChannelRequestPolicyPut(handlePV, cp) + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + global py_cb_handle_put + if cb: + py_cb_handle_put=cb + cp.setPyHandlerPut() #forces when=WITH_CALLBACK_USER_SUPPLIED + else: + cp.setMethodKind(WITH_CALLBACK_DEFAULT) + + self.ph.setChannelRequestPolicyPut(handlePV, cp) + return + ################################################################################## + + ################################################################################## + def setTimeout(self, timeout): + return self.ph.setTimeout(timeout) + ################################################################################## + + ################################################################################## + def getTimeoutGet(self): + cdef double minValue,p,g + minValue=0 + p=0 + g=0 + self.ph.getTimeoutMin(p,g) + minValue=g + self.ph.getTimeoutMax(p,g) + if (g < minValue): + minValue=g + return minValue + ################################################################################## + + + ################################################################################## + def getTimeoutPut(self): + cdef double minValue,p,g + minValue=0 + p=0 + g=0 + self.ph.getTimeoutMin(p,g) + minValue=p + self.ph.getTimeoutMax(p,g) + if (p < minValue): + minValue=g + return minValue + ################################################################################## + + + ################################################################################## + def setSelfGoverningTimeout(self, bint b): + return self.ph.setSelfGoverningTimeout(b) + ################################################################################## + + ################################################################################## + # Synchronous Groups + ################################################################################## + def setSGTimeout(self, double timeout): + return self.ph.setSGTimeout(timeout) + ################################################################################## + + ################################################################################## + def getSGTimeoutGet(self): + cdef double minValue,p,g + minValue=0 + p=0 + g=0 + self.ph.getSGTimeoutMin(p,g) + minValue=g + self.ph.getSGTimeoutMax(p,g) + if (g < minValue): + minValue=g + + return minValue + ################################################################################## + + ################################################################################## + def getSGTimeoutPut(self): + cdef double minValue,p,g + minValue=0 + p=0 + g=0 + self.ph.getSGTimeoutMin(p,g) + minValue=p + self.ph.getSGTimeoutMax(p,g) + if (p < minValue): + minValue=p + + return minValue + ################################################################################## + + ################################################################################## + def setSGSelfGoverningTimeout(self, bint b): + cdef PolicyHelper ph + return ph.setSGSelfGoverningTimeout(b) + ################################################################################## + + ################################################################################## + def attachContext(self, handlePV): + cdef str _METHOD_="attachContext" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + return self._c_cafe.attachContextByHandle(handlePV) + elif isinstance(handlePV, (str)) == 1: + return self._c_cafe.attachContextByPVName(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + + ################################################################################## + + ################################################################################## + def loadCollectionsFromXML(self, const char * fileName): + with nogil: + self._c_cafe.loadCollectionsFromXML(fileName) + return + ################################################################################## + ################################################################################## + def loadGroupsFromXML(self, const char * fileName): + with nogil: + self._c_cafe.loadGroupsFromXML(fileName) + return + ################################################################################## + + def devicePositionMap(self, const char * collectionName): + + p=[] + d=[] + cdef map[float, string] mmfs + cdef map[float, string].iterator it + self._c_cafe.devicePositionMap(collectionName, mmfs) + it= mmfs.begin() + tup=() #tuple + while it != mmfs.end(): + tup=deref(it) + + p.append(tup[0]) + d.append(tup[1]) + inc(it) + return d,p + + + def devicePositionV(self, const char * collectionName): + cdef str _METHOD_="devicePositionV(self, const char * collectionName)" + #p=[] + #d=[] + cdef vector[string] dev + cdef vector[float] pos + status=self._c_cafe.devicePositionV(collectionName, dev, pos) + + if status != ICAFE_NORMAL: + raise Exception("{} {} {} {} {} {}".format(self.exString, _METHOD_, \ + "status=", status, self.cs.code(status), self.cs.code(status) )) + + + #for i in range (0, dev.size()): + #d.append(dev[i]) + #p.append(pos[i]) + return dev, pos + + + + ################################################################################## + def groupList(self): + cdef vector[string] gList + #conservative guess + gList.reserve(36) + + self._c_cafe.groupList(gList) + + #Place in list to avoid this warning: + # warning: comparison between signed and unsigned integer expressions + #gl=[] + #for i in range (0, len(gList)): + # gl.append(gList[i]) + return gList + ################################################################################## + + + def getMonitorIDInCallback(self, handle): + return self.hh.getUsrArgsAsUInt(handle) + + def getDataTypeInCallback(self, handle): + return self.hh.getDataTypeCB(handle) + + def getDbrDataTypeInCallback(self, handle): + return self.hh.getDbrDataTypeCB(handle) + + def getDbrBaseInCallback(self, handle): + return self.hh.getCafeDbrTypeCB(handle) + + ################################################################################## + def getHandlesFromWithinGroup(self, gHandleName): + + cdef str _METHOD_="getHandlesFromWithinGroup(gHandleName)" + + cdef unsigned int groupHandle=0 + if isinstance(gHandleName, (int,long)) == 1: + groupHandle=gHandleName + elif isinstance(gHandleName, (str)) == 1: + groupHandle=self.hh.getGroupHandleFromGroupName(gHandleName) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if group handle, else if group name")) + + cdef vector[unsigned int] hList + hList=self.hh.getHandlesFromWithinGroupV(groupHandle) + return hList + ################################################################################## + + + + ################################################################################## + def close(self, handlePV): + cdef str _METHOD_="close" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + cdef int stat + with nogil: + stat=self._c_cafe.close(handle) + + return stat + + ################################################################################## + def closeChannels(self): + cdef int stat + with nogil: + stat=self._c_cafe.closeChannels() + return stat + + + ################################################################################## + def closeHandles(self, list handleList): + cdef str _METHOD_="closeHandlesV" + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be a 'list' of if handles or if PVs")) + + #Do this only to avoid compiler warnings + cdef vector[unsigned int] v + for i in range(0, len(handleList)): + v.push_back(handleList[i]) + cdef int stat + with nogil: + stat=self._c_cafe.closeHandlesV(v) + return stat + + ################################################################################## + def allConnected(self): + return self._c_cafe.allChannelsConnected() + + ################################################################################## + def isConnected(self, handlePV): + cdef str _METHOD_="isConnected" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + return self._c_cafe.isChannelConnected(handle) + + ################################################################################## + def printDisconnected(self): + return self._c_cafe.printDisconnectedHandles() + + def printDisconnectedHandles(self): + return self._c_cafe.printDisconnectedHandles() + + ################################################################################## + def printHandles(self): + return self._c_cafe.printHandles() + + ################################################################################## + def printHandle(self, handlePV): + cdef str _METHOD_="printHandle" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + return self._c_cafe.printHandle(handle) + ################################################################################## + + ################################################################################## + def printHandlesV(self, list handleList): + cdef str _METHOD_="printHandlesV" + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be a 'list' of if handles or if PVs")) + + #Do this only to avoid compiler warnings + cdef vector[unsigned int] v + for i in range(0, len(handleList)): + v.push_back(handleList[i]) + return self.hh.printHandlesV(v) + ################################################################################## + + ################################################################################## + def getDisconnectedHandles(self): + cdef vector[unsigned int] dhV + cdef vector[string] pvV + self.hh.getDisconnectedHandles(dhV,pvV) + return dhV,pvV + ################################################################################## + + + ################################################################################## + def getHandles(self): + cdef vector[unsigned int] dhV + cdef vector[string] pvV + self.hh.getHandles(dhV,pvV) + return dhV,pvV + ################################################################################## + + + ################################################################################## + def getHandleStates(self): + cdef vector[unsigned int] dhV + cdef vector[string] pvV + cdef vector[unsigned short] stateV + self.hh.getHandleStates(dhV,pvV, stateV) + return dhV,pvV,stateV + ################################################################################## + + + ################################################################################## + def getStatusSeverity(self, int statusCode): + return self._c_cafe.getCafeStatusSeverity().message(statusCode) + + ################################################################################## + def getStatusCodeAsText(self, int statusCode): + return self.cs.code(statusCode) + + ################################################################################## + def getStatusCodeAsString(self, int statusCode): + return self.cs.code(statusCode) + + ################################################################################## + def getStatusInfo(self, int statusCode): + return self.cs.info(statusCode) + + ################################################################################## + def getStatusMsg(self, int statusCode): + return self.cs.message(statusCode) + + ################################################################################## + def getStatus(self, handlePV): + cdef str _METHOD_="getStatus" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + return self.hh.getStatus(handle) + + ################################################################################## + def getAlarmStatusSeverity(self,handlePV): + cdef str _METHOD_="getAlarmStatusSeverity" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + cdef short aStatSev[2] + status=self.hh.getAlarmStatusSeverity(handle,aStatSev) + return aStatSev[0], aStatSev[1] + + ################################################################################## + def getTimeStamp(self,handlePV): + cdef str _METHOD_="getTimeStamp" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + cdef HandleHelper hh + + hh._etsNorm=self.hh.getEpicsTimeStampAsUInt32(handle) + + cpdef ll=[] + ll.append(hh._etsNorm.secPastEpoch) + ll.append(hh._etsNorm.nsec) + #print ("TimeStamp ", ll) + return ll + + ################################################################################## + def getTimeStampAsDate(self,handlePV): + cdef str _METHOD_="getimeStampAsDate" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + cdef HandleHelper hh + cpdef ld=[] + + hh._etsDate =self.hh.getEpicsTimeStampAsDate(handle) + ld.append(hh._etsDate.year ) + ld.append(hh._etsDate.mon ) + ld.append(hh._etsDate.day ) + ld.append(hh._etsDate.hour ) + ld.append(hh._etsDate.min ) + ld.append(hh._etsDate.sec ) + ld.append(hh._etsDate.nsec ) + #print ("TimeStampAsDate ", ld) + return ld + + ################################################################################## + ### Allow user to choose whether or not to open ##### + cpdef checkForHandle(self, str pv, bint force=True): + cdef unsigned int _handle=0; + _handle=self.hh.getHandleFromPV(pv) + if _handle == 0: + if (force): + return self.open(pv) + else: + return 0 + else: + return _handle + ################################################################################## + + + ################################################################################## + cpdef checkForHandleList(self, list pvList, bint force=True): + + cdef unsigned int nToOpen=0 + + handleList=[] + cdef unsigned int _handle=0 + for i in range(0, len(pvList)): + _handle=self.hh.getHandleFromPV(pvList[i]) + if _handle == 0: + if (force): + nToOpen=nToOpen+1; + self.openNoWait() + _handle=self.open(pvList[i]) + handleList.append(_handle) + else: + handleList.append(_handle) + if nToOpen > 0: + self.openNowAndWait(2.0+nToOpen*0.001) + return handleList + ################################################################################## + + + ################################################################################## + cpdef checkForGroupHandle(self, str gName, bint force=True): + cdef unsigned int _ghandle=0; + _ghandle=self.hh.getGroupHandleFromGroupName(gName) + if _ghandle == 0: + if (force): + return self.groupOpen(gName) + else: + return 0 + else: + return _ghandle + ################################################################################## + + + ################################################################################## + def getPVNameFromHandle(self, int h): + return self._c_cafe.getPVFromHandle(h) + ################################################################################## + + ################################################################################## + def getHandleFromPVName(self, str name): + #if type(name) is unicode: + # py_string = (name).encode('UTF-8') + # return self._c_cafe.getHandleFromPV(py_string) + return self._c_cafe.getHandleFromPV(name) + ################################################################################## + + ################################################################################## + def getChannelInfo(self, handlePV): + cdef str _METHOD_="getChannelInfo" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV, force=True) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def getChannelInfo") + + cdef ChannelRegalia cr + status=self._c_cafe.getChannelInfo(handle,cr) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def getChannelInfo. Status = %d" %status) + + #cdef channelInfo ci=channelRegaliaToStruct(cr) + #ci.channelID=self._c_cafe.getChannelIDAsString(cr.getChannelID()) + #do hex(cr.getChannelID()) to get channelId in hex form + + return channelRegaliaToStruct(cr) + ################################################################################## + + def getChannelList(self, list listStrings): + return self._c_cafe.getFromGlobalChannelList(listStrings) + + ################################################################################## + + + + + ################################################################################## + def getWFAsString(self, handlePV, bint cache=False): + cdef str _METHOD_="getWFAsString" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + cdef string strWF + if (cache == True): + status=self._c_cafe.getWFAsStringCache(handle, strWF) + else: + with nogil: + status=self._c_cafe.getWFAsString(handle, strWF) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def %s. Status = %d" %_METHOD_,status) + + return strWF + + ################################################################################## + + + ################################################################################## + def getWFAsStringCache(self, handlePV): + return self.getWFAsString(handlePV, cache=True) + + ################################################################################## + + + + + ################################################################################## + + def getEnumFromString(self, handlePV, str enumString): + cdef str _METHOD_="getEnumFromString" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + enumValue=self.hh.getEnumFromString(handle, enumString) + if enumValue == -1: + raise Exception("{} {} {} {} {}".format(self.exString, _METHOD_, \ + ": ENUM string value:", enumString, "not recognized! ")) + return enumValue + + ################################################################################## + + def getStringFromEnum(self, handlePV, int enumValue): + cdef str _METHOD_="getStringFromEnum" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + return self.hh.getStringFromEnum(handle, enumValue) + + ################################################################################## + + def loadSFGroups(self): + cdef bytes py_string + py_string = ('VA').encode('UTF-8') + #cdef vector[string] gnV + #gnV.push_back(py_string) + #return self._c_cafe.loadSFGroups(gnV[0]) + return self._c_cafe.loadSFGroups(py_string) + + def loadSFGroupsWithBase(self, str VA): + cdef bytes py_string + py_string = (VA).encode('UTF-8') + return self._c_cafe.loadSFGroups(py_string) + #return self._c_cafe.loadSFGroups(VA) + + + + + ################################################################################## + def setDbrBase(self, handlePV, DBR_TYPE dbrBase): + cdef str _METHOD_="setDbrBase" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + #Print Warning Message + if dbrBase > DBR_TIME: + print ("WARNING: PyCafe def setDbrBase(handle/PV, DBR_TYPE)") + print ("Allowed DBR_TYPEs are DBR_PLAIN (0), DBR_STS(1), DBR_TIME(2)") + print ("The value entered was", dbrBase, "hence assuming DBR_TIME" ) + dbrBase=DBR_TIME + + return self.hh.setCafeDbrType(handle, dbrBase) + ################################################################################## + + + ################################################################################## + def getDbrBase(self, handlePV): + cdef str _METHOD_="getDbrBase" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + + cdef DBR_TYPE _cafeDbrType=DBR_PLAIN + cdef int status=self.hh.getCafeDbrType(handle,_cafeDbrType) + + return _cafeDbrType + + ################################################################################## + + + ################################################################################## + def setGetCacheWaitPolicy(self, handlePV, ChannelGetCacheWaitPolicyKind wpk): + cdef str _METHOD_="setGetCacheWaitPolicy" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + #Print Warning Message + if wpk > GET_CACHE_WAIT: + print ("WARNING: PyCafe def setGetCacheWaitPolicy(handle/PV, ChannelGetCacheWaitPolicyKind)") + print ("Allowed ChannelGetCacheWaitPolicyKind are GET_CACHE_NO_CHECK (0), GET_CACHE_NO_WAIT (1), GET_CACHE_WAIT (2)") + print ("The value entered was", wpk, "hence assuming default value GET_CACHE_WAIT" ) + wpk=GET_CACHE_WAIT + + cdef ChannelGetCacheWaitPolicy channelGetCacheWaitPolicy + channelGetCacheWaitPolicy.setWaitKind(wpk) + + return self.ph.setChannelGetCacheWaitPolicy(handle,channelGetCacheWaitPolicy) + ################################################################################## + + ################################################################################## + def setGetCacheWaitPolicyAllHandles(self, ChannelGetCacheWaitPolicyKind wpk): + + #Print Warning Message + if wpk > GET_CACHE_WAIT: + print ("WARNING: PyCafe def setGetCacheWaitPolicyAllHandles(ChannelGetCacheWaitPolicyKind)") + print ("Allowed ChannelGetCacheWaitPolicyKind are GET_CACHE_NO_CHECK (0), GET_CACHE_NO_WAIT (1), GET_CACHE_WAIT (2)") + print ("The value entered was", wpk, "hence assuming default value GET_CACHE_WAIT" ) + wpk=GET_CACHE_WAIT + + cdef ChannelGetCacheWaitPolicy channelGetCacheWaitPolicy + channelGetCacheWaitPolicy.setWaitKind(wpk) + + return self.ph.setChannelGetCacheWaitPolicyAllHandles(channelGetCacheWaitPolicy) + ################################################################################## + + ################################################################################## + def setGetActionWhenMonitorPolicy(self, handlePV, ChannelGetActionWhenMonitorPolicyKind wmpk): + cdef str _METHOD_="setGetActionWhenMonitorPolicy" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + #Print Warning Message + if wmpk > GET_FROM_IOC: + print ("WARNING: PyCafe def setGetActionWhenMonitorPolicy(handle/PV, ChannelGetActionWhenMonitorPolicyKind)") + print ("Allowed ChannelGetActionWhenMonitorPolicyKind are GET_FROM_CACHE (0), GET_FROM_IOC (1)") + print ("The value entered was", wmpk, "hence assuming default value GET_FROM_IOC" ) + wmpk=GET_FROM_IOC + + cdef ChannelGetActionWhenMonitorPolicy channelGetActionWhenMonitorPolicy + channelGetActionWhenMonitorPolicy.setActionKind(wmpk) + + return self.ph.setChannelGetActionWhenMonitorPolicy(handle,channelGetActionWhenMonitorPolicy) + ################################################################################## + + + ################################################################################## + def setGetActionWhenMonitorPolicyAllHandles(self, ChannelGetActionWhenMonitorPolicyKind wmpk): + + #Print Warning Message + if wmpk > GET_FROM_IOC: + print ("WARNING: PyCafe def setGetActionWhenMonitorPolicyAllHandles(ChannelGetActionWhenMonitorPolicyKind)") + print ("Allowed ChannelGetActionWhenMonitorPolicyKind are GET_FROM_CACHE (0), GET_FROM_IOC (1)") + print ("The value entered was", wmpk, "hence assuming default value GET_FROM_IOC" ) + wmpk=GET_FROM_IOC + + cdef ChannelGetActionWhenMonitorPolicy channelGetActionWhenMonitorPolicy + channelGetActionWhenMonitorPolicy.setActionKind(wmpk) + + return self.ph.setChannelGetActionWhenMonitorPolicyAllHandles(channelGetActionWhenMonitorPolicy) + ################################################################################## + + ################################################################################## + def getNonBlocking(self, handlePV): + ################################################################################## + cdef str _METHOD_="getNonBlocking" + cdef unsigned int handle=0 + cdef int status + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + with nogil: + status=self._c_cafe.getNonBlocking(handle) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + raise Exception("EXCEPTION RAISED in PyCafe def getNonBlocking. Status = %d" %status) + + return status + ################################################################################## + + ################################################################################## + def getStr(self, handlePV, object cb=None): + return self.get(handlePV,dt='str') + ################################################################################## + + ################################################################################## + def getInt(self, handlePV, object cb=None): + return self.get(handlePV, dt='int') + ################################################################################## + + ################################################################################## + def getFloat(self, handlePV, object cb=None): + return self.get(handlePV, dt='float') + ################################################################################## + + ################################################################################## + def get(self, handlePV, str dt='native'): + ################################################################################## + cdef str _METHOD_ = "get" + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + cdef int status + cdef long dtr=0 + status=self.hh.getDataTypeNative(handle, dtr) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe', _source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + return None + + elif dtr in [CAFE_NO_ACCESS, CAFE_TYPENOTCONN]: + if self._c_cafe.isChannelConnected(handle) is False: + self._c_cafe.getChannelInfo(handle,self.channelInfo) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,self.channelInfo.getCafeConnectionState() ) + if self.haveExceptions: + #raise Exception("EXCEPTION RAISED in PyCafe def get. \ +#Channel Not Connected, status = %d" %self.channelInfo.getCafeConnectionState()) + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=self.channelInfo.getCafeConnectionState(), \ + _et=self.cs.code(self.channelInfo.getCafeConnectionState()), \ + _ei=self.cs.info(self.channelInfo.getCafeConnectionState())) + raise Exception(_cyCafeException) + + + return None + + #Likely to be superfluous + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,ICAFE_TYPENOTCONN) + if self.haveExceptions: + _cyCafeException = CyCafeException(type='cafe', _source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=ICAFE_TYPENOTCONN, _et=self.cs.code(ICAFE_TYPENOTCONN), _ei=self.cs.info(ICAFE_TYPENOTCONN)) + raise Exception(_cyCafeException) + return None + + #global py_cb_handle_get + #if cb: + #py_cb_handle_get=cb + #self.setChannelRequestPolicyGet(handle, wait=WAIT, when=FLUSH_NOW, method=WITH_CALLBACK_USER_SUPPLIED, pcb=True) + + cdef unsigned int dtcheck = dtr + dtcheck=getMatchedDataType(dt, dtr) + + + + if dtcheck in [CAFE_STRING]: + with nogil: + status=self._c_cafe.getString(handle, self.valStr) + if status==ICAFE_NORMAL: + return self.valStr + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + with nogil: + status=self._c_cafe.getLong(handle, self.valInt) + if status==ICAFE_NORMAL: + return self.valInt + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + with nogil: + status=self._c_cafe.getDouble(handle, self.valFloat) + + if status==ICAFE_NORMAL: + return self.valFloat + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + if self._c_cafe.isEnum(handle): + with nogil: + status=self._c_cafe.getString(handle, self.valStr) + if status==ICAFE_NORMAL: + return self.valStr + else: + with nogil: + status=self._c_cafe.getLong(handle, self.valInt) + if status ==ICAFE_NORMAL: + return self.valInt + else: + print ("This line in PyCafe def get should never appear!") + return None + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + return None + + + ################################################################################## + #END: def get(self, handlePV, dt) + ################################################################################## + + + ################################################################################## + def getIntList(self, handlePV): + return self.getList(handlePV, 'int') + + ################################################################################## + def getFloatList(self, handlePV): + return self.getList(handlePV, 'float') + + ################################################################################## + def getStrList(self, handlePV): + return self.getList(handlePV, 'str') + + ################################################################################## + def getList(self, handlePV, str dt='native'): + cdef str _METHOD_="getList(handlePV, str dt='native')" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + + cdef int status + cdef long dtr=0 + + status=self.hh.getDataTypeNative(handle, dtr) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return [None] + + elif dtr in [CAFE_NO_ACCESS, CAFE_TYPENOTCONN]: + if self._c_cafe.isChannelConnected(handle) is False: + self._c_cafe.getChannelInfo(handle,self.channelInfo) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,self.channelInfo.getCafeConnectionState() ) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=self.channelInfo.getCafeConnectionState(), _et=self.cs.code(self.channelInfo.getCafeConnectionState()),\ + _ei=self.cs.info(self.channelInfo.getCafeConnectionState())) + raise Exception(_cyCafeException) + return [None] + + #This paragraph should be superfluous + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,ICAFE_TYPENOTCONN) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=ICAFE_TYPENOTCONN, _et=self.cs.code(ICAFE_TYPENOTCONN), _ei=self.cs.info(ICAFE_TYPENOTCONN)) + raise Exception(_cyCafeException) + return [None] + + cdef unsigned int dtcheck = dtr + dtcheck=getMatchedDataType(dt, dtr) + + #print ("dtcheck", dtcheck) + + cdef unsigned int nelemNative =self.hh.getNelemNative (handle) + cdef unsigned int nelemClient =self.hh.getNelemClient (handle) + cdef unsigned int nelemRequest=self.hh.getNelemRequest(handle) + + + cdef unsigned int nelemMethod = nelemClient + + cdef dbr_string_t * valStringArray + cdef int * valIntArray + cdef double * valDoubleArray + + if dtcheck in [CAFE_STRING]: + + valStringArray = malloc( nelemMethod * sizeof(dbr_string_t)) + + with nogil: + status=self._c_cafe.getDbrStringArray(handle, valStringArray) + + ll=[] + for i in range(0,nelemMethod): + ll.append(valStringArray[i]) + free(valStringArray) + if status == ICAFE_NORMAL: + return ll + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + + valIntArray = malloc( nelemMethod * sizeof(int)) + + with nogil: + status=self._c_cafe.getLongArray(handle, valIntArray) + + ll=[] + for i in range(0, nelemMethod): + ll.append(valIntArray[i]) + free(valIntArray) + if status == ICAFE_NORMAL: + return ll + + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + + valDoubleArray = malloc( nelemMethod * sizeof(double)) + + with nogil: + status=self._c_cafe.getDoubleArray(handle, valDoubleArray) + + ll=[] + for i in range(0, nelemMethod): + ll.append(valDoubleArray[i]) + free(valDoubleArray) + if status == ICAFE_NORMAL: + return ll + + elif dtcheck==CAFE_ENUM: + + #if enum, string taken as native + if self._c_cafe.isEnum(handle): + valStringArray = malloc( nelemMethod * sizeof(dbr_string_t)) + + with nogil: + status=self._c_cafe.getDbrStringArray(handle, valStringArray) + + ll=[] + for i in range(0,nelemMethod): + ll.append(valStringArray[i]) + free(valStringArray) + if status ==ICAFE_NORMAL: + return ll + else: + valIntArray = malloc( nelemMethod * sizeof(int)) + with nogil: + status=self._c_cafe.getLongArray(handle, valIntArray) + + ll=[] + for i in range(0,nelemMethod): + ll.append(valIntArray[i]) + free(valIntArray) + if status ==ICAFE_NORMAL: + return ll + #Will not happen; already covered above + elif dtcheck in [CAFE_NO_ACCESS,CAFE_TYPENOTCONN]: + print ("Channel", self._c_cafe.getPVFromHandle(handle), " not connected") + return None + else: + print ("This line in PyCafe def getAsList should never appear!") + return None + + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.withExceptions is False: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return None + + + ################################################################################## + def getStrArray(self, handlePV, str art='memoryview'): + return self.getArray(handlePV, dt='str', art=art) + ################################################################################## + + ################################################################################## + def getIntArray(self, handlePV, str art='memoryview' ): + return self.getArray(handlePV, dt='int', art=art) + ################################################################################## + + ################################################################################## + def getFloatArray(self, handlePV, str art='memoryview'): + return self.getArray(handlePV, dt='float', art=art ) + ################################################################################## + + ################################################################################## + def getArray(self, handlePV, str dt='native', str art='memoryview'): + ################################################################################## + #Typed Memoryviews from K.W. Smith + #Cython has a C-level type the typed memoryview, that conceptually overlaps + #with the Python memoryiew and expands on it. A typed memory view is used to + #view (share) data from a buffer-producing object. + #A typed memoryview has a memory-view like interface and is easier to use than + #working with C-level buffers directly. And because a typed memoryview is designed + #to work with the buffer protocol it supports any buffer-producing object efficiently + #allowing sharing of data buffers without copying + #If we declare a typed memoryview with a single colon in each dimension's slot, + #the typed mv can acquire a buffer from an object if the same dimensionality and with + #either strided or contiguous packing. + #Declaring a C-contiguous typed memoryview: all dimensions except the last is specified + #with two colons followed by a literal 1. The mnemonic is that the last dimension has + #a unitary stride, i.e., is contiguous in memory, hence C contiguous + + cdef str _METHOD_="getArray" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + cdef: + short * i16val + + int * ival + double * dval + float * fval + dbr_string_t * sval + cnp.int16_t [::1] mvShort #C-contiguous + int [::1] mvInt #C-contiguous + double [::1] mvDouble #C-contiguous + float [::1] mvFloat #C-contiguous + #str [:,::1] mvStr + cnp.ndarray arr + long dtr=0 + int status + #cvarray mvDoubleArray + + unsigned int i + unsigned int ij + array.array a + + cnp.uint8_t [::1] mvUInt8 #C-contiguous + cnp.int8_t [::1] mvInt8 #C-contiguous + cnp.uint16_t [::1] mvUInt16 #C-contiguous + cnp.int16_t [::1] mvInt16 #C-contiguous + cnp.uint32_t [::1] mvUInt32 #C-contiguous + cnp.int32_t [::1] mvInt32 #C-contiguous + cnp.uint64_t [::1] mvUInt64 #C-contiguous + cnp.int64_t [::1] mvInt64 #C-contiguous + #cnp.float16_t [::1] mvFloat16 #C-contiguous + cnp.float32_t [::1] mvFloat32 #C-contiguous + cnp.float64_t [::1] mvFloat64 #C-contiguous + + + + #cdef PVDataHolder pvd + + status=self.hh.getDataTypeNative(handle, dtr) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return [None] + + elif dtr in [CAFE_NO_ACCESS, CAFE_TYPENOTCONN]: + if self._c_cafe.isChannelConnected(handle) is False: + self._c_cafe.getChannelInfo(handle,self.channelInfo) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,self.channelInfo.getCafeConnectionState() ) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=self.channelInfo.getCafeConnectionState(), _et=self.cs.code(self.channelInfo.getCafeConnectionState()),\ + _ei=self.cs.info(self.channelInfo.getCafeConnectionState())) + raise Exception(_cyCafeException) + return [None] + + #Likely to be superfluous + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,ICAFE_TYPENOTCONN) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=ICAFE_TYPENOTCONN, _et=self.cs.code(ICAFE_TYPENOTCONN), _ei=self.cs.info(ICAFE_TYPENOTCONN)) + raise Exception(_cyCafeException) + return [None] + + cdef unsigned int dtcheck = dtr + + dtcheck=getMatchedDataType(dt, dtr) + + cdef unsigned int nelemNative = self.hh.getNelemNative (handle) + cdef unsigned int nelemClient = self.hh.getNelemClient (handle) + cdef unsigned int nelemRequest = self.hh.getNelemRequest(handle) + + cdef unsigned int nelemMethod = nelemClient + cdef unsigned int nelemMemory = nelemClient #previously nelemNative - has to be at least size of nelemClient + + #print('native', self.hh.getNelemNative(handle)) + #print('client', self.hh.getNelemClient(handle)) + #print('request',self.hh.getNelemRequest(handle)) + + #print ('dtcheck', dtcheck) + + #cdef double [::1] cyarr_view + #The element type of a typed memoryview may be a numeric scalar type (int, float) + #It may be a ctypedef alias, or it may be a structured type declared with e.g. cdef struct + + if dtcheck in [CAFE_STRING, CAFE_ENUM]: + sval = malloc( nelemMemory * sizeof(dbr_string_t)) + with nogil: + status=self._c_cafe.getDbrStringArray(handle, sval) + + #http://cython.readthedocs.org/en/latest/src/tutorial/numpy.html + #Some data types are not yet supported, like boolean arrays and string arrays. + + locallist=[] + + if status==ICAFE_NORMAL: + + if art in ['numpy','ndarray','numpy.ndarray']: + + ###elif dt in ['np.string','np.str','np.unicode','np.string_','np.str_','np.unicode_']: + + mvStr = np.empty(nelemMethod, dtype=(np.str_,40)) + #mvStr=np.array(self.hh.getNelemRequest(handle), dtype='S40') + + for i in range(0, nelemMethod): + #print sval[i].decode('utf8'), i + mvStr[i]=str(sval[i]) #.decode('utf8') + #locallist.append(sval[i]) + + free(sval) + + return np.array(mvStr) + + elif art in ['memoryview','mv','memoryviewslice']: + mvStr = np.empty(nelemMethod, dtype=(np.str_,40), order='C') + + for ij in range(0, nelemMethod): + mvStr[ij]=str(sval[ij]) + free(sval) + + return memoryview(mvStr) + + elif art in ['array','array.array']: + print ("PyCafe.pyx getArray, 'array' type does not support array of strings; returning list") + #RETURNING LIST - DOES NOT SUPPORT array of strings; + #arrayArray=array.array('u', 'hello \u2641') + arrayArray=[] + for ij in range(0, nelemMethod): + arrayArray.append(str(sval[ij])) + free(sval) + return arrayArray + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_char_p*nelemMethod)() #c_wchar_p is unicode! + for ij in range(0, nelemMethod): + ctypesArray[ij]=(sval[ij]).encode('utf-8') + free(sval) + return ctypesArray + + else: + print("Unknown array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvStr = np.empty(nelemMethod, dtype=(np.str_,40), order='C') + for ij in range(0, nelemMethod): + mvStr[ij]=sval[ij] + free(sval) + + return mvStr + + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR]: + + + i16val = malloc(nelemMemory * sizeof(np.int16)) + with nogil: + status=self._c_cafe.getShortArray(handle, i16val) + + if status==ICAFE_NORMAL: + #np.empty preferred, else mvInt does not get correct value for first couple of array elements + + if art in ['numpy','ndarray','numpy.ndarray']: + + # ##mvInt=ival + # ##arr = np.ascontiguousarray(mvInt) + # ##set_base(arr, ival) + + if dt in ['np.short','np.int16','short','int16']: + mvShort = np.empty(nelemMethod, dtype=np.int16, order='C') + for ij in range(0, nelemMethod): + mvShort[ij]=i16val[ij] + free(i16val) + return np.array(mvShort) + + elif dt in ['np.int8','np.bool_','np.byte','bool','byte']: + mvInt8 = np.empty(nelemMethod, dtype=np.int8, order='C') + for ij in range(0, nelemMethod): + mvInt8[ij]=i16val[ij] + free(i16val) + return np.array(mvInt8) + + + elif dt in ['uchar','np.uint8']: + mvUInt8 = np.empty(nelemMethod, dtype=np.uint8, order='C') + for ij in range(0, nelemMethod): + mvUInt8[ij]=i16val[ij] + free(i16val) + return np.array(mvUInt8) + + else: + + mvShort = np.empty(nelemMethod, dtype=np.int16, order='C') + #mvShortNP = np.ndarray(buffer=np.array(i16val), dtype=np.int16, order='C') + for ij in range(0, nelemMethod): + mvShort[ij]=i16val[ij] + #mvShortNP=cnp.asarray(i16val) + + #aaa=np.full(nelemMethod,i16val[ij] + free(i16val) + + return memoryview(mvShort) + + elif art in ['array','array.array']: + + a=array.array('h') + for ij in range(0, nelemMethod): + a.append(i16val[ij]) + free(i16val) + return a + + elif art in ['ctypes', 'ctype']: + + ctypesArray16=(ctypes.c_int16*nelemMethod)() + for ij in range(0, nelemMethod): + ctypesArray16[ij]=i16val[ij] + free(i16val) + return ctypesArray16 + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvShort = np.empty(nelemMethod, dtype=np.int16, order='C') + for ij in range(0, nelemMethod): + mvShort[ij]=i16val[ij] + free(i16val) + + return mvShort + + + elif dtcheck in [CAFE_LONG]: + + ival = malloc( nelemMemory * sizeof(np.int32)) + with nogil: + status=self._c_cafe.getLongArray(handle, ival) + + if status==ICAFE_NORMAL: + #np.empty preferred, else mvInt does not get correct value for first couple of array elements + + #nelemMethod=self.hh.getnelemMethod(handle) + + if art in ['numpy','ndarray','numpy.ndarray']: + + +##elif dt in ['np.intc','np.int_','np.long','np.ulong','np.ushort','np.int32','np.int64','np.uint32','np.uint64']: + + + if dt in ['np.int32','int32']: + mvInt32 = np.empty(nelemMethod, dtype=np.int32, order='C') + for ij in range(0, nelemMethod): + mvInt32[ij]=ival[ij] + free(ival) + return np.array(mvInt32) # + elif dt in ['np.uint32','uint32']: + mvUInt32 = np.empty(nelemMethod, dtype=np.uint32, order='C') + for ij in range(0, nelemMethod): + mvUInt32[ij]=ival[ij] + free(ival) + return np.array(mvUInt32) + + + #elif dt in ['np.int64','int64']: + # mvInt64 = np.empty(nelemMethod, dtype=np.int64, order='C') + # for ij in range(0, nelemMethod): + # mvInt64[ij]=ival[ij] + # free(ival) + # return np.array(mvInt64) # + #elif dt in ['np.uint64','uint64']: + # mvUInt64 = np.empty(nelemMethod, dtype=np.uint64, order='C') + # for ij in range(0, nelemMethod): + # mvUInt64[ij]=ival[ij] + # free(ival) + # return np.array(mvUInt64) + + + else: + mvInt = np.empty(nelemMethod, dtype=np.int32, order='C') + for ij in range(0, nelemMethod): + mvInt[ij]=ival[ij] + free(ival) + return np.array(mvInt) #arr + + elif art in ['memoryview','mv','memoryviewslice']: + mvInt = np.empty(nelemMethod, dtype=np.int32, order='C') + for ij in range(0, nelemMethod): + mvInt[ij]=ival[ij] + free(ival) + return memoryview(mvInt) + + elif art in ['array','array.array']: + a=array.array('h') + for ij in range(0, nelemMethod): + a.append(ival[ij]) + free(ival) + return a + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_int32*nelemMethod)() + for ij in range(0, nelemMethod): + ctypesArray[ij]=ival[ij] + free(ival) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvInt = np.empty(nelemMethod, dtype=np.int32, order='C') + for ij in range(0, nelemMethod): + mvInt[ij]=ival[ij] + free(ival) + return mvInt + + + elif dtcheck in [CAFE_FLOAT]: + + fval = malloc( nelemMemory * sizeof(float)) + start=time.time() + with nogil: + status=self._c_cafe.getFloatArray(handle, fval) + + +# pvd.setNelem(self.hh.getnelemMethod(handle)) +# with nogil: +# status=self._c_cafe.get(handle, pvd) + + if status==ICAFE_NORMAL: + #nelemMethod=self.hh.getnelemMethod(handle) + + if art in ['numpy','ndarray','numpy.ndarray']: + + ##elif dt in ['np.float16','np.float32']: + + mvFloat = np.empty(nelemMethod, dtype=np.float32) + for ij in range(0, nelemMethod): + mvFloat[ij]=fval[ij] # pvd.getAsFloat(ij) + #arr=np.asarray(mvFloat) + + free(fval) + +#arr = np.ascontiguousarray(mvDouble) +#set_base(arr, dval) + + return np.array(mvFloat) #arr + + elif art in ['memoryview','mv','memoryviewslice']: + + + #Method A to return memory view + mvFloat = np.empty(nelemMethod, dtype=np.float32) + for ij in range(0, nelemMethod): + mvFloat[ij]=fval[ij] + + free(fval) + #memoryview(mvFloat).tolist() #tolist() only supports byte views + + return memoryview(mvFloat) + + + #Method B to return memory view + ''' + mvDoubleArray=cvarray(shape=(nelemMethod,), itemsize=sizeof(double), format="d") + cyarr_view=mvDoubleArray + for i in range(0, nelemMethod): + #mvDoubleArray AVOID COPY TO mvDoubel Array!! + cyarr_view[i]=dval[i] + + free(dval) + return cyarr_view + ''' + + elif art in ['array','array.array']: + + a=array.array('f') + + for ij in range(0, nelemMethod): + a.append(fval[ij]) + free(fval) + + return a + ''' + arrayArray=array.array('f') + for ij in range(0, nelemMethod): + arrayArray.append(fval[ij]) + free(fval) + return arrayArray + ''' + + ''' + cvFloatArray=cvarray(shape=(nelemMethod,), itemsize=sizeof(float), format="f") + cyarr_view=cvFloatArray + for i in range(0, nelemMethod): + #mvDoubleArray AVOID COPY TO mvDoubel Array!! + cyarr_view[i]=fval[i] + + free(fval) + return cyarr_view + ''' + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_float*nelemMethod)() + for ij in range(0, nelemMethod): + ctypesArray[ij]=fval[ij] + free(fval) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvFloat = np.empty(nelemMethod, dtype=np.float32) + for ij in range(0, nelemMethod): + mvFloat[ij]=fval[ij] + free(fval) + return mvFloat + + + elif dtcheck in [CAFE_DOUBLE]: + + #start=time.time() + dval = malloc( nelemMemory * sizeof(double)) + + with nogil: + #for ij in range(0, 10000): + status=self._c_cafe.getDoubleArray(handle, dval) + + if status==ICAFE_NORMAL: + #nelemMethod=self.hh.getnelemMethod(handle) + + if art in ['numpy','ndarray','numpy.ndarray']: + + + #elif dt in ['double', 'np.float_','np.float64']: + + #mvDouble=dval + mvDouble = np.empty(nelemMethod, dtype=np.float64) + for ij in range(0, nelemMethod): + mvDouble[ij]=dval[ij] + #arr=np.asarray(mvDouble) + free(dval) + #end=time.time() + #print (end - start) + return np.array(mvDouble) #arr + + elif art in ['memoryview','mv','memoryviewslice']: + + #Method A to return memory view + mvDouble = np.empty(nelemMethod, dtype=np.float64) + for ij in range(0, nelemMethod): + mvDouble[ij]=dval[ij] + free(dval) + #end=time.time() + #print (end - start) + return memoryview(mvDouble) + + elif art in ['array','array.array']: + a=array.array('d') + for ij in range(0, nelemMethod): + a.append(dval[ij]) + free(dval) + #end=time.time() + #print (end - start) + return a + + elif art in ['ctypes', "ctype"]: + ctypesArray=(ctypes.c_double*nelemMethod)() + for ij in range(0, nelemMethod): + ctypesArray[ij]=dval[ij] + free(dval) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvDouble = np.empty(nelemMethod, dtype=np.float64) + for ij in range(0, nelemMethod): + mvDouble[ij]=dval[ij] + free(dval) + return mvDouble + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return [None] + + ################################################################################## + #END: def getArray(self, handlePV, dt): + ################################################################################## + + + ################################################################################## + def getPVInt(self, handlePV): + return self.getPV(handlePV,'int') + ################################################################################## + + ################################################################################## + def getPVFloat(self, handlePV): + return self.getPV(handlePV,'float') + ################################################################################## + + ################################################################################## + def getPVStr(self, handlePV): + return self.getPV(handlePV,'str') + ################################################################################## + + ################################################################################## + def getPV(self, handlePV, str dt='native'): + ################################################################################## + cdef str _METHOD_="getPV" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + cdef int status + cdef PVDataHolder pvd = PVDataHolder(self.hh.getNelemNative(handle)) + + with nogil: + status=self._c_cafe.get(handle, pvd) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + + pvd_valnone=PVDataHolderToStruct(pvd, dt) + pvd_valnone.value[0]=None + return pvd_valnone + + return PVDataHolderToStruct(pvd, dt) + + ################################################################################## + #END def getPV(self, handlePV): + ################################################################################## + + + ################################################################################## + def getPVStrList(self, handleList): + return self.getPVList(handleList, dt='str') + ################################################################################## + + ################################################################################## + def getPVIntList(self, handleList): + return self.getPVList(handleList, dt='int') + ################################################################################## + + ################################################################################## + def getPVFloatList(self, handleList): + return self.getPVList(handleList, dt='float') + ################################################################################## + + ################################################################################## + def getPVList(self, handleList, str dt='native', cacheFlag=False): + ################################################################################## + cdef str _METHOD_="getPVList" + + if isinstance(handleList, (str,int,long)): + hl=[] + hl.append(handleList) + handleList=[] + handleList=hl + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be a 'list' of if handles, else if PVs")) + +#cdef unsigned int nelemTotal=0 +#for i in range(0, len(handleList)): +# nelemTotal+=self.hh.getNelemNative(handleList[i]) + +# cdef int size_cdu = sizeof(CAFE_DATATYPE_UNION) #16 is size of boost_shared_ptr (size 40) + +# cdef PVDataHolder * pvd = \ +# malloc( 100000000 + \ +# len(handleList) * sizeof(PVDataHolder) + nelemTotal*size_cdu) + + cdef vector[unsigned int] v + + #do this to avoid compiler warning messages + + for i in range(0, len(handleList)): + v.push_back(handleList[i]) + + cdef PVDataHolder * pvd = self._c_cafe.getPVData(v) + + for i in range(0, len(handleList)): + pvd[i].setNelem(self.hh.getNelemNative(handleList[i])) + #print " ", pvd[i].getNelem(), self.hh.getNelemNative(handleList[i]), i + + cdef int status + + if(cacheFlag): + status=self._c_cafe.getCachePVArray(v, pvd) + else: + with nogil: + status=self._c_cafe.getPVArray(v, pvd) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + for i in range(0, len(handleList)): + if (pvd[i].getStatus() != ICAFE_NORMAL): + print ("Handle=", handleList[i], "PV=", self.hh.getPVFromHandle(handleList[i]) ) + print ("with error status=", pvd[i].getStatus() ) + self._c_cafe.printStatusMessage(status) + print ("") + #raise Exception("EXCEPTION RAISED in PyCafe def getPVList. Status = %d" %status) + + + cdef unsigned int dtn + cdef unsigned int dtcheck + + pvdList=[] + cpdef pvdata p1 + + for i in range(0, len(handleList)): + dtn = pvd[i].getDataType(); + + dtcheck=getMatchedDataType(dt, dtn) + localList=[] + + if pvd[i].getNelem() == 1: + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + if self._c_cafe.isEnum(handleList[i]): + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_CHAR: + localList.append(pvd[i].getAsLong()) #( pvd[i].getAsChar()) + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) #no data + + else: + localListInner=[] + if dtcheck==CAFE_STRING: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsString(j)) + elif dtcheck==CAFE_SHORT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_FLOAT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + elif dtcheck==CAFE_ENUM: + for j in range(0, pvd[i].getNelem()): + #if enum, string taken as native + if self._c_cafe.isEnum(handleList[i]): + localListInner.append(pvd[i].getAsString(j)) + else: + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_CHAR: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j))#( pvd[i].getAsChar(j)) + elif dtcheck==CAFE_LONG: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_DOUBLE: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + else: + for j in range(0, pvd[i].getNelem()): + localListInner.append(0) #no data + localList.append(localListInner) + + p1 = pvdata() + p1.value=localList + p1.status=pvd[i].getStatus() + p1.nelem=pvd[i].getNelem() + p1.alarmStatus=pvd[i].getAlarmStatus() + p1.alarmSeverity=pvd[i].getAlarmSeverity() + + pvd._etsNorm=pvd[i].getEpicsTimeStampAsUInt32() + + ll=[] + ll.append((pvd[i]._etsNorm).secPastEpoch) + ll.append((pvd[i]._etsNorm).nsec) + p1.ts=ll + + pvd._etsDate=pvd[i].getEpicsTimeStampAsDate() + + ld=[] + ld.append( (pvd[i]._etsDate).year ) + ld.append( (pvd[i]._etsDate).mon ) + ld.append( (pvd[i]._etsDate).day ) + ld.append( (pvd[i]._etsDate).hour ) + ld.append( (pvd[i]._etsDate).min ) + ld.append( (pvd[i]._etsDate).sec ) + ld.append( (pvd[i]._etsDate).nsec ) + p1.tsDate=ld + + pvdList.append(p1) + + #free(pvd) + + + return pvdList, status + + + ################################################################################## + #END: def getPVList(self, handlePV, dt): + ################################################################################## + + ################################################################################## + def printStatusIfError(self, handleList, statusList): + ################################################################################## + cdef str _METHOD_="printStatusIfError" + + if isinstance(handleList,(str,int,long)): + handleListB=[] + handleListB.append(handleList) + handleList=[] + handleList=handleListB + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be a 'list' of if handles or if PVs")) + + if isinstance(statusList, (int,long)): + statusListB=[] + statusListB.append(statusList) + statusList=[] + statusList=statusListB + + if not isinstance(statusList, (list)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "Second input argument should be of ")) + + if not isinstance(statusList[0], (int, long, float)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "Second input argument should be a of ")) + + cdef vector[unsigned int] v + #do next step to avoid: + #warning: comparison between signed and unsigned integer expressions + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + return self._c_cafe.printStatusIfError(v, statusList) + + ################################################################################## + + ################################################################################## + def getAsyn(self, handleList): + ################################################################################## + cdef str _METHOD_="getAsyn" + + if isinstance(handleList, (str,int,long)): + handleListB=[] + handleListB.append(handleList) + handleList=[] + handleList=handleListB + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be a 'list' of if handles or if PVs")) + + cdef vector[unsigned int] v + cdef vector[int] vStatus + v.reserve (len(handleList)) + vStatus.reserve(len(handleList)) + + #do next step to avoid: + #warning: comparison between signed and unsigned integer expressions + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + #Need to copy to a vector since + #Coercion from Python not allowed without the GIL + with nogil: + status=self._c_cafe.getV(v, vStatus) + + if (status!=ICAFE_NORMAL): + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("Error/Warning from def getAsyn: ") + self._c_cafe.printStatusMessage(status) + + return status, vStatus + + + ################################################################################## + #END: def getAsyn(self, handleList): + ################################################################################## + + + + ################################################################################## + def waitForGetEvent(self,handlePV): + ################################################################################## + cdef str _METHOD_="waitForGetEvent(handlePV)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument, should be if handle, else if PV")) + with nogil: + status=self._c_cafe.waitForGetEvent(handle) + return status + ################################################################################## + #END: def waitForGetEvent(self, handlePV) + ################################################################################## + + + ################################################################################## + def waitForBundledEvents(self, handleList): + ################################################################################## + cdef str _METHOD_="waitForBundledEvents(self, handleList)" + + if isinstance(handleList, (str,int,long)): + handleListB=[] + handleListB.append(handleList) + handleList=[] + handleList=handleListB + + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def waitForBundledEvents. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def waitForBundledEvents. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + cdef vector[unsigned int] v + cdef vector[int] vRB + + v.reserve (len(handleList)) + vRB.reserve(len(handleList)) + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + + #Wait for bundle + with nogil: + status=self._c_cafe.waitForBundledEvents(v, vRB) + if (status!=ICAFE_NORMAL): + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("Error in def waitForBundledEvents: ") + self._c_cafe.printStatusMessage(status) + return status + return status, vRB + ################################################################################## + #END: def waitForBundledEvents(self, handleList): + ################################################################################## + + + + ################################################################################## + def getScalarArray(self, handleList, str dt='native', bint cacheFlag=False): + ################################################################################## + cdef str _METHOD_="getScalarArray(handleList, str dt='native')" + + #cdef float [::1] mvFloat #C-contiguous + + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getScalarList. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getScalarList. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + nelemPrevious= [] + + for i in range(0, len(handleList)): + nelemPrevious.append(self._c_cafe.setNelemToOne(handleList[i])) + + + #pack into numpy + cdef vector[unsigned int] v + cdef vector[int] vStatus + + v.reserve (len(handleList)) + vStatus.reserve(len(handleList)) + + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + cdef vector[int] vRB + status=ICAFE_NORMAL + + if (cacheFlag == False): + #Need to copy to a vector since + #Coercion from Python not allowed without the GIL + with nogil: + status=self._c_cafe.getV(v, vStatus) + + #Check for error code 704: ICAFE_WAITING_FOR_PREV_CALLBACK + #as this may mean we have a double handle instance. + #This is not a problem as such but if this is the case let's + #remove the error if the first getAsyn call for the handle in question was OK + #Functionality not yet moved to CAFE:: + #Required for when dt='native' + if (status != ICAFE_NORMAL): + for i in range(0,len(vStatus)): + if (vStatus[i]==ICAFE_WAITING_FOR_PREV_CALLBACK): + #getHandle + for j in range(0,(i-1)): + if(v[j]==v[i]): + if (vStatus[j]==ICAFE_NORMAL): + vStatus[i]=vStatus[j] + + #ca_poll() Not required as above will flush! + + #Wait for bundle + + with nogil: + statusBundle=self._c_cafe.waitForBundledEvents(v, vRB) + if (statusBundle!=ICAFE_NORMAL): + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("Error in def getScalarList: ") + self._c_cafe.printStatusMessage(statusBundle) + + cdef unsigned int dtcheck=CAFE_NOT_REQUESTED #native type not yet know + dtcheck=getMatchedDataType(dt, dtcheck) + + #print ("dt=", dt, "dtcheck=", dtcheck) + + if dtcheck in [CAFE_STRING]: + + self.vStr.clear() + self.vStr.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVStr(v, self.vStr, vStatus) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + ##localList=[] + ##statusList=[] + + #for i in range(0, len(self.vStr)): + #localList.append( self.vStr[i]) + return self.vStr, status, vStatus + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + + self.vInt.clear() + self.vInt.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVLong(v, self.vInt, vStatus) + + #for i in range(0, len(vStatus)): + #print ("status " , vStatus[i], " i", i, self._c_cafe.getPVFromHandle(handleList[i])) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + ##localList=[] + ##statusList=[] + + #for i in range(0, len(self.vInt)): + return self.vInt, status, vStatus + + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + + self.vFloat.clear() + self.vFloat.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVDouble(v, self.vFloat, vStatus) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + #for i in range(0, len(vStatus)): + # print ("status/// " , vStatus[i], " i", i, self._c_cafe.getPVFromHandle(handleList[i])) + #print ("overall status", status) + + ##localList=[] + ##statusList=[] + #Method A to return memory view + #mvFloat = np.empty(len(handleList), dtype=np.float32) + #for ij in range(0, len(handleList)): + # mvFloat[ij]=self.vFloat[ij] + #return mvFloat, status, vStatus + + + #for i in range(0, len(self.vFloat)): + return self.vFloat, status, vStatus + + #Native + + +#cdef unsigned int nelemTotal=0 +# for i in range(0, len(handleList)): +# nelemTotal+=self.hh.getNelemNative(handleList[i]) + + #cdef int size_cdu = sizeof(CAFE_DATATYPE_UNION) #16 is size of boost_shared_ptr (size 40) + + #Create temporary group from handleList + #Does group exist? + cdef PVDataHolder * pvd = self._c_cafe.getPVData(v) + + +#for i in range (0, len(handleList)): +# print pvd[i].getPVName(), pvd[i].getAsString(), " [",i,"]" +# print "" + + #print ("-----------------------------------------------------------------") + + #cdef PVDataHolder * pvd = \ + #malloc( 100000000 + \ + # len(handleList) * sizeof(PVDataHolder) + nelemTotal*size_cdu) + #print "size_pvd=", sizeof(PVDataHolder) + #print "sizeoverall", len(handleList) * sizeof(PVDataHolder)*10000 + + #Required to allocate memory for shared pointer + for i in range(0, len(handleList)): + pvd[i].setNelem(1) + + + statusNoWait=self._c_cafe.getCachePVArrayNoWait(v, pvd) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + statusList=[] + statusFlag=True + statusLocal=ICAFE_NORMAL + if (cacheFlag==True): + + #if status !=ICAFE_NORMAL: + # if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + # self._c_cafe.printStatusMessage(status) + #status=ICAFE_NORMAL + for i in range(0, len(handleList)): + statusList.append(pvd[i].getStatus()) + if pvd[i].getStatus() != ICAFE_NORMAL: + print ("Error in Element ", i, " from ", len(handleList), " in PyCafe def getScalarList") + print ("Handle= ", handleList[i], " PV=", self.hh.getPVFromHandle(handleList[i])) + print ("with error status=", pvd[i].getStatus()) + self._c_cafe.printStatusMessage(pvd[i].getStatus()) + if statusFlag: + statusLocal =pvd[i].getStatus() + statusFlag=False + + + # + #else: + # statusList.append(status) + + + #Wht not as a memoryView? + + cdef unsigned int dtn + + localList=[] + + for i in range(0, len(handleList)): + + dtn = pvd[i].getDataType(); + dtcheck = getMatchedDataType(dt, dtn) + + #print ("dt=", dt, "dtn=", dtn, "dtcheck=", dtcheck) + #print (pvd[i].getAsString()) + #print (pvd[i].getAsDouble()) + + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + + if self._c_cafe.isEnum(self.hh.getHandleFromPV(pvd[i].getPVName()))==1: + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + + elif dtcheck==CAFE_CHAR: + localList.append( pvd[i].getAsLong()) # pvd[i].getAsChar() + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_HIGH: + print ("def getScalarList:") + print ("Entering 0 for element", i, "as channel is not connected!") + + #print (" vstatus = ", vStatus[i] , " pvd[i].status ", pvd[i].getStatus() ) + + #free(pvd) + if (cacheFlag==True): + return localList, statusLocal, statusList + + return localList, status, vStatus # use vstatus instead of statusList (as cache is NoWait) + + ################################################################################## + #END: def getScalarList(self, handleList, dt): + ################################################################################## + + + + + + + + + + + + + + + + ################################################################################## + def getStrScalarList(self, handleList): + ################################################################################## + return self.getScalarList(handleList, dt='str') + + ################################################################################## + def getIntScalarList(self, handleList): + ################################################################################## + return self.getScalarList(handleList, dt='int') + + ################################################################################## + def getFloatScalarList(self, handleList): + ################################################################################## + return self.getScalarList(handleList, dt='float') + + + ################################################################################## + def getScalarList(self, handleList, str dt='native', bint cacheFlag=False): + ################################################################################## + cdef str _METHOD_="getScalarList(handleList, str dt='native')" + + #cdef float [::1] mvFloat #C-contiguous + + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getScalarList. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getScalarList. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + nelemPrevious= [] + + for i in range(0, len(handleList)): + nelemPrevious.append(self._c_cafe.setNelemToOne(handleList[i])) + + #c=self.hh.getNelemClient(handleList[i]) + #n=self.hh.getNelemNative(handleList[i]) + #r=self.hh.getNelemRequest(handleList[i]) + #print "c,n,r", c,n,r, "[",i,"]" + #c=self.hh.getNelemToRetrieveFromCache(handleList[i]) + #print "cache", c, "[",i,"]" + + #pack into vectors + cdef vector[unsigned int] v + cdef vector[int] vStatus + + v.reserve (len(handleList)) + vStatus.reserve(len(handleList)) + + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + cdef vector[int] vRB + status=ICAFE_NORMAL + + if (cacheFlag == False): + #Need to copy to a vector since + #Coercion from Python not allowed without the GIL + with nogil: + status=self._c_cafe.getV(v, vStatus) + + #Check for error code 704: ICAFE_WAITING_FOR_PREV_CALLBACK + #as this may mean we have a double handle instance. + #This is not a problem as such but if this is the case let's + #remove the error if the first getAsyn call for the handle in question was OK + #Functionality not yet moved to CAFE:: + #Required for when dt='native' + if (status != ICAFE_NORMAL): + for i in range(0,len(vStatus)): + if (vStatus[i]==ICAFE_WAITING_FOR_PREV_CALLBACK): + #getHandle + for j in range(0,(i-1)): + if(v[j]==v[i]): + if (vStatus[j]==ICAFE_NORMAL): + vStatus[i]=vStatus[j] + + #ca_poll() Not required as above will flush! + + #Wait for bundle + + with nogil: + statusBundle=self._c_cafe.waitForBundledEvents(v, vRB) + if (statusBundle!=ICAFE_NORMAL): + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("Error in def getScalarList: ") + self._c_cafe.printStatusMessage(statusBundle) + + cdef unsigned int dtcheck=CAFE_NOT_REQUESTED #native type not yet know + dtcheck=getMatchedDataType(dt, dtcheck) + + #print ("dt=", dt, "dtcheck=", dtcheck) + + if dtcheck in [CAFE_STRING]: + + self.vStr.clear() + self.vStr.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVStr(v, self.vStr, vStatus) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + ##localList=[] + ##statusList=[] + + #for i in range(0, len(self.vStr)): + #localList.append( self.vStr[i]) + return self.vStr, status, vStatus + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + + self.vInt.clear() + self.vInt.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVLong(v, self.vInt, vStatus) + + #for i in range(0, len(vStatus)): + #print ("status " , vStatus[i], " i", i, self._c_cafe.getPVFromHandle(handleList[i])) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + ##localList=[] + ##statusList=[] + + #for i in range(0, len(self.vInt)): + return self.vInt, status, vStatus + + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + + self.vFloat.clear() + self.vFloat.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVDouble(v, self.vFloat, vStatus) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + #for i in range(0, len(vStatus)): + # print ("status/// " , vStatus[i], " i", i, self._c_cafe.getPVFromHandle(handleList[i])) + #print ("overall status", status) + + ##localList=[] + ##statusList=[] + #Method A to return memory view + #mvFloat = np.empty(len(handleList), dtype=np.float32) + #for ij in range(0, len(handleList)): + # mvFloat[ij]=self.vFloat[ij] + #return mvFloat, status, vStatus + + + #for i in range(0, len(self.vFloat)): + return self.vFloat, status, vStatus + + #Native + + +#cdef unsigned int nelemTotal=0 +# for i in range(0, len(handleList)): +# nelemTotal+=self.hh.getNelemNative(handleList[i]) + + #cdef int size_cdu = sizeof(CAFE_DATATYPE_UNION) #16 is size of boost_shared_ptr (size 40) + + #Create temporary group from handleList + #Does group exist? + cdef PVDataHolder * pvd = self._c_cafe.getPVData(v) + + +#for i in range (0, len(handleList)): +# print pvd[i].getPVName(), pvd[i].getAsString(), " [",i,"]" +# print "" + + #print ("-----------------------------------------------------------------") + + #cdef PVDataHolder * pvd = \ + #malloc( 100000000 + \ + # len(handleList) * sizeof(PVDataHolder) + nelemTotal*size_cdu) + #print "size_pvd=", sizeof(PVDataHolder) + #print "sizeoverall", len(handleList) * sizeof(PVDataHolder)*10000 + + #Required to allocate memory for shared pointer + for i in range(0, len(handleList)): + pvd[i].setNelem(1) + + + statusNoWait=self._c_cafe.getCachePVArrayNoWait(v, pvd) + + for i in range(0, len(handleList)): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + statusList=[] + statusFlag=True + statusLocal=ICAFE_NORMAL + if (cacheFlag==True): + + #if status !=ICAFE_NORMAL: + # if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + # self._c_cafe.printStatusMessage(status) + #status=ICAFE_NORMAL + for i in range(0, len(handleList)): + statusList.append(pvd[i].getStatus()) + if pvd[i].getStatus() != ICAFE_NORMAL: + print ("Error in Element ", i, " from ", len(handleList), " in PyCafe def getScalarList") + print ("Handle= ", handleList[i], " PV=", self.hh.getPVFromHandle(handleList[i])) + print ("with error status=", pvd[i].getStatus()) + self._c_cafe.printStatusMessage(pvd[i].getStatus()) + if statusFlag: + statusLocal =pvd[i].getStatus() + statusFlag=False + + + # + #else: + # statusList.append(status) + + + #Wht not as a memoryView? + + cdef unsigned int dtn + + localList=[] + + for i in range(0, len(handleList)): + + dtn = pvd[i].getDataType(); + dtcheck = getMatchedDataType(dt, dtn) + + #print ("dt=", dt, "dtn=", dtn, "dtcheck=", dtcheck) + #print (pvd[i].getAsString()) + #print (pvd[i].getAsDouble()) + + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + + if self._c_cafe.isEnum(self.hh.getHandleFromPV(pvd[i].getPVName()))==1: + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + + elif dtcheck==CAFE_CHAR: + localList.append( pvd[i].getAsLong()) # pvd[i].getAsChar() + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_HIGH: + print ("def getScalarList:") + print ("Entering 0 for element", i, "as channel is not connected!") + + #print (" vstatus = ", vStatus[i] , " pvd[i].status ", pvd[i].getStatus() ) + + #free(pvd) + if (cacheFlag==True): + return localList, statusLocal, statusList + + return localList, status, vStatus # use vstatus instead of statusList (as cache is NoWait) + + ################################################################################## + #END: def getScalarList(self, handleList, dt): + ################################################################################## + + + ### # int alarmStatus=None, int alarmSev=None): + ################################################################################## + def getCompoundList(self, handleList, str dt='native', bint cacheFlag=False): + ################################################################################## + cdef str _METHOD_="getCompoundList(handleList, str dt='native')" + + if isinstance(handleList, (str)): + handleList=self.getHandlesFromWithinGroup(handleList) + else: + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getCompoundList. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def getCompoundList. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + #pack into vectors + cdef vector[unsigned int] v + cdef vector[int] vStatus + + cdef vector[int] vRB + + v.reserve (len(handleList)) + vStatus.reserve(len(handleList)) + + cdef bint flagCompound=False + + cdef unsigned int nelemLocal=1 + + for i in range(0, len(handleList)): + v.push_back(handleList[i]) #do this copy to avoid compiler warning messages + + + if (nelemLocal==1): + nelemLocal=self.hh.getNelemNative(handleList[i]) + if nelemLocal > 1: + flagCompound=True + + + if (cacheFlag == False): + + #Need to copy to a vector since + #Coercion from Python not allowed without the GIL + with nogil: + status=self._c_cafe.getV(v, vStatus) + + #ca_poll() Not required as above will flush! + + #Wait for bundle + + with nogil: + statusBundle=self._c_cafe.waitForBundledEvents(v, vRB) + if (statusBundle!=ICAFE_NORMAL): + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("Error in def getCompoundList: ") + self._c_cafe.printStatusMessage(statusBundle) + + cdef unsigned int dtcheck=CAFE_NOT_REQUESTED #native type not yet know + dtcheck=getMatchedDataType(dt, dtcheck) + + #Use Scalar + if flagCompound == False: + + if dtcheck in [CAFE_STRING]: + + self.vStr.clear() + self.vStr.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVStr(v, self.vStr, vStatus) + + #localList=[] + #statusList=[] + + #for i in range(0, len(self.vStr)): + #localList.append( self.vStr[i]) + return self.vStr, status, vStatus + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + + self.vInt.clear() + self.vInt.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVLong(v, self.vInt, vStatus) + + #localList=[] + #statusList=[] + + return self.vInt, status, vStatus + + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + + self.vFloat.clear() + self.vFloat.reserve(len(handleList)) + + with nogil: + status=self._c_cafe.getCacheVDouble(v, self.vFloat, vStatus) + + #localList=[] + #statusList=[] + + return self.vFloat, status, vStatus + + + #continue Can be a compound or native + #Native + #Create temporary group from handleList + #Does group exist? + cdef PVDataHolder * pvd = self._c_cafe.getPVData(v) + + + #Required to allocate memory for shared pointer + for i in range(0, len(handleList)): + pvd[i].setNelem(self.hh.getNelemClient(handleList[i])) + + statusNoWait=self._c_cafe.getCachePVArrayNoWait(v, pvd) + + + statusList=[] + statusFlag=True + statusLocal=ICAFE_NORMAL + if (cacheFlag==True): + + for i in range(0, len(handleList)): + statusList.append(pvd[i].getStatus()) + if pvd[i].getStatus() != ICAFE_NORMAL: + print ("Error in Element ", i, " from ", len(handleList), " in PyCafe def getCompundList") + print ("Handle= ", handleList[i], " PV=", self.hh.getPVFromHandle(handleList[i])) + print ("with error status=", pvd[i].getStatus()) + self._c_cafe.printStatusMessage(pvd[i].getStatus()) + if statusFlag: + statusLocal =pvd[i].getStatus() + statusFlag=False + + + + cdef unsigned int dtn + + localList=[] + + for i in range(0, len(handleList)): + + dtn = pvd[i].getDataType(); + dtcheck = getMatchedDataType(dt, dtn) + + if pvd[i].getNelem() == 1: + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + if self._c_cafe.isEnum(handleList[i])==1: + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + + elif dtcheck==CAFE_CHAR: + localList.append( pvd[i].getAsChar()) + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) #no data + else: + localListInner=[] + if dtcheck==CAFE_STRING: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsString(j)) + elif dtcheck==CAFE_SHORT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_FLOAT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + elif dtcheck==CAFE_ENUM: + + for j in range(0, pvd[i].getNelem()): + #if enum, string taken as native + if self._c_cafe.isEnum(handleList[i])==1: + localListInner.append(pvd[i].getAsString(j)) + else: + localListInner.append(pvd[i].getAsLong(j)) + + elif dtcheck==CAFE_CHAR: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) # pvd[i].getAsChar(j)) + elif dtcheck==CAFE_LONG: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_DOUBLE: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + else: + for j in range(0, pvd[i].getNelem()): + localListInner.append(0) #no data + localList.append(localListInner) + + + #free(pvd) + if (cacheFlag==True): + return localList, statusLocal, statusList + return localList, status, vStatus # use vstatus instead of statusList (as cache is NoWait) + + ################################################################################## + #END: def getCompoundList(self, handleList, dt): + ################################################################################## + + + + ################################################################################## + def getCompoundPVGroup(self, ghandleName, str dt='native'): + ################################################################################## + cdef str _METHOD_="getCompoundPVGroup(ghandleName, str dt='native')" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + + raise Exception ("EXCEPTION RAISED IN PyCafe def getCompoundPVGroup. \n\ +First input argument, should be if group handle, else if group name") + + handleList=[] + handleList=self.getHandlesFromWithinGroup(ghandle) + + localList=[] + statusList=[] + + cdef vector[unsigned int] hV + + for i in range(0, len(handleList)): + hV.push_back(handleList[i]) + + self.hh.setCafeDbrTypeV(hV, DBR_TIME) + + localList, status, statusList=self.getCompoundList(handleList, dt) + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + cdef PVDataHolder * pvd + pvd=pvg.getPVData() + + cdef pvdata p1 + + localListToStruct=[] + + cdef int groupStatus=ICAFE_NORMAL + + for i in range(0, pvg.getNPV()): + p1 = pvdata() + + #pvd[i].setDouble(localList[i]) + p1=PVDataHolderToStruct(pvd[i], dt) + + if not isinstance(localList[i],(list)): + ll=[] + ll.append(localList[i]) + p1.value=ll + else: + p1.value=localList[i] #put into List! + + p1.status=statusList[i] + + if groupStatus == ICAFE_NORMAL: + groupStatus=statusList[i] + + aStatSev=[] + aStatSev=self.getAlarmStatusSeverity(handleList[i]) + p1.alarmStatus=aStatSev[0] + p1.alarmSeverity=aStatSev[1] + + p1.ts=self.getTimeStamp(handleList[i]) + p1.tsDate=self.getTimeStampAsDate(handleList[i]) + + #p1.showMax(10) + localListToStruct.append(p1) + + #for j in range (0, len(localListToStruct)): + #localListToStruct[j].showMax(10) + + + + cpdef pvgroup pg + + pg = pvgroup() + + pg.pvdata=localListToStruct + #pg.pvdata[0].showMax(10) + + pg.npv=pvg.getNPV() + pg.name=pvg.getNameAsString() + pg.groupStatus=groupStatus #pvg.getStatusGroup() + pg.groupHandle=pvg.getGroupHandle() + + #pg.showMax(1) + + return pg + + ################################################################################## + #END: def getCompoundPVGroup(self, handleList, dt): + ################################################################################## + + + + ################################################################################## + def getStrCache(self, handlePV): + return self.getCache(handlePV,'str') + ################################################################################## + + ################################################################################## + def getIntCache(self, handlePV): + return self.getCache(handlePV,'int') + ################################################################################## + + ################################################################################## + def getFloatCache(self, handlePV): + return self.getCache(handlePV,'float') + ################################################################################## + + ################################################################################## + def getCache(self, handlePV, str dt='native'): + cdef str _METHOD_="getCache(handlePV, str dt='native')" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def getCache. \n\ +First input argument, should be if handle, else if PV") + + cdef long dtr=0 + status=self.hh.getDataTypeNative(handle, dtr) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + raise Exception("EXCEPTION RAISED in PyCafe def getCache. Status = %d" %status) + return None + + elif dtr in [CAFE_NO_ACCESS, CAFE_TYPENOTCONN]: + if self._c_cafe.isChannelConnected(handle) is False: + self._c_cafe.getChannelInfo(handle,self.channelInfo) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,self.channelInfo.getCafeConnectionState() ) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=self.channelInfo.getCafeConnectionState(), _et=self.cs.code(self.channelInfo.getCafeConnectionState()),\ + _ei=self.cs.info(self.channelInfo.getCafeConnectionState())) + raise Exception(_cyCafeException) + return [None] + + #Likely to be superfluous + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,ICAFE_TYPENOTCONN) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=ICAFE_TYPENOTCONN, _et=self.cs.code(ICAFE_TYPENOTCONN), _ei=self.cs.info(ICAFE_TYPENOTCONN)) + raise Exception(_cyCafeException) + return [None] + + + cdef unsigned int dtcheck = dtr + dtcheck=getMatchedDataType(dt, dtr) + + if dtcheck in [CAFE_STRING]: + status=self._c_cafe.getCacheString(handle, self.valStr) + if status==ICAFE_NORMAL: + return self.valStr + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR, CAFE_LONG]: + status=self._c_cafe.getCacheLong(handle, self.valInt) + if status==ICAFE_NORMAL: + return self.valInt + + elif dtcheck in [CAFE_FLOAT, CAFE_DOUBLE]: + status=self._c_cafe.getCacheDouble(handle, self.valFloat) + if status==ICAFE_NORMAL: + return self.valFloat + + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + if self._c_cafe.isEnum(handle): + status=self._c_cafe.getCacheString(handle, self.valStr) + if status==ICAFE_NORMAL: + return self.valStr + else: + status=self._c_cafe.getCacheLong(handle, self.valInt) + if status ==ICAFE_NORMAL: + return self.valInt + + else: + status=self.hh.getStatus(handle) + if status == ICAFE_NORMAL: + print ("This line in PyCafe def getCache should never appear!") + print ("Datatype unknown, returning value 0") + return 0 + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + + + ################################################################################## + + + + ################################################################################## + def getStrArrayCache(self, handlePV, str art='memoryview'): + return self.getArrayCache(handlePV, dt='str', art=art) + ################################################################################## + + ################################################################################## + def getIntArrayCache(self, handlePV, str art='memoryview'): + return self.getArrayCache(handlePV, dt='int', art=art) + ################################################################################## + + ################################################################################## + def getFloatArrayCache(self, handlePV, str art='memoryview'): + return self.getArrayCache(handlePV, dt='float', art=art) + ################################################################################## + + + ################################################################################## + def getArrayCache(self, handlePV, str dt='native', str art='memoryview'): + ################################################################################## + #Typed Memoryviews from K.W. Smith + #Cython has a C-level type the typed memoryview, that conceptually overlaps + #with the Python memoryiew and expands on it. A typed memory view is used to + #view (share) data from a buffer-producing object. + #A typed memoryview has a memory-view like interface and is easier to use than + #workingwith C-lvevel buffers directly. And because a typed memoryview is designed + #to work with the buffer protocol it supports any buffer-producing object efficiently + #allowing sharing of data buffers without copying + + cdef str _METHOD_="getArrayCache" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception("{} {} {}".format(self.exString, _METHOD_, \ + "First input argument should be if handle, else if PV")) + + cdef: + short * i16val + int * ival + double * dval + float * fval + dbr_string_t * sval + cnp.int16_t [::1] mvShort #C-contiguous + int [::1] mvInt #C-contiguous + double [::1] mvDouble #C-contiguous + float [::1] mvFloat #C-contiguous + #str [:,::1] mvStr + cnp.ndarray arr + long dtr=0 + int status + unsigned int i + unsigned int ij + + + status=self.hh.getDataTypeNative(handle, dtr) + + if status != ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return [None] + + + + elif dtr in [CAFE_NO_ACCESS, CAFE_TYPENOTCONN]: + if self._c_cafe.isChannelConnected(handle) is False: + self._c_cafe.getChannelInfo(handle,self.channelInfo) + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,self.channelInfo.getCafeConnectionState() ) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=self.channelInfo.getCafeConnectionState(), _et=self.cs.code(self.channelInfo.getCafeConnectionState()),\ + _ei=self.cs.info(self.channelInfo.getCafeConnectionState())) + raise Exception(_cyCafeException) + return [None] + + #Likely to be superfluous + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatus(handle,ICAFE_TYPENOTCONN) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=ICAFE_TYPENOTCONN, _et=self.cs.code(ICAFE_TYPENOTCONN), _ei=self.cs.info(ICAFE_TYPENOTCONN)) + raise Exception(_cyCafeException) + return [None] + + + cdef unsigned int nelemToRetrieveFromCache=self.hh.getNelemToRetrieveFromCache(handle) + + cdef unsigned int dtcheck = dtr + dtcheck=getMatchedDataType(dt, dtr) + + + #The elemnt type of a typed memoryview may be a numeric scalar type (int, float) + #It may be a ctypedef alias, or it may be a structured type declared with e.g. cdef struct + + if dtcheck in [CAFE_STRING, CAFE_ENUM]: + sval = malloc( nelemToRetrieveFromCache * sizeof(dbr_string_t)) + + status=self._c_cafe.getCacheDbrStringArray(handle, sval) + + locallist=[] + + if status==ICAFE_NORMAL: + + for i in range(0,nelemToRetrieveFromCache): + locallist.append(sval[i]) + + free(sval) + return locallist + + if status==ICAFE_NORMAL: + + if art in ['numpy','ndarray','numpy.ndarray']: + mvStr = np.empty(nelemToRetrieveFromCache, dtype=(np.str_,40)) + for i in range(0, nelemToRetrieveFromCache): + mvStr[i]=str(sval[i]) + free(sval) + + return mvStr + + elif art in ['memoryview','mv','memoryviewslice']: + mvStr = np.empty(nelemToRetrieveFromCache, dtype=(np.str_,40), order='C') + + for ij in range(0, nelemToRetrieveFromCache): + mvStr[ij]=str(sval[ij]) + free(sval) + + return mvStr + + elif art in ['array','array.array']: + print ("PyCafe.pyx getArray, 'array' type does not support array of strings; returning list") + #RETURNING LIST - DOES NOT SUPPORT array of strings; + + arrayArray=[] + for ij in range(0, nelemToRetrieveFromCache): + arrayArray.append(str(sval[ij])) + free(sval) + return arrayArray + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_char_p*nelemToRetrieveFromCache)() #c_wchar_p is unicode! + for ij in range(0, nelemToRetrieveFromCache): + ctypesArray[ij]=(sval[ij]).encode('utf-8') + free(sval) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvStr = np.empty(nelemToRetrieveFromCache, dtype=(np.str_,40), order='C') + for ij in range(0, nelemToRetrieveFromCache): + mvStr[ij]=sval[ij] + free(sval) + + return mvStr + + elif dtcheck in [CAFE_SHORT, CAFE_CHAR]: + + i16val = malloc( nelemToRetrieveFromCache * sizeof(np.int16)) + + status=self._c_cafe.getCacheShortArray(handle, i16val) + + if status==ICAFE_NORMAL: + #np.empty preferred, else mvInt does not get correct value for first couple of array elements + + if art in ['numpy','ndarray','numpy.ndarray']: + + mvShortNP = np.empty(nelemToRetrieveFromCache, dtype=np.int16, order='C') + + for ij in range(0, nelemToRetrieveFromCache): + mvShortNP[ij]=i16val[ij] + #arr=np.asarray(mvShort) + + free(i16val) + + return mvShortNP #arr + + elif art in ['memoryview','mv','memoryviewslice']: + mvShort = np.empty(nelemToRetrieveFromCache, dtype=np.int16, order='C') + + for ij in range(0, nelemToRetrieveFromCache): + mvShort[ij]=i16val[ij] + free(i16val) + + return mvShort + + elif art in ['array','array.array']: + arrayArray=array.array('h') + for ij in range(0, nelemToRetrieveFromCache): + arrayArray.append(i16val[ij]) + free(i16val) + return arrayArray + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_int16*nelemToRetrieveFromCache)() + for ij in range(0, nelemToRetrieveFromCache): + ctypesArray[ij]=i16val[ij] + free(i16val) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvShort = np.empty(nelemToRetrieveFromCache, dtype=np.int16, order='C') + for ij in range(0, nelemToRetrieveFromCache): + mvShort[ij]=i16val[ij] + free(i16val) + + return mvShort + + + elif dtcheck in [CAFE_LONG]: + + ival = malloc( nelemToRetrieveFromCache * sizeof(np.int32)) + + status=self._c_cafe.getCacheLongArray(handle, ival) + + if status==ICAFE_NORMAL: + + if art in ['numpy','ndarray','numpy.ndarray']: + + mvIntNP = np.empty(nelemToRetrieveFromCache, dtype=np.int32, order='C') + for ij in range(0, nelemToRetrieveFromCache): + mvIntNP[ij]=ival[ij] + free(ival) + return mvIntNP #arr + + elif art in ['memoryview','mv','memoryviewslice']: + mvInt = np.empty(nelemToRetrieveFromCache, dtype=np.int32, order='C') + for ij in range(0, nelemToRetrieveFromCache): + mvInt[ij]=ival[ij] + free(ival) + return mvInt + + elif art in ['array','array.array']: + arrayArray=array.array('h') + for ij in range(0, nelemToRetrieveFromCache): + arrayArray.append(ival[ij]) + free(ival) + return arrayArray + + elif art in ['ctypes', 'ctype']: + ctypesArray=(ctypes.c_int32*nelemToRetrieveFromCache)() + for ij in range(0, nelemToRetrieveFromCache): + ctypesArray[ij]=ival[ij] + free(ival) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvInt = np.empty(nelemToRetrieveFromCache, dtype=np.int32, order='C') + for ij in range(0, nelemToRetrieveFromCache): + mvInt[ij]=ival[ij] + free(ival) + return mvInt + + + elif dtcheck in [CAFE_FLOAT]: + + fval = malloc( nelemToRetrieveFromCache * sizeof(float)) + + status=self._c_cafe.getCacheFloatArray(handle, fval) + + if status==ICAFE_NORMAL: + + if art in ['numpy','ndarray','numpy.ndarray']: + + mvFloatNP = np.empty(nelemToRetrieveFromCache, dtype=np.float32) + for ij in range(0, nelemToRetrieveFromCache): + mvFloatNP[ij]=fval[ij] # pvd.getAsFloat(ij) + + free(fval) + + return mvFloatNP #arr + + elif art in ['memoryview','mv','memoryviewslice']: + + + #Method A to return memory view + mvFloat = np.empty(nelemToRetrieveFromCache, dtype=np.float32) + for ij in range(0, nelemToRetrieveFromCache): + mvFloat[ij]=fval[ij] + + free(fval) + return mvFloat + + + #Method B to return memory view + ''' + mvDoubleArray=cvarray(shape=(nelemToRetrieveFromCache,), itemsize=sizeof(double), format="d") + cyarr_view=mvDoubleArray + for i in range(0, nelemToRetrieveFromCache): + #mvDoubleArray AVOID COPY TO mvDoubel Array!! + cyarr_view[i]=dval[i] + + free(dval) + return cyarr_view + ''' + + + elif art in ['array','array.array']: + arrayArray=array.array('f') + for ij in range(0, nelemToRetrieveFromCache): + arrayArray.append(fval[ij]) + free(fval) + return arrayArray + + elif art in ['ctypes', "ctype"]: + ctypesArray=(ctypes.c_float*nelemToRetrieveFromCache)() + for ij in range(0, nelemToRetrieveFromCache): + ctypesArray[ij]=fval[ij] + free(fval) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvFloat = np.empty(nelemToRetrieveFromCache, dtype=np.float32) + for ij in range(0, nelemToRetrieveFromCache): + mvFloat[ij]=fval[ij] + free(fval) + return mvFloat + + + + elif dtcheck in [CAFE_DOUBLE]: + + dval = malloc( nelemToRetrieveFromCache * sizeof(double)) + + status=self._c_cafe.getDoubleArray(handle, dval) + + if status==ICAFE_NORMAL: + + if art in ['numpy','ndarray','numpy.ndarray']: + + + mvDoubleNP = np.empty(nelemToRetrieveFromCache, dtype=np.float64) + for ij in range(0, nelemToRetrieveFromCache): + mvDoubleNP[ij]=dval[ij] + + free(dval) + return mvDoubleNP #arr + + elif art in ['memoryview','mv','memoryviewslice']: + + #Method A to return memory view + mvDouble = np.empty(nelemToRetrieveFromCache, dtype=np.float64) + for ij in range(0, nelemToRetrieveFromCache): + mvDouble[ij]=dval[ij] + free(dval) + return mvDouble + + elif art in ['array','array.array']: + arrayArray=array.array('d') + for ij in range(0, nelemToRetrieveFromCache): + arrayArray.append(dval[ij]) + free(dval) + return arrayArray + + elif art in ['ctypes', "ctype"]: + ctypesArray=(ctypes.c_double*nelemToRetrieveFromCache)() + for ij in range(0, nelemToRetrieveFromCache): + ctypesArray[ij]=dval[ij] + free(dval) + return ctypesArray + + else: + print("Unknow array type in user request for art='",art,"'. Possible types are:") + print("memoryview, numpy, array, ctypes") + print("Returning memoryview") + mvDouble = np.empty(nelemToRetrieveFromCache, dtype=np.float64) + for ij in range(0, nelemToRetrieveFromCache): + mvDouble[ij]=dval[ij] + free(dval) + return mvDouble + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + return [None] + + ################################################################################## + #END: def getArrayCache(self, handlePV, dt): + ################################################################################## + + + + ################################################################################## + def getPVStrCache(self, handlePV): + return self.getPVCache(handlePV,'str') + ################################################################################## + + ################################################################################## + def getPVIntCache(self, handlePV): + return self.getPVCache(handlePV,'int') + ################################################################################## + + ################################################################################## + def getPVFloatCache(self, handlePV): + return self.getPVCache(handlePV,'float') + ################################################################################## + + ################################################################################## + def getPVCache(self, handlePV, str dt='native'): + ################################################################################## + + cdef str _METHOD_="getPVCache(handlePV, str dt='native'" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def getPVCache. \n \ + First input argument, should be if handle, else if PV") + + cdef PVDataHolder pvd + + pvd.setNelem(self.hh.getNelemToRetrieveFromCache(handle)) + + status=self._c_cafe.getCache(handle, pvd) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + pvd_valnone=PVDataHolderToStruct(pvd, dt) + pvd_valnone.value[0]=None + return pvd_valnone + + return PVDataHolderToStruct(pvd, dt) + + + ################################################################################## + #END def getPVCache(self, handlePV): + ################################################################################## + + + ################################################################################## + def getCtrl(self, handlePV, str dt='native'): + ################################################################################## + + cdef str _METHOD_="getCtrl(handlePV, str dt='native')" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def getCtrl. \n\ +First input argument, should be if handle, else if PV") + + + cdef PVCtrlHolder pvc + + pvc.setNelem(self.hh.getNelemClientCtrl(handle)) #do this dynamically + + cdef int status + with nogil: + status=self._c_cafe.getCtrl(handle, pvc) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + pvc_valnone=PVCtrlHolderToStruct(pvc, dt) + pvc_valnone.value[0]=None + return pvc_valnone + return PVCtrlHolderToStruct(pvc, dt) + + ################################################################################## + #END: def getCtrl(self, handlePV, dt='native'): + ################################################################################## + + + + ################################################################################## + def getCtrlCache(self, handlePV, str dt='native'): + ################################################################################## + cdef str _METHOD_="getCtrlCache(handlePV, str dt='native')" + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def getCtrlCache. \n\ +First input argument, should be if handle, else if PV") + + cdef PVCtrlHolder pvc + + pvc.setNelem(self.hh.getNelemToRetrieveFromCtrlCache(handle)) + + status=self._c_cafe.getCtrlCache(handle, pvc) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + pvc_valnone=PVCtrlHolderToStruct(pvc, dt) + pvc_valnone.value[0]=None + return pvc_valnone + + return PVCtrlHolderToStruct(pvc, dt) + + ################################################################################## + #END: def getCtrlCache(self, handlePV, dt='native'): + ################################################################################## + + + + ################################################################################## + def groupMonitorStop(self, ghandleName): + ################################################################################## + cdef str _METHOD_="groupMonitorStop(ghandleName)" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + cdef vector[int] vStatus + vStatus.reserve(pvg.getNPV()) + + with nogil: + status=self._c_cafe.groupMonitorStop(ghandle, vStatus) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + return status, vStatus + + + ################################################################################## + #END: def groupMonitorStop(self, ghandleName): + ################################################################################## + + def getMonitorPolicyVector(self, handlePV, _monid): + + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV, force=True) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def getMonitorPolicyVector \n\ +First input argument, should be if handle, else if PV") + + + cdef vector[MonitorPolicy] mpV + + self.hh.getMonitorPolicyVector(handle, mpV) + + + cdef monitorpolicy mp + + mp = monitorpolicy() + + cdef unsigned int i + + + + for i in range (0, mpV.size()): + + if mpV[i].getMonitorID()== _monid: + + + mp.monid=mpV[i].getMonitorID() + + mp.nelem=mpV[i].getNelem() + + mp.dataType=mpV[i].getDataType() + mp.userArgs=mpV[i].getUserArgs() + mp.dbrDataType=mpV[i].getDbrDataType() + mp.cafeDbrType=mpV[i].getCafeDbrType() + mp.mask=mpV[i].getMask() + mp.maskHasDBE_PROPERTY=mpV[i].maskHasDBE_PROPERTY() + mp.maskHasDBE_VALUE=mpV[i].maskHasDBE_VALUE() + mp.maskHasDBE_LOG=mpV[i].maskHasDBE_LOG() + mp.maskHasDBE_ALARM=mpV[i].maskHasDBE_ALARM() + break + + return mp + + + ################################################################################## + def groupMonitorStart(self, ghandleName, object cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM): + ########################################################################################## + cdef str _METHOD_="groupMonitorStart(ghandleName, object cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM)" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + + global monDictGlobal + + if dbr: + if dbr not in [DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL]: + print ("***Warning*** from groupMonitorStart for handle(orPV)=", ghandleName) + print ("dbr base type should be one of DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL") + print ("Assuming DBR_TIME") + dbr=DBR_TIME + + global py_cb + + cdef vector[MonitorPolicy] mpV + cdef unsigned int mpid + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + cdef MonitorPolicy * mp + mp=self._c_cafe.createMonitorPolicyArray(pvg.getNPV()) + + for i in range(0, pvg.getNPV()): + + mp[i].setMask(mask) + mp[i].setCafeDbrType(dbr) + + mpid=mp[i].getMonitorID() + + if cb: + a=inspect.getargspec(cb) + monDictGlobal[mpid]=cb + + if (len(a[0])==1): + mp[i].setUserArgs( mpid) + mp[i].setPyHandler() + else: + mp[i].setPyHandlerData() + + mpV.push_back(mp[i]) + + + cdef vector[int] vStatus + vStatus.reserve(pvg.getNPV()) + + with nogil: + status=self._c_cafe.groupMonitorStart(ghandle, vStatus, mpV) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + return status, vStatus + + ################################################################################## + + + ################################################################################## + def groupMonitorStartWithCBList(self, ghandleName, list cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM): + ########################################################################################## + cdef str _METHOD_="groupMonitorStartWithCBList(ghandleName, list cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM)" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + + global monDictGlobal + + if dbr: + if dbr not in [DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL]: + print ("***Warning*** from groupMonitorStartWithCBList for handle(orPV)=", ghandleName) + print ("dbr base type should be one of DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL") + print ("Assuming DBR_TIME") + dbr=DBR_TIME + + if not isinstance(cb,(list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def groupMonitorStartWithCBList. \n\ +Input cb should be of type and give the list of cb objects") + + global py_cb + + cdef vector[MonitorPolicy] mpV + cdef unsigned int mpid + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + if (len(cb) != pvg.getNPV() ): + print("No of group members is ", pvg.getNPV(), " while list of callback objects is", len(cb)) + raise Exception ("EXCEPTION RAISED IN PyCafe def groupMonitorStartWithCBList. \n\ +No of group members doe not match the length of callback object list") + + cdef MonitorPolicy * mp + mp=self._c_cafe.createMonitorPolicyArray(pvg.getNPV()) + + for i in range(0, pvg.getNPV()): + + mp[i].setMask(mask) + mp[i].setCafeDbrType(dbr) + + mpid=mp[i].getMonitorID() + + if cb[i]: + a=inspect.getargspec(cb[i]) + monDictGlobal[mpid]=cb[i] + + if (len(a[0])==1): + mp[i].setUserArgs( mpid) + mp[i].setPyHandler() + else: + mp[i].setPyHandlerData() + + mpV.push_back(mp[i]) + + cdef vector[int] vStatus + vStatus.reserve(pvg.getNPV()) + + with nogil: + status=self._c_cafe.groupMonitorStart(ghandle, vStatus, mpV) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + return status, vStatus + + ################################################################################## + + def getGroupStr(self, ghandleName): + return self.getGroup(ghandleName, 'str') + + def getGroupInt(self, ghandleName): + return self.getGroup(ghandleName, 'int') + + def getGroupFloat(self, ghandleName): + return self.getGroup(ghandleName, 'float') + + ################################################################################## + def getGroup(self, ghandleName, str dt='native'): + cdef str _METHOD_="getGroup(ghandleName, str dt='native')" + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + cdef PVDataHolder * pvd + pvd=pvg.getPVData(); + for i in range (0, pvg.getNPV()): + pvd[i].setHasAlarm(False) + pvd[i].setHasTS(False) + #pvd[i].setRule(False) + + pvg.setPVData(pvd) + ##pvd=pvg.getPVData(); + #print "get rule 0p", pvd[0].getRule() + #print "get rule 1p", pvd[1].getRule() + #print "get rule 2p", pvd[2].getRule() + ## + + with nogil: + status=self._c_cafe.groupGet(ghandle, pvg) + + if status == ECA_TIMEOUT : + print ("======================================================") + self._c_cafe.printStatusMessage(status) + print ("TIMEOUT in getGroup; swithing to getCompoundList") + print ("======================================================") + return self.getCompoundList(pvg.getNameAsString(), dt) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + #do not raise exception + #raise Exception("EXCEPTION RAISED in PyCafe def getGroup. Status = %d" %status) + #pvg.showMaxMax(5,10) + + pvd=pvg.getPVData() + + localList=[] + statusList=[] + cdef unsigned int dtn, dtcheck + + for i in range(0, pvg.getNPV()): + dtn = pvd[i].getDataType(); + + dtcheck=getMatchedDataType(dt, dtn) + + statusList.append(pvd[i].getStatus()) + + if pvd[i].getNelem() == 1: + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + + if self._c_cafe.isEnum(self.hh.getHandleFromPVWithinGroup(pvd[i].getPVName(),ghandle))==1: + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + + elif dtcheck==CAFE_CHAR: + localList.append( pvd[i].getAsChar()) + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) #no data + else: + localListInner=[] + if dtcheck==CAFE_STRING: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsString(j)) + elif dtcheck==CAFE_SHORT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_FLOAT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + elif dtcheck==CAFE_ENUM: + + for j in range(0, pvd[i].getNelem()): + #if enum, string taken as native + if self._c_cafe.isEnum(self.hh.getHandleFromPVWithinGroup(pvd[i].getPVName(),ghandle))==1: + localListInner.append(pvd[i].getAsString(j)) + else: + localListInner.append(pvd[i].getAsLong(j)) + + elif dtcheck==CAFE_CHAR: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) # pvd[i].getAsChar(j)) + elif dtcheck==CAFE_LONG: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_DOUBLE: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + else: + for j in range(0, pvd[i].getNelem()): + localListInner.append(0) #no data + localList.append(localListInner) + + + return localList, status, statusList + + ################################################################################## + #END: def getGroup(self, ghandleName, dt='native'): + ################################################################################## + + + + ################################################################################## + def getGroupCache(self, ghandleName, str dt='native'): + cdef str _METHOD_="getGroupCache(self, ghandleName, str dt='native')" + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + cdef PVDataHolder * pvd + + with nogil: + status=self._c_cafe.groupGetCache(ghandle, pvg) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + #do not raise exception + #raise Exception("EXCEPTION RAISED in PyCafe def getGroup. Status = %d" %status) + + pvd=pvg.getPVData() + + localList=[] + statusList=[] + cdef unsigned int dtn, dtcheck + + for i in range(0, pvg.getNPV()): + dtn = pvd[i].getDataType(); + + dtcheck=getMatchedDataType(dt, dtn) + + statusList.append(pvd[i].getStatus()) + + if pvd[i].getNelem() == 1: + if dtcheck==CAFE_STRING: + localList.append(pvd[i].getAsString()) + elif dtcheck==CAFE_SHORT: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_FLOAT: + localList.append(pvd[i].getAsDouble()) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + + if self._c_cafe.isEnum(self.hh.getHandleFromPVWithinGroup(pvd[i].getPVName(),ghandle))==1: + localList.append(pvd[i].getAsString()) + else: + localList.append(pvd[i].getAsLong()) + + elif dtcheck==CAFE_CHAR: + localList.append( pvd[i].getAsChar()) + elif dtcheck==CAFE_LONG: + localList.append(pvd[i].getAsLong()) + elif dtcheck==CAFE_DOUBLE: + localList.append(pvd[i].getAsDouble()) + else: + localList.append(0) #no data + else: + localListInner=[] + if dtcheck==CAFE_STRING: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsString(j)) + elif dtcheck==CAFE_SHORT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_FLOAT: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + elif dtcheck==CAFE_ENUM: + + for j in range(0, pvd[i].getNelem()): + #if enum, string taken as native + if self._c_cafe.isEnum(self.hh.getHandleFromPVWithinGroup(pvd[i].getPVName(),ghandle))==1: + localListInner.append(pvd[i].getAsString(j)) + else: + localListInner.append(pvd[i].getAsLong(j)) + + elif dtcheck==CAFE_CHAR: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) # pvd[i].getAsChar(j)) + elif dtcheck==CAFE_LONG: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsLong(j)) + elif dtcheck==CAFE_DOUBLE: + for j in range(0, pvd[i].getNelem()): + localListInner.append(pvd[i].getAsDouble(j)) + else: + for j in range(0, pvd[i].getNelem()): + localListInner.append(0) #no data + localList.append(localListInner) + + + return localList, status, statusList + + ################################################################################## + #END: def getGroup(self, ghandleName, dt='native'): + ################################################################################## + + + ################################################################################## + + def getPVGroupStr(self, ghandleName): + return self.getPVGroup(ghandleName, dt='str') + + def getPVGroupInt(self, ghandleName): + return self.getPVGroup(ghandleName, dt='int') + + def getPVGroupFloat(self, ghandleName): + return self.getPVGroup(ghandleName, dt='float') + + ################################################################################## + def getPVGroup(self, ghandleName, str dt='native'): + cdef str _METHOD_="getPVGroup(ghandleName, str dt='native')" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + #elif isinstance(ghandleName, (pvgroup)) == 1: + # print ("We have a PV Group ", type(ghandleName) ) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + cdef PVGroup pvg + cdef PVDataHolder * pvd + cdef int status + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + + pvd=pvg.getPVData() + + ''' + for i in range (0, pvg.getNPV()): + pvd[i].setHasAlarm(True) + pvd[i].setHasTS(True) + #pvd[i].setRule(True) + + pvg.setPVData(pvd) + ''' + + + with nogil: + status=self._c_cafe.groupGet(ghandle, pvg) + + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print("Error in PyCafe def getPVGroup. Status = %d" %status) + self._c_cafe.printStatusMessage(status) + #do not raise exception + #raise Exception("EXCEPTION RAISED in PyCafe def getPVGroup. Status = %d" %status) + + + if status == ECA_TIMEOUT: + print ("======================================================") + print ("TIMEOUT in getGroup; swithing to getCompoundPVGroup") + print ("======================================================") + return self.getCompoundPVGroup(ghandle,dt) + + pvd=pvg.getPVData() + + localList=[] + + for i in range(0, pvg.getNPV()): + #print(pvd[i].getAsString(0), " " , pvd[i].getStatus()) + #print(pvd[i].getEpicsTimeStampAsUInt32().secPastEpoch, " ", pvd[i].getEpicsTimeStampAsUInt32().nsec) + localList.append(PVDataHolderToStruct(pvd[i], dt)) + cpdef pvgroup pg + + pg = pvgroup() + + pg.pvdata=localList + + pg.npv=pvg.getNPV() + pg.name=pvg.getNameAsString() + pg.groupStatus=pvg.getStatusGroup() + pg.groupHandle=pvg.getGroupHandle() + + #pg.showMax(1) + + + return pg #localList, status + ################################################################################## + #END: def getPVGroup(self, ghandleName, str dt='native') + ################################################################################## + + + + ################################################################################## + def getPVGroupCache(self, ghandleName, str dt='native'): + cdef str _METHOD_="getPVGroupCache" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + #elif isinstance(ghandleName, (pvgroup)) == 1: + # print ("We have a PV Group ", type(ghandleName) ) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + cdef PVGroup pvg + cdef PVDataHolder * pvd + cdef int status + + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + print ("==============" ) + print (_METHOD_) + pvg.showMax(1) + + pvd=pvg.getPVData() + + status=self._c_cafe.groupGetCache(ghandle, pvg) + pvg.showMax(1) + print ("==============" ) + print(status, pvg.getStatusGroup() ) + print ("==============" ) + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print("Error in PyCafe def getPVGroupCache. Status = %d" %status) + self._c_cafe.printStatusMessage(status) + #do not raise exception + #raise Exception("EXCEPTION RAISED in PyCafe def getPVGroup. Status = %d" %status) + + + pvd=pvg.getPVData() + + localList=[] + + for i in range(0, pvg.getNPV()): + #print(pvd[i].getAsString(0), " " , pvd[i].getStatus()) + #print(pvd[i].getEpicsTimeStampAsUInt32().secPastEpoch, " ", pvd[i].getEpicsTimeStampAsUInt32().nsec) + localList.append(PVDataHolderToStruct(pvd[i], dt)) + cpdef pvgroup pg + + pg = pvgroup() + + pg.pvdata=localList + + pg.npv=pvg.getNPV() + pg.name=pvg.getNameAsString() + pg.groupStatus= pvg.getStatusGroup() + pg.groupHandle=pvg.getGroupHandle() + + return pg + ################################################################################## + #END: def getPVGroup(self, ghandleName, str dt='native') + ################################################################################## + + + + + + + + + + + ################################################################################## + def PVGroupValuesToList(self, pvgroup pg): + glist=[] + for i in range(0,pg.npv): + if len(pg.pvdata[i].value)==1: + glist.append(pg.pvdata[i].value[0]) + else: + iL=[] + for j in range(0, len(pg.pvdata[i].value)): + iL.append(pg.pvdata[i].value[j]) + glist.append(iL) + return glist + ################################################################################## + + + ################################################################################## + def groupMemberList(self, str gname): + cdef str _METHOD_="groupMemberList(self, str gname)" + cdef vector[string] pvlist + status=self._c_cafe.groupMemberList(gname, pvlist) + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + +#for i in range(0, len(pvlist)): +# memberList.append(pvlist[i]) + return pvlist + + + ################################################################################## + + def grouping(self, char * gname, list _pvlist): + cdef str _METHOD_="grouping(char * gname, list _pvlist)" + + cdef int status + status=self._c_cafe.groupDefine(gname, _pvlist) + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + cdef unsigned int ghandle=0 + cdef char * _gname=gname + + #try: + # self._c_cafe.groupOpen(_gname, ghandle) + #except: + # raise Exception("EXCEPTION RAISED in PyCafe def grouping. ERROR OPENING PVGROUP= %s" %_gname) + + + try: + status=self._c_cafe.groupOpen(_gname, ghandle) + except: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=ghandle, _pv=_gname, \ + _ec=ECA_ALLOCMEM, _et=self.cs.code(ECA_ALLOCMEM), _ei=self.cs.info(ECA_ALLOCMEM)) + raise Exception(_cyCafeException) + + if status != ICAFE_NORMAL: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=ghandle, _pv=_gname, \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + #cdef PVGroup pvg + #self._c_cafe.groupAttach(ghandle, pvg); + + cdef: + list localList + list statusList + + + if self._c_cafe.channelOpenGroupPolicy.getWhenToFlushSendBuffer()==FLUSH_NOW: + + localList,status,statusList= self.getGroup(ghandle) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + print ("") + print ("Error in def grouping for group named", _gname) + self._c_cafe.printStatusMessage(status) + print ("Analysing statusList[]...") + for i in range(0, len(statusList)): + if statusList[i] !=ICAFE_NORMAL: + print ("PV", _pvlist[i], "[",i,"]", " has error: ") + self._c_cafe.printStatusMessage(statusList[i]) + print ("") + return ghandle + + ################################################################################## + def defineGroup(self, char * gname, list _pvlist): + #cdef vector[const char *] pvlist + #for i in range(0, len(_pvlist)): + # pvlist.push_back(_pvlist[i]) + status=self._c_cafe.groupDefine(gname, _pvlist) + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + return status + ################################################################################## + + ################################################################################## + def groupOpen(self, char * gname): + cdef str _METHOD_="groupOpen(char * gname)" + + if isinstance(gname, (str)) == 0: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument should be for group name") + raise Exception(_cyCafeException) + + cdef unsigned int ghandle=0 + cdef char * _gname=gname + + try: + status=self._c_cafe.groupOpen(_gname, ghandle) + except: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=ghandle, _pv=_gname, \ + _ec=ECA_ALLOCMEM, _et=self.cs.code(ECA_ALLOCMEM), _ei=self.cs.info(ECA_ALLOCMEM)) + raise Exception(_cyCafeException) + + if status != ICAFE_NORMAL: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=ghandle, _pv=_gname, \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return ghandle + ################################################################################## + + + ################################################################################## + def groupClose(self, gHandleName): + cdef str _METHOD_="groupClose(gHandleName)" + + cdef unsigned int gHandle=0 + cdef str _gname=None + status=ICAFE_NORMAL + + if isinstance(gHandleName, (int,long)): + gHandle=gHandleName + elif isinstance(gHandleName, (str)): + _gname=gHandleName + gHandle=self.checkForGroupHandle(gHandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if group handle, else if group name") + raise Exception(_cyCafeException) + + if gHandle == 0: + status=ECAFE_INVALID_GROUP_HANDLE + + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=gHandle, _pv=_gname, \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + + status=self._c_cafe.groupClose(gHandle) + + + if status != ICAFE_NORMAL: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=gHandle, _pv=_gname, \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return status + ################################################################################## + + def getNoMonitors(self, handlePV): + cdef str _METHOD_="getNoMonitors(handlePV)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + return self.hh.getNmonitor(handle) + ################################################################################## + + ################################################################################## + def getMonitorIDs(self, handlePV): + cdef str _METHOD_="getMonitorIDs(handlePV)" + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + return self.hh.getMonitorIDs(handle); + ################################################################################## + + ########################################################################################## + def monitorStart(self, handlePV, object cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM): + cdef str _METHOD_="monitorStart(handlePV, object cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask=DBE_VALUE|DBE_LOG|DBE_ALARM)" + + pv=None + cdef int status=ICAFE_NORMAL + + #cdef pCallback my_callback + #my_callback=callbackHandlerMonitor + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + pv=handlePV + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + #py_cb_handle phase out; us fn in dictionary! + #global py_cb_handle + global py_cb + + #if cb: + # py_cb=cb + + #Does channel Exist? + if self._c_cafe.isValid(handle) == 0: + status=ECAFE_INVALID_HANDLE + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=pv, \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + return status; + + + cdef MonitorPolicy mp + cdef unsigned int mpid=mp.getMonitorID() + + mp.setMask(mask) + + + #print ("dbr=", dbr) + self._c_cafe.getChannelInfo(handle,self.channelInfo) + #print ("nativeDataType=", self.channelInfo.getDataType()) + + + if dbr in [DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL]: + #set Native Datatype first + mp.setDataType(self.channelInfo.getDataType()); + mp.setCafeDbrType(dbr) + #print ("def monitorStart ", mp.getCafeDbrType()) + #print ("def monitorStart ", mp.getDbrDataType()) + else: + print ("***Warning*** from monitorStart for handle=",handlePV) + print ("dbr base type should be one of DBR_PLAIN, DBR_STS, DBR_TIME, DBR_GR, DBR_CTRL") + print ("Assuming DBR_TIME") + mp.setDataType(self.channelInfo.getDataType()); + mp.setCafeDbrType(DBR_TIME) + + #if cb: + # + # print "py_cb_handle", len(a[0]) + + global monDictGlobal + #print ("MONITOR START (self, handlePV, object cb=None, DBR_TYPE dbr=DBR_TIME, unsigned int mask) ") + #print (monDictGlobal) + + if cb: + a=inspect.getargspec(cb) + #print (a) + if(len(a[0])==1): + ##py_cb_handle=cb + #self.monidList.append(mpid) + #self.moncbList.append(cb) + ##self.monDict[mpid]=cb + + monDictGlobal[mpid]=cb + #print (monDictGlobal) + #print self.monidList + #print self.moncbList + #print self.monDict + # + #print "mpid = ", mpid + mp.setUserArgs( mpid) + mp.setPyHandler() + #print (mp.getUserArgs()) + else: + py_cb=cb + mp.setPyHandlerData() + #else: + # mp.setHandler(callbackHandlerMonitor_wrapper) + + + with nogil: + status=self._c_cafe.monitorStart(handle,mp) + + + #Need this to allow a fraction of a second for the callback fn to be called + #if setPyHandler is used + if (self.getMonitorWhenToFlushSendBuffer == FLUSH_NOW): + time.sleep(0.01); + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + #do not raise an exception + #raise Exception("EXCEPTION RAISED in PyCafe def monitorStart. Status = %d" %status) + + return mpid + ################################################################################## + + + ################################################################################## + def monitorStop(self, handlePV, mpid=None): + cdef str _METHOD_="monitorStop(handlePV, mpid=None)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)) == 1: + handle=handlePV + elif isinstance(handlePV, (str)) == 1: + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + cdef int status + cdef unsigned int mpidUI + + global monDictGlobal + + if mpid: + if isinstance(mpid, (int,long)): + mpidUI=mpid + with nogil: + status=self._c_cafe.monitorStopWithID(handle, mpidUI) + time.sleep(0.01) + + if (status==ICAFE_NORMAL): + #index=self.monidList.index(mpidUI) + #self.monidList.remove(mpidUI) + #self.moncbList.remove(self.moncbList[index]) + #del self.monDict[mpidUI] + + #print (monDictGlobal) + #DELETE ENTRY ONLY IF IT EXISTS! + if monDictGlobal.has_key(mpidUI): + del monDictGlobal[mpidUI] + + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def monitorStop. \n\ +monitorPolicy ID (mpid) should be ") + else: + with nogil: + status=self._c_cafe.monitorStop(handle) + time.sleep(0.01) + + if (status==ICAFE_NORMAL): + + #print "size", self.hh.getNmonitor(handle) + mpidUIV=self.hh.getMonitorIDs(handle) + #print "size", mpidUIV.size() + + for i in range(0, mpidUIV.size()): + #index=self.monidList.index(mpidUIV[i]) + #self.monidList.remove(mpidUIV[i]) + #self.moncbList.remove(self.moncbList[index]) + #del self.monDict[mpidUIV[i]] + if monDictGlobal.has_key(mpidUIV[i]): + del monDictGlobal[mpidUIV[i]] + #monDictGlobal.remove(mpidUIV[i]) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + #do not raise an exception + #raise Exception("EXCEPTION RAISED in PyCafe def monitorStop. Status = %d" %status) + + return status + ################################################################################## + + + ################################################################################## + def monitorStopAll(self): + + cdef str _METHOD_="monitorStopAll()" + + global monDictGlobal + + cdef int status + with nogil: + status=self._c_cafe.monitorStopAll() + + #give plenty of time for monitors to stop! + + #print ("-----------------------------------------------------------------") + #print self.monidList + #print self.moncbList + #print self.monDict + #print (monDictGlobal) + #print ("------------------------------------------------------------------") + #del self.monidList[:] + #del self.moncbList[:] + #self.monDict.clear() + time.sleep(0.5) + monDictGlobal.clear() + + #print self.monDict + #print monDictGlobal + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def monitorStopAll. Status = %d" %status) + + return status + ################################################################################## + + + ################################################################################## + def set(self, handlePV, valSet): + cdef str _METHOD_="set(handlePV, valSet)" + + cdef unsigned int handle=0 + + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + + #CHECK FOR ALL DATA TYPES! + + cdef unsigned short valType=CAFE_STRING + cdef int status=ICAFE_NORMAL + cdef float valSetF + cdef double valSetD + cdef int valSetI + cdef long long valSetLL + cdef short valSetShort + cdef unsigned short valSetUShort + cdef unsigned char valSetChar + cdef string valSetS + cdef vector[double] vecD + cdef vector[float] vecF + cdef vector[short] vecShort + cdef vector[unsigned short] vecUShort + cdef vector[dbr_char_t] vecChar + cdef vector[dbr_long_t] vecI + cdef vector[string] vecS + + cdef unsigned int nLA=0 + + cdef tuple ctypesString = (ctypes.c_wchar, ctypes.c_char_p, ctypes.c_wchar_p) + cdef tuple ctypesUChar = (ctypes.c_char, ctypes.c_ubyte, ctypes.c_bool, ctypes.c_uint8, ) + cdef tuple ctypesShort = (ctypes.c_int16, ctypes.c_int8, ctypes.c_short, ctypes.c_byte) + cdef tuple ctypesUShort = (ctypes.c_uint16,ctypes.c_ushort) + cdef tuple ctypesInt = (ctypes.c_int, ctypes.c_int32, \ + ctypes.c_long, ctypes.c_size_t) + cdef tuple ctypesLongLong=(ctypes.c_uint, ctypes.c_uint32, ctypes.c_int64, ctypes.c_uint64, \ + ctypes.c_ulong,ctypes.c_ulonglong, ctypes.c_longdouble, \ + ctypes.c_longlong, ctypes.c_ssize_t, \ + ctypes.c_void_p, ctypes.c_voidp) + +# ctypes.c_char, ctypes.c_float, ctypes.c_double are separate + + + cdef tuple dtypesString = (np.str_, np.unicode_) + cdef tuple dtypesUChar = (np.ubyte, np.bool8, np.bool_, np.uint8) + cdef tuple dtypesShort = (np.byte, np.short, np.int8, np.int16) + cdef tuple dtypesUShort = (np.uint16,np.ushort) + cdef tuple dtypesInt = (np.int_, np.intc, np.int32, np.uintp) + cdef tuple dtypesLongLong= (np.uint, np.uintc, np.uint32, np.int64, np.uint64, \ + np.ulonglong, np.longlong, np.intp, np.uintp) + + cdef tuple dtypesFloat = (np.single, np.float16, np.float32) + cdef tuple dtypesDouble = (np.double, np.float_, np.float64) + + + #List: Major[0] Minor[1] Patch[2] 'final'[3] 0 [4] + #print "type= // ", type(valSet) + + cdef bint isGoodType=False + cdef bint isBytesType=False + +# print('set method', type(valSet)) + +# print("is instance array.array", isinstance(valSet, array.array)) +# print("is instance np.ndarray", isinstance(valSet, np.ndarray)) +# print("is instance memoryview", isinstance(valSet, memoryview)) +# print("is instance ctypes float", isinstance(valSet, ctypes.c_float)) +# print("is instance ctypes long ", isinstance(valSet, ctypes.c_long )) +# print("is instance ctypes int ", isinstance(valSet, ctypes.c_int )) +# print("is instance int ", isinstance(valSet, int )) +# print("is instance ctypes char_p ", isinstance(valSet, ctypes.c_char_p )) +# print("is instance ctypes Array ", isinstance(valSet, ctypes.Array )) +# print("is instance bytes ", isinstance(valSet, bytes )) +# print("is instance bytearrays ", isinstance(valSet, bytearray )) + # ctypes.c_buffer is of class function + # crtpes.c_buffer(b'abc') is of rtype ctypes.Array (!)) +#print("is instance ctypes buffer ", isinstance(valSet, ctypes.c_buffer )) # no such type! + +# dir(ctypes) +# print(type(valSet)) +# print (valSet.__class__) + cdef str classType = (valSet.__class__).__name__ + cdef str substringmv = "_memoryviewslice" + + + #print ("python Version", self.pythonVersion[0]) + + #Cython does not know about PyCafe._memoryviewslice + #if (isinstance(valSet,PyCafe._memoryviewslice)): + # print('OK for memoryview') + + if ( (self.pythonVersion[0] > 2 ) or (self.pythonVersion[0] == 2 and self.pythonVersion[1]>6) ) : + + if isinstance(valSet,(list, array.array, np.ndarray, cython.view.memoryview, memoryview, ctypes.Array)): + isGoodType=True + else: + if isinstance(valSet,(list, array.array, np.ndarray, ctypes.Array)): + isGoodType=True + + if (isGoodType==False): + if (substringmv in classType): + isGoodType=True + + #This is to cater for ctypes.c_buffer which is an instance of ctypes.Array + #where the element of the array is of type bytes - there need to match to cafe.setString + if isinstance(valSet,ctypes.Array): + if isinstance(valSet[0],bytes): + isGoodType=False + isBytesType=True + + #where the element of the array is of type bytes - there need to match to cafe.setSrting + + #if isinstance(valSet,np.ndarray): + #print ("np.ndarray is true") + #print (type(valSet[0])) + #if isinstance(valSet[0],bytes): + #isGoodType=False + #isBytesType=True + + #print("isGoodType ", isGoodType) + #print("isBytesType ", isBytesType) + + if isGoodType: + + #print('set method', type(valSet[0])) + + nLA=len(valSet) + + #Just check on first element if array.array etc.. + if not isinstance(valSet, (list)): + #if isinstance(valSet, (array.array, np.ndarray, cython.view.memoryview, memoryview)): + nLA=1 + + for i in range(0, nLA): + if isinstance(valSet[i],(str, bytes)): + valType=CAFE_STRING + break + elif isinstance(valSet[i],dtypesString): + valType=CAFE_STRING + break + elif isinstance(valSet[i],(float)): + valType=CAFE_DOUBLE + elif isinstance(valSet[i],(dtypesDouble)): + valType=CAFE_DOUBLE + elif isinstance(valSet[i],(dtypesFloat)): + valType=CAFE_FLOAT + elif isinstance(valSet[i],(long, int)): + valType=CAFE_LONG + elif isinstance(valSet[i], dtypesInt+dtypesLongLong+dtypesUChar): + valType=CAFE_LONG + elif isinstance(valSet[i], dtypesShort): + valType=CAFE_SHORT + elif isinstance(valSet[i], dtypesUShort): + valType=CAFE_USHORT + else: + + print("PyCafe.pyx: We do not cater for type ", type(valSet[i]), " and thus assume a string" ) + valType=CAFE_STRING + break + + # valSet to vector since + # coercion from Python not allowed without the GIL + if valType==CAFE_DOUBLE: + + vecD.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecD.push_back(valSet[i]) + with nogil: + status=self._c_cafe.setVDouble(handle, vecD) + + elif valType==CAFE_FLOAT: + + vecF.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecF.push_back(valSet[i]) + with nogil: + status=self._c_cafe.setVFloat(handle, vecF) + + elif valType==CAFE_LONG: + + vecI.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecI.push_back(valSet[i]) + + with nogil: + status=self._c_cafe.setVLong(handle, vecI) + + elif valType==CAFE_SHORT: + + vecShort.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecShort.push_back(valSet[i]) + + with nogil: + status=self._c_cafe.setVShort(handle, vecShort) + + elif valType==CAFE_USHORT: + + vecUShort.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecUShort.push_back(valSet[i]) + + with nogil: + status=self._c_cafe.setVUShort(handle, vecUShort) + + elif valType==CAFE_CHAR: + + vecChar.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecChar.push_back(valSet[i]) + + with nogil: + status=self._c_cafe.setVChar(handle, vecChar) + + elif valType==CAFE_STRING: + vecS.reserve(len(valSet)) + for i in range(0, len(valSet)): + vecS.push_back(str(valSet[i])) + with nogil: + status=self._c_cafe.setVString(handle, vecS) + + elif isBytesType: + #print("isBytesType") + valSetS=valSet.value + with nogil: + status=self._c_cafe.setString(handle, valSetS) + elif isinstance(valSet, (ctypes.c_char)): + #print("is ctypes.c_char") + #print(valSet.value) + #print(valSet.value.decode()) + valSetS=valSet.value.decode() + with nogil: + status=self._c_cafe.setString(handle, valSetS) + elif isinstance(valSet, (ctypes.c_float)): + valSetF=valSet.value + with nogil: + status=self._c_cafe.setFloat(handle, valSetF) + elif isinstance(valSet, (ctypes.c_double)): + valSetD=valSet.value + with nogil: + status=self._c_cafe.setDouble(handle, valSetD) + elif isinstance(valSet, ctypesInt): + #print("ctypesInt") + valSetI= valSet.value + with nogil: + status=self._c_cafe.setLong(handle, valSetI) + elif isinstance(valSet, ctypesLongLong): + #print("ctypesLongLong") + valSetLL=valSet.value + with nogil: + status=self._c_cafe.setLong(handle, valSetLL) + elif isinstance(valSet, ctypesShort): + #print("ctypesShort") + valSetShort=valSet.value + with nogil: + status=self._c_cafe.setShort(handle, valSetShort) + elif isinstance(valSet, ctypesUShort): + #print("ctypesUShort") + valSetUShort=valSet.value + with nogil: + status=self._c_cafe.setUShort(handle, valSetUShort) + elif isinstance(valSet, (ctypesString) ): + #print("ctypesString") + valSetS=valSet.value + with nogil: + status=self._c_cafe.setString(handle, valSetS) + elif isinstance(valSet, ctypesUChar): + #print("ctypesUChar") + valSetUChar=valSet.value + with nogil: + status=self._c_cafe.setChar(handle, valSetUChar) + elif isinstance(valSet, (float)): +#print("float type") + valSetD= valSet + with nogil: + status=self._c_cafe.setDouble(handle, valSetD) + elif isinstance(valSet, (int, long)): + #print("int/long type") + valSetI= valSet + with nogil: + status=self._c_cafe.setLong(handle, valSetI) + elif isinstance(valSet, (str)): +# print("str type") + valSetS=valSet + with nogil: + status=self._c_cafe.setString(handle, valSetS) + elif isinstance(valSet, (bytes,bytearray)): + #print("bytes,bytearray") + valSetS=valSet.decode('utf8') + with nogil: + status=self._c_cafe.setString(handle, valSetS) + elif isinstance(valSet, (unicode)): + #print("unicode") + valSetS=valSet + with nogil: + status=self._c_cafe.setString(handle, valSetS) + else: + print("PyCafe def set WARNING: DATA TYPE NOT SUPPORTED") + print("Input data (whether within a 'list','array.array','cython.view.memoryview','memoryview' \n\ +or not) should be of , or ") + type(valSet) + + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + if handle == 0: + self._c_cafe.printStatusMessage(status) + else: + self._c_cafe.printStatus(handle, status) + if self.haveExceptions: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_,_handle=handle, _pv=self._c_cafe.getPVFromHandle(handle), \ + _ec=status, _et=self.cs.code(status), _ei=self.cs.info(status)) + raise Exception(_cyCafeException) + + return status + ################################################################################## + #END def set(self, handlePV, valSet): + ################################################################################## + + + + ################################################################################## + def setScalarList(self, handleList, list valList): + cdef str _METHOD_="setScalarList(handleList, list valList)" + + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setScalarList. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setScalarList. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + if len(handleList) != len(valList): + raise Exception ("EXCEPTION RAISED IN PyCafe def setScalarList. \ +Length of handle list ", len(handleList), " does not match the length of data list ", len(valList)) + + nelemPrevious = [] + + #Better with PVDataHolder + cdef unsigned int nelemTotal=0 + for i in range(0, len(handleList)): + #nelemTotal+=self.hh.getNelemNative(handleList[i]) + nelemPrevious.append(self.hh.getNelemClient(handleList[i])) + + #cdef int size_cdu = sizeof(CAFE_DATATYPE_UNION) + + + #do this to avoid compiler warning messages + cdef vector[unsigned int] v + for i in range(0, len(handleList)): + v.push_back(handleList[i]) + + #Create temporary group from handleList + #Does group exist? + cdef PVDataHolder * pvd = self._c_cafe.getPVData(v) + + #cdef PVDataHolder * pvd = malloc( 100000000 + \ + # len(handleList) * sizeof(PVDataHolder) + nelemTotal*size_cdu) + + + for i in range(0, len(handleList)): + #pvd[i].val =malloc(sizeof(CAFE_DATATYPE_UNION)) + #pvd[i]= PVDataHolder(1); + pvd[i].setNelem(1) + + cdef unsigned short valType=CAFE_STRING + + for i in range(0, len(handleList)): + if isinstance(valList[i],(str)): + pvd[i].setString(valList[i]) + elif isinstance(valList[i],(float)): + pvd[i].setDouble(valList[i]) + elif isinstance(valList[i],(long, int)): + pvd[i].setInt(valList[i]) + else: + print ("This line in PyCafe def setScalarList should never appear!") + + cdef int status=ICAFE_NORMAL + with nogil: + status=self._c_cafe.setPVArray(v, pvd) + + for i in range(0, len(handleList)): + if (nelemPrevious[i] != 1): + self._c_cafe.setNelemToPrevious(handleList[i],nelemPrevious[i]) + + #return status for individual channels + statusList=[] + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + for i in range(0, len(handleList)): + if (pvd[i].getStatus() != ICAFE_NORMAL): + print ("Handle=", handleList[i], "PV=", self.hh.getPVFromHandle(handleList[i]) ) + print ("with error status=", pvd[i].getStatus()) + self._c_cafe.printStatusMessage(pvd[i].getStatus()) + print ("") + statusList.append(pvd[i].getStatus()) + + #free(pvd) + + return status, statusList + + ################################################################################## + + + + + ################################################################################## + def setCompoundList(self, handleList, list vectorList): + + cdef str _METHOD_="setCompoundList(handleList, list vectorList)" + + if isinstance(handleList, (str)): + handleList=self.getHandlesFromWithinGroup(handleList) + else: + if not isinstance(handleList, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setCompoundList. \n\ +First input argument, should be of handles or PVs") + + if isinstance(handleList[0], (str)): + handleList=self.checkForHandleList(handleList) + elif not isinstance(handleList[0], (int, long)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setCompoundList. \n\ +First input argument, should be a 'list' of if handles or if PVs") + + if len(handleList) != len(vectorList): + raise Exception ("EXCEPTION RAISED IN PyCafe def setCompoundList. \ +Length of handle list ", len(handleList), " does not match the length of data list ", len(vectorList)) + + + #do this to avoid compiler warning messages + cdef vector[unsigned int] v + cdef int i + + for i in range(0, len(handleList)): + v.push_back(handleList[i]) + + #Create temporary group from handleList + #Does group exist? + cdef PVDataHolder * pvdata = self._c_cafe.getPVData(v) + + + for i in range(0, len(vectorList)): + + #if not list + if isinstance(vectorList[i],(str)): + pvdata[i].setString(vectorList[i]) + + elif isinstance(vectorList[i],(float)): + pvdata[i].setDouble(vectorList[i]) + + elif isinstance(vectorList[i],(long, int)): + pvdata[i].setInt(vectorList[i]) + + elif isinstance(vectorList[i], (list)): + + #if list + valType=CAFE_INVALID_DATATYPE + pvdata[i].setNelem(len(vectorList[i])) + #for k in range(0, len(vectorList[i])): + #Just check on first element + for k in range(0,1): # can expand this to all elemnts or reduce to 1 + if isinstance(vectorList[i][k],(str)): + valType=CAFE_STRING + break + elif isinstance(vectorList[i][k],(float)): + valType=CAFE_DOUBLE + elif isinstance(vectorList[i][k],(long, int)): + if valType != CAFE_DOUBLE: + valType=CAFE_LONG + else: + valType=CAFE_STRING + break + + #check dt of first element + if valType==CAFE_DOUBLE: + pvdata[i].setVDouble(vectorList[i]) + elif valType==CAFE_LONG: + pvdata[i].setVInt (vectorList[i]) + elif valType==CAFE_STRING: + pvdata[i].setVString(vectorList[i]) + + else: + print ("This line in PyCafe def setCompoundList should never appear!") + raise Exception ("EXCEPTION RAISED IN PyCafe def setCompoundList. \n\ +Unknown data input; should be one of , , , ") + + #endForLoop + + cdef int status=ICAFE_NORMAL + with nogil: + status=self._c_cafe.setPVArray(v, pvdata) + + #return status for individual channels + statusList=[] + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + for i in range(0, len(handleList)): + if (pvdata[i].getStatus() != ICAFE_NORMAL): + print ("Handle=", handleList[i], "PV=", self.hh.getPVFromHandle(handleList[i]) ) + print ("with error status=", pvdata[i].getStatus()) + self._c_cafe.printStatusMessage(pvdata[i].getStatus()) + print ("") + #raise Exception("EXCEPTION RAISED in PyCafe def setCompoundList. Status = %d" %status) + statusList.append(pvdata[i].getStatus()) + + return status, statusList + + ################################################################################## + + + + + ################################################################################## + def setGroup(self, ghandleName, list vectorList): + + cdef str _METHOD_="setGroup(self, ghandleName, list vectorList)" + + cdef unsigned int ghandle=0 + if isinstance(ghandleName, (int,long)) == 1: + ghandle=ghandleName + elif isinstance(ghandleName, (str)) == 1: + ghandle=self.checkForGroupHandle(ghandleName) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument should be if group handle, else if group name") + raise Exception(_cyCafeException) + + cdef PVGroup pvg + + with nogil: + self._c_cafe.groupAttach(ghandle, pvg) + ### + #print ("len V", len(vectorList), " npv=", pvg.getNPV()) + + cdef PVDataHolder * pvdata = pvg.getPVData(); + + + for i in range(0, len(vectorList)): + + #if not list + if isinstance(vectorList[i],(str)): + pvdata[i].setString(vectorList[i]) + + elif isinstance(vectorList[i],(float)): + pvdata[i].setDouble(vectorList[i]) + + elif isinstance(vectorList[i],(long, int)): + pvdata[i].setInt(vectorList[i]) + + elif isinstance(vectorList[i], (list)): + + #if list + valType=CAFE_INVALID_DATATYPE + pvdata[i].setNelem(len(vectorList[i])) + #for k in range(0, len(vectorList[i])): + #Just check on first element + for k in range(0,1): # can expand this to all elemnts or reduce to 1 + if isinstance(vectorList[i][k],(str)): + valType=CAFE_STRING + break + elif isinstance(vectorList[i][k],(float)): + valType=CAFE_DOUBLE + elif isinstance(vectorList[i][k],(long, int)): + if valType != CAFE_DOUBLE: + valType=CAFE_LONG + else: + valType=CAFE_STRING + break + + #check dt of first element + if valType==CAFE_DOUBLE: + pvdata[i].setVDouble(vectorList[i]) + elif valType==CAFE_LONG: + pvdata[i].setVInt (vectorList[i]) + elif valType==CAFE_STRING: + pvdata[i].setVString(vectorList[i]) + + else: + + print ("PyCafe def setGroup: Unusual data type for element", i, " : ", type(vectorList[i])) + raise Exception ("EXCEPTION RAISED IN PyCafe def setGroup. \n\ +Unknown data input; should be one of , , , ") + + #endForLoop + + cdef int status=ICAFE_NORMAL + statusList=[] + pvg.setPVData(pvdata) + + + with nogil: + status=self._c_cafe.groupSet(ghandle, pvg) + + cdef PVDataHolder * pvd + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + #do not raise exception + #raise Exception("EXCEPTION RAISED in PyCafe def setGroup. Status = %d" %status) + + pvd=pvg.getPVData() + + for i in range(0, pvg.getNPV()): + statusList.append(pvd[i].getStatus()) + else: + statusList.append(status) + + return status, statusList + + ################################################################################## + #END: def setGroup(self, ghandleName, dt='native') + ################################################################################## + + + ################################################################################## + def setAndMatchMany(self, list handlePVSet, list valSet, list handlePVMatch, double tolerance, double timeout, bint printFlag): + cdef str _METHOD_="setAndMatchMany(list handlePVSet, list valSet, list handlePVMatch, double tolerance, double timeout, bint printFlag)" + + if not isinstance(handlePVSet, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setAndMatchMany. \n\ +First input argument, should be of handles or PVs") + + if not isinstance(valSet, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setAndMatchMany. \n\ +Second input argument, should be of scalar values") + + if not isinstance(handlePVMatch, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setAndMatchMany. \n\ +Third input argument, should be of handles or PVs") + + if (len(handlePVSet) != len(valSet)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setAndMatchMany. \n\ +Lengths of first (handlePVSet) and second (valSet) input lists must match!") + + if (len(handlePVSet) != len(handlePVMatch)): + raise Exception ("EXCEPTION RAISED IN PyCafe def setAndMatchMany. \n\ +Lengths of first (handlePVSet) and third (handlePVMatch) input lists must match!") + + + cdef vector[unsigned int] handleSet + handleSet.reserve(len(handlePVSet)) + + cdef vector[unsigned int] handleMatch + handleMatch.reserve(len(handlePVMatch)) + + cdef vector[double] valSetV + valSetV.reserve(len(valSet)) + + for i in range(0, len(handlePVSet)): + if isinstance(handlePVSet[i], (int,long)) == 1: + handleSet.push_back(handlePVSet[i]) + elif isinstance(handlePVSet[i], (str)) == 1: + handleSet.push_back(self.checkForHandle(handlePVSet)) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="ThandlePVSet list member should be if handle, else if PV") + raise Exception(_cyCafeException) + + for i in range(0, len(handlePVMatch)): + if isinstance(handlePVMatch[i], (int,long)) == 1: + handleMatch.push_back(handlePVMatch[i]) + elif isinstance(handlePVMatch[i], (str)) == 1: + handleMatch.push_back(self.checkForHandle(handlePVMatch)) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="handleMatch list member should be if handle, else if PV") + raise Exception(_cyCafeException) + + for i in range(0, len(valSet)): + valSetV.push_back(valSet[i]) + + cdef int status + + with nogil: + status=self._c_cafe.setAndMatchMany(handleSet, valSetV, handleMatch, tolerance, timeout, printFlag) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def setAndMatchMany. Status = %d" %status) + + return status + ################################################################################## + + + ################################################################################## + def setAndMatch(self, handlePVSet, double valSet, handlePVMatch, double tolerance, double timeout, bint printFlag): + cdef str _METHOD_="setAndMatch(handlePVSet, double valSet, handlePVMatch, double tolerance, double timeout, bint printFlag)" + + cdef unsigned int handleSet=0 + if isinstance(handlePVSet, (int,long)) == 1: + handleSet=handlePVSet + elif isinstance(handlePVSet, (str)) == 1: + handleSet=self.checkForHandle(handlePVSet) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + cdef unsigned int handleMatch=0 + if isinstance(handlePVMatch, (int,long)) == 1: + handleMatch=handlePVMatch + elif isinstance(handlePVMatch, (str)) == 1: + handleMatch=self.checkForHandle(handlePVMatch) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="Third input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + cdef int status + + with nogil: + status=self._c_cafe.setAndMatch(handleSet, valSet, handleMatch, tolerance, timeout, printFlag) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def setAndMatch. Status = %d" %status) + + return status + ################################################################################## + + + + + ################################################################################## + def matchMany(self, list valSet, list handlePVMatch, double tolerance, double timeout, bint printFlag): + cdef str _METHOD_="matchMany(self, list valSet, list handlePVMatch, double tolerance, double timeout, bint printFlag)" + + if not isinstance(valSet, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def matchMany. \n\ +Second input argument, should be of scalar values") + + if not isinstance(handlePVMatch, (list)): + raise Exception ("EXCEPTION RAISED IN PyCafe def matchMany. \n\ +Third input argument, should be of handles or PVs") + + if (len(valSet) != len(handlePVMatch)): + raise Exception ("EXCEPTION RAISED IN PyCafe def matchMany. \n\ +Lengths of first (handlePVSet) and third (handlePVMatch) input lists must match!") + + + cdef vector[unsigned int] handleMatch + handleMatch.reserve(len(handlePVMatch)) + + cdef vector[double] valSetV + valSetV.reserve(len(valSet)) + + for i in range(0, len(handlePVMatch)): + if isinstance(handlePVMatch[i], (int,long)) == 1: + handleMatch.push_back(handlePVMatch[i]) + elif isinstance(handlePVMatch[i], (str)) == 1: + handleMatch.push_back(self.checkForHandle(handlePVMatch)) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + + for i in range(0, len(valSet)): + valSetV.push_back(valSet[i]) + + cdef int status + + with nogil: + status=self._c_cafe.matchMany( valSetV, handleMatch, tolerance, timeout, printFlag) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def matchMany. Status = %d" %status) + + return status + ################################################################################## + + + ################################################################################## + def match(self, double valSet, handlePVMatch, double tolerance, double timeout, bint printFlag): + cdef str _METHOD_="match(double valSet, handlePVMatch, double tolerance, double timeout, bint printFlag)" + + cdef unsigned int handleMatch=0 + if isinstance(handlePVMatch, (int,long)) == 1: + handleMatch=handlePVMatch + elif isinstance(handlePVMatch, (str)) == 1: + handleMatch=self.checkForHandle(handlePVMatch) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + cdef int status + + with nogil: + status=self._c_cafe.match(valSet, handleMatch, tolerance, timeout, printFlag) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + raise Exception("EXCEPTION RAISED in PyCafe def match. Status = %d" %status) + + return status + ################################################################################## + + + ################################################################################## + def setNelemCtrl(self, handlePV, unsigned int nelem): + cdef str _METHOD_="setNelemCtrl(self, handlePV, unsigned int nelem)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def setNelemToRetrieveFromCacheToOne") + + #returns nelem + return self.hh.setNelemCtrl(handle, nelem) + + + + + ################################################################################## + def setNelem(self, handlePV, unsigned int nelem): + cdef str _METHOD_="setNelem(self, handlePV, unsigned int nelem)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def setNelemToRetrieveFromCacheToOne") + + #returns nelem + return self.hh.setNelem(handle, nelem) + + ################################################################################## + def setNelemToNative(self, handlePV): + cdef str _METHOD_="setNelemToNative(self, handlePV)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def setNelemToRetrieveFromCacheToOne") + + #returns nelem + return self.hh.setNelemToNative(handle) + + ################################################################################## + + def setNelemToRetrieveFromCacheToOne(self, handlePV): + cdef str _METHOD_="setNelemToRetrieveFromCacheToOne(self, handlePV)" + + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + _cyCafeException = CyCafeException(_type='cafe',_source=_METHOD_, \ + _ei="First input argument, should be if handle, else if PV") + raise Exception(_cyCafeException) + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def setNelemToRetrieveFromCacheToOne") + + #returns previous nelem + return self._c_cafe.setNelemToRetrieveFromCacheToOne(handle) + + ################################################################################## + def setNelemToRetrieveFromCache(self, handlePV, netrfc): + cdef unsigned int handle=0 + if isinstance(handlePV, (int,long)): + handle=handlePV + elif isinstance(handlePV, (str)): + handle=self.checkForHandle(handlePV) + else: + raise Exception ("EXCEPTION RAISED IN PyCafe def set. \n\ +First input argument, should be if handle, else if PV") + + + if handle == 0: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(ECAFE_INVALID_HANDLE) + raise Exception("EXCEPTION RAISED in PyCafe def setNelemToRetrieveFromCacheToOne") + + #returns new nelem + return self._c_cafe.setNelemToRetrieveFromCacheToPrevious(handle, netrfc) + + + ################################################################################## + def terminate(self): + with nogil: + self._c_cafe.terminate() + return + ################################################################################## + + +''' +################################################################################## + def prepareSFdbpm(self): +################################################################################## + self._c_cafe.prepareDBPM(self.bpmList, self.bpmHandles, self.bpmDev, self.bpmPos) #self.bpmPosDev) + + #for i in range(0, self.bpmDev.size()): + #print (self.bpmPos[i], self.bpmDev[i] ) + + if not self.dbpmInitialized: + self.dbpm= DBPMKeeper(self.bpmList,self.bpmHandles, self.bpmDev, self.bpmPos) #self.bpmPosDev) + self.dbpmInitialized=True + return + + + + +################################################################################## +#END def prepareSFdbpm(self) +################################################################################## + + +################################################################################## + def setSFdbpmBS(self, bint bsFlag=True): + return self.dbpm.setBS(bsFlag) + +################################################################################## + + +################################################################################## + def resetSFdbpmBS(self): + return self.dbpm.resetBS() + +################################################################################## + + +################################################################################## + def closeSFdbpmBS(self): + return self.dbpm.closeBS() + +################################################################################## + + +################################################################################## + def readSFdbpmOffsets(self): +################################################################################## + return self._c_cafe.readDBPMOffsets(self.dbpm) + +################################################################################## + def getSFdbpm(self): +################################################################################## + cdef str _METHOD_="getSFdbpm" + + cdef int status + + with nogil: + status=self._c_cafe.getDBPM(self.dbpm) + + if status !=ICAFE_NORMAL: + if PYCAFE_PRINT_LEVEL>=PYCAFE_PRINT_LOW: + self._c_cafe.printStatusMessage(status) + + return dbpmHolderToStruct(self.dbpm) + +################################################################################## +#END def getSFdbpm(self): +################################################################################## + + +################################################################################### + def getSFdbpmOffs_x(self): + return self.dbpm.getOffsetX() + + + def getSFdbpmOffs_y(self): + return self.dbpm.getOffsetY() + + +################################################################################### +################################################################################## +#END: cdef CAFE################################################################### +################################################################################## +''' diff --git a/PyCafeDefs.pxi b/PyCafeDefs.pxi new file mode 120000 index 0000000..3854182 --- /dev/null +++ b/PyCafeDefs.pxi @@ -0,0 +1 @@ +PyCafeDefs_api.pxi \ No newline at end of file diff --git a/PyCafeDefs_api.pxi b/PyCafeDefs_api.pxi new file mode 100644 index 0000000..7881944 --- /dev/null +++ b/PyCafeDefs_api.pxi @@ -0,0 +1,1336 @@ + + +#define threshold +cdef int PYCAFE_PRINT_HIGH=9 +cdef int PYCAFE_PRINT_MED=5 +cdef int PYCAFE_PRINT_LOW=1 + +cdef int PYCAFE_PRINT_LEVEL=PYCAFE_PRINT_MED + +ctypedef shared_ptr[vector [double]] vdouble_ptr +ctypedef shared_ptr[vector [float]] vfloat_ptr + +cdef object py_cb = None +cdef object py_cb_handle = None +cdef object py_cb_ctrl = None + + +''' +def py_cb(pvdata pv1, unsigned int handle, str pvname): + print ("PV:", pvname, " Handle:", handle + pv1.showMax(10) + return + +def py_cb_handle(unsigned int handle): + print (" Handle:", handle + return + +#Add control callback! + +def py_cb_ctrl(pvctrl c1, unsigned int handle, str pvname): + print ("PV:", pvname, " Handle:", handle + c1.showMax(10) + return +''' + +#***********api*************** + +cdef api void py_cb_wrapper(PVDataHolder pvd, unsigned int handle, string pvname) with gil: + cdef pvdata pv1 = PVDataHolderToStruct(pvd) + py_cb(pv1, handle, pvname) + with nogil: + return + +cdef api void py_cb_ctrl_wrapper(PVCtrlHolder pvc, unsigned int handle, string pvname) with gil: + cdef pvctrl c1 = PVCtrlHolderToStruct(pvc) + py_cb_ctrl(c1, handle, pvname) + with nogil: + return + +cdef api void py_cb_handle_wrapper(unsigned int handle) with gil: + + py_cb_handle(handle) + + with nogil: + return + +cdef api void py_cb_handle_monid_wrapper(unsigned int handle, unsigned long monid) with gil: + + if monDictGlobal.has_key(monid): + cbobjt=monDictGlobal[monid] + cbobjt(handle) + + with nogil: + return + + +cdef api void py_cb_handle_get_wrapper(unsigned int handle) with gil: + py_cb_handle_get(handle) + with nogil: + return + +cdef api void py_cb_handle_put_wrapper(unsigned int handle) with gil: + py_cb_handle_put(handle) + with nogil: + return + + +#***********api*************** +''' +cdef object callbackHandlerMonitor = None + + +cdef void callbackHandlerMonitor_wrapper(event_handler_args args) with gil: + handle= args.usr + py_cb_handle(handle) + with nogil: + return +''' +#Correct memory management a la KWSmith p.190 +cdef class _finalizer: + cdef void *_data + def __dealloc__(self): + if self._data is not NULL: + free(self._data) + return + +cdef void set_base(cnp.ndarray arr, void * carr): + cdef _finalizer fin = _finalizer() + fin._data = carr + cnp.set_array_base(arr, fin) + return + +cdef class CyCa: + cpdef readonly unsigned int CY_DBE_VALUE + cpdef readonly unsigned int CY_DBE_LOG + cpdef readonly unsigned int CY_DBE_ARCHIVE + cpdef readonly unsigned int CY_DBE_ALARM + cpdef readonly unsigned int CY_DBE_PROPERTY + cpdef readonly unsigned int CY_DBR_PRIMITIVE + cpdef readonly unsigned int CY_DBR_PLAIN + cpdef readonly unsigned int CY_DBR_STS + cpdef readonly unsigned int CY_DBR_TIME + cpdef readonly unsigned int CY_DBR_GR + cpdef readonly unsigned int CY_DBR_CTRL + cpdef readonly unsigned int CY_DBR_PUT + cpdef readonly unsigned int CY_DBR_STSACK + cpdef readonly unsigned int CY_DBR_CLASS + cpdef readonly unsigned int CY_DBR_NONE + cpdef readonly unsigned int CY_DBR_STRING #returns a NULL terminated string + cpdef readonly unsigned int CY_DBR_SHORT #returns an unsigned short + cpdef readonly unsigned int CY_DBR_INT #returns an unsigned short + cpdef readonly unsigned int CY_DBR_FLOAT #returns an IEEE floating point value + cpdef readonly unsigned int CY_DBR_ENUM #returns an unsigned short which is the enum item + cpdef readonly unsigned int CY_DBR_CHAR #returns an unsigned char + cpdef readonly unsigned int CY_DBR_LONG #returns an unsigned long + cpdef readonly unsigned int CY_DBR_DOUBLE #returns a double precision floating point number + cpdef readonly unsigned int CY_DBR_STS_STRING #returns a string status structure (dbr_sts_string) + cpdef readonly unsigned int CY_DBR_STS_SHORT #returns a short status structure (dbr_sts_short) + cpdef readonly unsigned int CY_DBR_STS_INT #returns a short status structure (dbr_sts_int) + cpdef readonly unsigned int CY_DBR_STS_FLOAT #returns a float status structure (dbr_sts_float) + cpdef readonly unsigned int CY_DBR_STS_ENUM #returns an enum status structure (dbr_sts_enum) + cpdef readonly unsigned int CY_DBR_STS_CHAR #returns a char status structure (dbr_sts_char) + cpdef readonly unsigned int CY_DBR_STS_LONG #returns a long status structure (dbr_sts_long) + cpdef readonly unsigned int CY_DBR_STS_DOUBLE #returns a double status structure (dbr_sts_double) + cpdef readonly unsigned int CY_DBR_TIME_STRING #returns a string time structure (dbr_time_string) + cpdef readonly unsigned int CY_DBR_TIME_SHORT #returns a short time structure (dbr_time_short) + cpdef readonly unsigned int CY_DBR_TIME_INT #returns a short time structure (dbr_time_short) + cpdef readonly unsigned int CY_DBR_TIME_FLOAT #returns a float time structure (dbr_time_float) + cpdef readonly unsigned int CY_DBR_TIME_ENUM #returns an enum time structure (dbr_time_enum) + cpdef readonly unsigned int CY_DBR_TIME_CHAR #returns a char time structure (dbr_time_char) + cpdef readonly unsigned int CY_DBR_TIME_LONG #returns a long time structure (dbr_time_long) + cpdef readonly unsigned int CY_DBR_TIME_DOUBLE #returns a double time structure (dbr_time_double) + cpdef readonly unsigned int CY_DBR_GR_STRING #returns a graphic string structure (dbr_gr_string) + cpdef readonly unsigned int CY_DBR_GR_SHORT #returns a graphic short structure (dbr_gr_short) + cpdef readonly unsigned int CY_DBR_GR_INT #returns a graphic short structure (dbr_gr_int) + cpdef readonly unsigned int CY_DBR_GR_FLOAT #returns a graphic float structure (dbr_gr_float) + cpdef readonly unsigned int CY_DBR_GR_ENUM #returns a graphic enum structure (dbr_gr_enum) + cpdef readonly unsigned int CY_DBR_GR_CHAR #returns a graphic char structure (dbr_gr_char) + cpdef readonly unsigned int CY_DBR_GR_LONG #returns a graphic long structure (dbr_gr_long) + cpdef readonly unsigned int CY_DBR_GR_DOUBLE #returns a graphic double structure (dbr_gr_double) + cpdef readonly unsigned int CY_DBR_CTRL_STRING #returns a control string structure (dbr_ctrl_int) + cpdef readonly unsigned int CY_DBR_CTRL_SHORT #returns a control short structure (dbr_ctrl_short) + cpdef readonly unsigned int CY_DBR_CTRL_INT #returns a control short structure (dbr_ctrl_int) + cpdef readonly unsigned int CY_DBR_CTRL_FLOAT #returns a control float structure (dbr_ctrl_float) + cpdef readonly unsigned int CY_DBR_CTRL_ENUM #returns a control enum structure (dbr_ctrl_enum) + cpdef readonly unsigned int CY_DBR_CTRL_CHAR #returns a control char structure (dbr_ctrl_char) + cpdef readonly unsigned int CY_DBR_CTRL_LONG #returns a control long structure (dbr_ctrl_long) + cpdef readonly unsigned int CY_DBR_CTRL_DOUBLE #returns a control double structure (dbr_ctrl_double) + + #cpdef readonly int CY_ECA_TIMEOUT + + + cpdef readonly int CY_ECA_NORMAL # 1 + cpdef readonly int CY_ECA_ALLOCMEM # 48 + cpdef readonly int CY_ECA_TOLARGE # 72 + cpdef readonly int CY_ECA_TIMEOUT # 80 + cpdef readonly int CY_ECA_BADTYPE # 114 + cpdef readonly int CY_ECA_INTERNAL # 142 + cpdef readonly int CY_ECA_GETFAIL # 152 + cpdef readonly int CY_ECA_PUTFAIL # 160 + cpdef readonly int CY_ECA_BADCOUNT # 176 + cpdef readonly int CY_ECA_BADSTR # 186 + cpdef readonly int CY_ECA_DISCONN # 192 + cpdef readonly int CY_ECA_DBLCHNL # 200 + cpdef readonly int CY_ECA_EVDISALLOW # 210 + cpdef readonly int CY_ECA_BADMONID # 242 + cpdef readonly int CY_ECA_BADMASK # 330 + cpdef readonly int CY_ECA_IODONE # 339 + cpdef readonly int CY_ECA_IOINPROGRESS # 347 + cpdef readonly int CY_ECA_BADSYNCGRP # 354 + cpdef readonly int CY_ECA_PUTCBINPROG # 362 + cpdef readonly int CY_ECA_NORDACCESS # 368 + cpdef readonly int CY_ECA_NOWTACCESS # 376 + cpdef readonly int CY_ECA_ANACHRONISM # 386 + cpdef readonly int CY_ECA_NOSEARCHADDR # 392 + cpdef readonly int CY_ECA_NOCONVERT # 400 + cpdef readonly int CY_ECA_BADCHID # 410 + cpdef readonly int CY_ECA_BADFUNCPTR # 418 + cpdef readonly int CY_ECA_ISATTACHED # 424 + cpdef readonly int CY_ECA_UNAVAILINSERV # 432 + cpdef readonly int CY_ECA_CHANDESTROY # 440 + cpdef readonly int CY_ECA_BADPRIORITY # 450 + cpdef readonly int CY_ECA_NOTTHREADED # 458 + cpdef readonly int CY_ECA_16KARRAYCLIENT # 464 + cpdef readonly int CY_ECA_CONNSEQTMO # 472 + cpdef readonly int CY_ECA_UNRESPTMO # 480 + + + cpdef readonly int ICAFE_CS_NEVER_CONN + cpdef readonly int ICAFE_CS_PREV_CONN + cpdef readonly int ICAFE_CS_CONN + cpdef readonly int ICAFE_CS_CLOSED + cpdef readonly int ICAFE_CS_DISCONN + cpdef readonly int ICAFE_CS_UNKNOWN + + cpdef readonly int ICAFE_TYPENOTCONN + cpdef readonly int ICAFE_RULE_FALSE + cpdef readonly int ICAFE_BADCOUNT + cpdef readonly int ICAFE_CALLBACK_NOT_YET_INVOKED + cpdef readonly int ICAFE_WAITING_FOR_PREV_CALLBACK + cpdef readonly int ICAFE_CACHE_EMPTY + cpdef readonly int ICAFE_CHANNEL_BLOCKING_POLICY_CONFLICT + cpdef readonly int ICAFE_MONITOR_DELAYED_AS_CONN_DOWN + cpdef readonly int ICAFE_HAS_MONITOR_GET_DONE_FROM_CACHE + cpdef readonly int ICAFE_SET_AND_GET_MISMATCH + + cpdef readonly int ICAFE_CA_OP_GET + cpdef readonly int ICAFE_CA_OP_PUT + cpdef readonly int ICAFE_CA_OP_CREATE_CHANNEL + cpdef readonly int ICAFE_CA_OP_ADD_EVENT + cpdef readonly int ICAFE_CA_OP_CLEAR_EVENT + cpdef readonly int ICAFE_CA_OP_OTHER + cpdef readonly int ICAFE_CA_OP_CONN_DOWN + cpdef readonly int ICAFE_CA_OP_CONN_UP + + cpdef readonly int ECAFE_LOAD_COLLECTION + cpdef readonly int ECAFE_LOAD_GROUP + + cpdef readonly int ICAFE_NORMAL + cpdef readonly int ICAFE_SUCCESS + + cpdef readonly int ECAFE_NODATA + cpdef readonly int ECAFE_INVALID_TYPE + cpdef readonly int ECAFE_BADCOUNT + cpdef readonly int ECAFE_BADSTR + cpdef readonly int ECAFE_BADTYPE + cpdef readonly int ECAFE_NO_CONVERT + cpdef readonly int ECAFE_NULLCONTEXT + cpdef readonly int ECAFE_NULLCHID + cpdef readonly int ECAFE_NULLEVID + cpdef readonly int ECAFE_UNKNOWN_COLLECTION + cpdef readonly int ECAFE_EMPTY_COLLECTION + cpdef readonly int ECAFE_COLLECTION_PREV_DEF + cpdef readonly int ECAFE_COLLECTION_INVALID_MEMBER + cpdef readonly int ECAFE_RULE_FALSE + cpdef readonly int ECAFE_UNKNOWN_GROUP + cpdef readonly int ECAFE_EMPTY_GROUP + cpdef readonly int ECAFE_GROUP_PREV_DEF + cpdef readonly int ECAFE_INVALID_HANDLE + cpdef readonly int ECAFE_INVALID_GROUP_HANDLE + cpdef readonly int ECAFE_NORDACCESS + cpdef readonly int ECAFE_NOWTACCESS + cpdef readonly int ECAFE_TIMEOUT + cpdef readonly int ECAFE_CANNOT_OPEN_FILE + cpdef readonly int ECAFE_INVALID_SWITCH_CASE + cpdef readonly int ECAFE_PVALIAS_PREV_DEF + cpdef readonly int ECAFE_PVALIAS_INVALID + cpdef readonly int ECAFE_PVNAME_PREV_DEF_AS_PVALIAS + cpdef readonly int ECAFE_DEVICE_ATTRIB_NOT_FOUND + cpdef readonly int ECAFE_HASH_UNIQUEID_EXISTS + cpdef readonly int ECAFE_WRONG_CA_CONTEXT + cpdef readonly int ECAFE_INVALID_CAFENUM_POLICY_TYPE + cpdef readonly int ECAFE_MAX_MONITORS_PER_CHAN_EXCEEDED + cpdef readonly int ECAFE_INVALID_ENUM_INDEX + cpdef readonly int ECAFE_PVGROUP_GROUPHANDLE_MISMATCH + cpdef readonly int ECAFE_TIMEOUT_SET_AND_MATCH + cpdef readonly int ECAFE_HANDLE_MISMATCH_SET_AND_MATCH + + #ctypedef enum ChannelRequestPolicyKind: + cpdef readonly unsigned int WITHOUT_CALLBACK + cpdef readonly unsigned int WITH_CALLBACK_DEFAULT + cpdef readonly unsigned int WITH_CALLBACK_USER_SUPPLIED + + #ChannelFlushSendBufferPolicyKind: + cpdef readonly unsigned int WITH_FLUSH_IO + cpdef readonly unsigned int WITH_PEND_IO + cpdef readonly unsigned int WITH_PEND_EVENT + cpdef readonly unsigned int WITH_POLL + + #ChannelWhenToFlushSendBufferPolicyKind: + cpdef readonly unsigned int FLUSH_AUTOMATIC + cpdef readonly unsigned int FLUSH_NOW + cpdef readonly unsigned int FLUSH_AFTER_EACH_CHANNEL_CREATION + cpdef readonly unsigned int FLUSH_AFTER_EACH_CHANNEL_SUBSCRIPTION + cpdef readonly unsigned int FLUSH_AFTER_EACH_MESSAGE + cpdef readonly unsigned int FLUSH_AFTER_EACH_GROUP_CREATION + cpdef readonly unsigned int FLUSH_DESIGNATED_TO_CLIENT + + + #ChannelGetCacheWaitPolicyKind: + cpdef readonly unsigned int GET_CACHE_NO_CHECK + cpdef readonly unsigned int GET_CACHE_NO_WAIT + cpdef readonly unsigned int GET_CACHE_NOW + cpdef readonly unsigned int GET_CACHE_WAIT + + #ChannelGetActionWhenMonitorPolicyKind: + cpdef readonly unsigned int GET_FROM_CACHE + cpdef readonly unsigned int GET_FROM_IOC + + + + #ChannelRequestDataTypePolicyKind: + cpdef readonly unsigned int NATIVE_DATATYPE + cpdef readonly unsigned int LOWEST_DATATYPE # The smaller in byte size of type requested and native datatype + + #ChannelWaitForResponsePolicyKind: + cpdef readonly unsigned int BLOCKING + cpdef readonly unsigned int WAIT + cpdef readonly unsigned int NON_BLOCKING + cpdef readonly unsigned int NO_WAIT + + #StatusMessageKind: + cpdef readonly unsigned int NO_MESSAGE + cpdef readonly unsigned int PRE_REQUEST + cpdef readonly unsigned int FROM_REQUEST + cpdef readonly unsigned int FROM_PEND + cpdef readonly unsigned int FROM_CALLBACK + cpdef readonly unsigned int FROM_MESSAGE + + #CallbackProgressKind: + cpdef readonly unsigned int NOT_INITIATED + cpdef readonly unsigned int PENDING + cpdef readonly unsigned int COMPLETE + + + + def __cinit__(self): + + #self.CY_ECA_TIMEOUT =ECA_TIMEOUT + + self.CY_ECA_NORMAL =ECA_NORMAL + self.CY_ECA_ALLOCMEM =ECA_ALLOCMEM + self.CY_ECA_TOLARGE =ECA_TOLARGE + self.CY_ECA_TIMEOUT =ECA_TIMEOUT + self.CY_ECA_BADTYPE =ECA_BADTYPE + self.CY_ECA_INTERNAL =ECA_INTERNAL + self.CY_ECA_GETFAIL =ECA_GETFAIL + self.CY_ECA_PUTFAIL =ECA_PUTFAIL + self.CY_ECA_BADCOUNT =ECA_BADCOUNT + self.CY_ECA_BADSTR =ECA_BADSTR + self.CY_ECA_DISCONN =ECA_DISCONN + self.CY_ECA_DBLCHNL =ECA_DBLCHNL + self.CY_ECA_EVDISALLOW =ECA_EVDISALLOW + self.CY_ECA_BADMONID =ECA_BADMONID + self.CY_ECA_BADMASK =ECA_BADMASK + self.CY_ECA_IODONE =ECA_IODONE + self.CY_ECA_IOINPROGRESS =ECA_IOINPROGRESS + self.CY_ECA_BADSYNCGRP =ECA_BADSYNCGRP + self.CY_ECA_PUTCBINPROG =ECA_PUTCBINPROG + self.CY_ECA_NORDACCESS =ECA_NORDACCESS + self.CY_ECA_NOWTACCESS =ECA_NOWTACCESS + self.CY_ECA_ANACHRONISM =ECA_ANACHRONISM + self.CY_ECA_NOSEARCHADDR =ECA_NOSEARCHADDR + self.CY_ECA_NOCONVERT =ECA_NOCONVERT + self.CY_ECA_BADCHID =ECA_BADCHID + self.CY_ECA_BADFUNCPTR =ECA_BADFUNCPTR + self.CY_ECA_ISATTACHED =ECA_ISATTACHED + self.CY_ECA_UNAVAILINSERV =ECA_UNAVAILINSERV + self.CY_ECA_CHANDESTROY =ECA_CHANDESTROY + self.CY_ECA_BADPRIORITY =ECA_BADPRIORITY + self.CY_ECA_NOTTHREADED =ECA_NOTTHREADED + self.CY_ECA_16KARRAYCLIENT=ECA_16KARRAYCLIENT + self.CY_ECA_CONNSEQTMO =ECA_CONNSEQTMO + self.CY_ECA_UNRESPTMO =ECA_UNRESPTMO + + + + self.ICAFE_NORMAL =ICAFE_NORMAL + self.ICAFE_SUCCESS =ICAFE_SUCCESS + + self.ICAFE_CS_NEVER_CONN =ICAFE_CS_NEVER_CONN + self.ICAFE_CS_PREV_CONN =ICAFE_CS_PREV_CONN + self.ICAFE_CS_CONN =ICAFE_CS_CONN + self.ICAFE_CS_CLOSED =ICAFE_CS_CLOSED + self.ICAFE_CS_DISCONN =ICAFE_CS_DISCONN + self.ICAFE_CS_UNKNOWN =ICAFE_CS_UNKNOWN + + self.ICAFE_TYPENOTCONN =ICAFE_TYPENOTCONN + self.ICAFE_RULE_FALSE =ICAFE_RULE_FALSE + self.ICAFE_BADCOUNT =ICAFE_BADCOUNT + self.ICAFE_CALLBACK_NOT_YET_INVOKED =ICAFE_CALLBACK_NOT_YET_INVOKED + self.ICAFE_WAITING_FOR_PREV_CALLBACK =ICAFE_WAITING_FOR_PREV_CALLBACK + self.ICAFE_CACHE_EMPTY =ICAFE_CACHE_EMPTY + self.ICAFE_CHANNEL_BLOCKING_POLICY_CONFLICT=ICAFE_CHANNEL_BLOCKING_POLICY_CONFLICT + self.ICAFE_MONITOR_DELAYED_AS_CONN_DOWN =ICAFE_MONITOR_DELAYED_AS_CONN_DOWN + self.ICAFE_HAS_MONITOR_GET_DONE_FROM_CACHE =ICAFE_HAS_MONITOR_GET_DONE_FROM_CACHE + self.ICAFE_SET_AND_GET_MISMATCH =ICAFE_SET_AND_GET_MISMATCH + + + self.ICAFE_CA_OP_GET =ICAFE_CA_OP_GET + self.ICAFE_CA_OP_PUT =ICAFE_CA_OP_PUT + self.ICAFE_CA_OP_CREATE_CHANNEL =ICAFE_CA_OP_CREATE_CHANNEL + self.ICAFE_CA_OP_ADD_EVENT =ICAFE_CA_OP_ADD_EVENT + self.ICAFE_CA_OP_CLEAR_EVENT =ICAFE_CA_OP_CLEAR_EVENT + self.ICAFE_CA_OP_OTHER =ICAFE_CA_OP_OTHER + self.ICAFE_CA_OP_CONN_DOWN =ICAFE_CA_OP_CONN_DOWN + self.ICAFE_CA_OP_CONN_UP =ICAFE_CA_OP_CONN_UP + + self.ECAFE_LOAD_COLLECTION =ECAFE_LOAD_COLLECTION + self.ECAFE_LOAD_GROUP =ECAFE_LOAD_GROUP + + self.ECAFE_NODATA =ECAFE_NODATA + self.ECAFE_INVALID_TYPE =ECAFE_INVALID_TYPE + self.ECAFE_BADCOUNT =ECAFE_BADCOUNT + self.ECAFE_BADSTR =ECAFE_BADSTR + self.ECAFE_BADTYPE =ECAFE_BADTYPE + self.ECAFE_NO_CONVERT =ECAFE_NO_CONVERT + self.ECAFE_NULLCONTEXT =ECAFE_NULLCONTEXT + self.ECAFE_NULLCHID =ECAFE_NULLCHID + self.ECAFE_NULLEVID =ECAFE_NULLEVID + self.ECAFE_UNKNOWN_COLLECTION =ECAFE_UNKNOWN_COLLECTION + self.ECAFE_EMPTY_COLLECTION =ECAFE_EMPTY_COLLECTION + self.ECAFE_COLLECTION_PREV_DEF =ECAFE_COLLECTION_PREV_DEF + self.ECAFE_COLLECTION_INVALID_MEMBER =ECAFE_COLLECTION_INVALID_MEMBER + self.ECAFE_RULE_FALSE =ECAFE_RULE_FALSE + self.ECAFE_UNKNOWN_GROUP =ECAFE_UNKNOWN_GROUP + self.ECAFE_EMPTY_GROUP =ECAFE_EMPTY_GROUP + self.ECAFE_GROUP_PREV_DEF =ECAFE_GROUP_PREV_DEF + self.ECAFE_INVALID_HANDLE =ECAFE_INVALID_HANDLE + self.ECAFE_INVALID_GROUP_HANDLE =ECAFE_INVALID_GROUP_HANDLE + self.ECAFE_NORDACCESS =ECAFE_NORDACCESS + self.ECAFE_NOWTACCESS =ECAFE_NOWTACCESS + self.ECAFE_TIMEOUT =ECAFE_TIMEOUT + self.ECAFE_CANNOT_OPEN_FILE =ECAFE_CANNOT_OPEN_FILE + self.ECAFE_INVALID_SWITCH_CASE =ECAFE_INVALID_SWITCH_CASE + self.ECAFE_PVALIAS_PREV_DEF =ECAFE_PVALIAS_PREV_DEF + self.ECAFE_PVALIAS_INVALID =ECAFE_PVALIAS_INVALID + self.ECAFE_PVNAME_PREV_DEF_AS_PVALIAS =ECAFE_PVNAME_PREV_DEF_AS_PVALIAS + self.ECAFE_DEVICE_ATTRIB_NOT_FOUND =ECAFE_DEVICE_ATTRIB_NOT_FOUND + self.ECAFE_HASH_UNIQUEID_EXISTS =ECAFE_HASH_UNIQUEID_EXISTS + self.ECAFE_WRONG_CA_CONTEXT =ECAFE_WRONG_CA_CONTEXT + self.ECAFE_INVALID_CAFENUM_POLICY_TYPE =ECAFE_INVALID_CAFENUM_POLICY_TYPE + self.ECAFE_MAX_MONITORS_PER_CHAN_EXCEEDED =ECAFE_MAX_MONITORS_PER_CHAN_EXCEEDED + self.ECAFE_INVALID_ENUM_INDEX =ECAFE_INVALID_ENUM_INDEX + self.ECAFE_PVGROUP_GROUPHANDLE_MISMATCH =ECAFE_PVGROUP_GROUPHANDLE_MISMATCH + self.ECAFE_TIMEOUT_SET_AND_MATCH =ECAFE_TIMEOUT_SET_AND_MATCH + self.ECAFE_HANDLE_MISMATCH_SET_AND_MATCH =ECAFE_HANDLE_MISMATCH_SET_AND_MATCH + + + self.CY_DBE_VALUE =DBE_VALUE + self.CY_DBE_LOG =DBE_LOG + self.CY_DBE_ARCHIVE =DBE_ARCHIVE + self.CY_DBE_ALARM =DBE_ALARM + self.CY_DBE_PROPERTY =DBE_PROPERTY + self.CY_DBR_PRIMITIVE =DBR_PRIMITIVE + self.CY_DBR_PLAIN =DBR_PLAIN + self.CY_DBR_STS =DBR_STS + self.CY_DBR_TIME =DBR_TIME + self.CY_DBR_GR =DBR_GR + self.CY_DBR_CTRL =DBR_CTRL + self.CY_DBR_PUT =DBR_PUT # DBR_PUT_ACKT and DBR_PUT_ACKS Write only - used from global alarm acknowledge. + self.CY_DBR_STSACK =DBR_STSACK # is DBR_STSACK_STRING + self.CY_DBR_CLASS =DBR_CLASS # is DBR_CLASS_NAME, + self.CY_DBR_NONE =DBR_NONE + self.CY_DBR_STRING =DBR_STRING + self.CY_DBR_SHORT =DBR_SHORT #returns an unsigned short + self.CY_DBR_INT =DBR_INT #returns an unsigned short + self.CY_DBR_FLOAT =DBR_FLOAT #returns an IEEE floating point value + self.CY_DBR_ENUM =DBR_ENUM #returns an unsigned short which is the enum item + self.CY_DBR_CHAR =DBR_CHAR #returns an unsigned char + self.CY_DBR_LONG =DBR_LONG #returns an unsigned long + self.CY_DBR_DOUBLE =DBR_DOUBLE #returns a double precision floating point number + self.CY_DBR_STS_STRING=DBR_STS_STRING #returns a string status structure (dbr_sts_string) + self.CY_DBR_STS_SHORT =DBR_STS_SHORT #returns a short status structure (dbr_sts_short) + self.CY_DBR_STS_INT =DBR_STS_INT #returns a short status structure (dbr_sts_int) + self.CY_DBR_STS_FLOAT =DBR_STS_FLOAT #returns a float status structure (dbr_sts_float) + self.CY_DBR_STS_ENUM =DBR_STS_ENUM #returns an enum status structure (dbr_sts_enum) + self.CY_DBR_STS_CHAR =DBR_STS_CHAR #returns a char status structure (dbr_sts_char) + self.CY_DBR_STS_LONG =DBR_STS_LONG #returns a long status structure (dbr_sts_long) + self.CY_DBR_STS_DOUBLE=DBR_STS_DOUBLE #returns a double status structure (dbr_sts_double) + self.CY_DBR_TIME_STRING=DBR_TIME_STRING #returns a string time structure (dbr_time_string) + self.CY_DBR_TIME_SHORT =DBR_TIME_SHORT #returns a short time structure (dbr_time_short) + self.CY_DBR_TIME_INT =DBR_TIME_INT #returns a short time structure (dbr_time_short) + self.CY_DBR_TIME_FLOAT =DBR_TIME_FLOAT #returns a float time structure (dbr_time_float) + self.CY_DBR_TIME_ENUM =DBR_TIME_ENUM #returns an enum time structure (dbr_time_enum) + self.CY_DBR_TIME_CHAR =DBR_TIME_CHAR #returns a char time structure (dbr_time_char) + self.CY_DBR_TIME_LONG =DBR_TIME_LONG #returns a long time structure (dbr_time_long) + self.CY_DBR_TIME_DOUBLE=DBR_TIME_DOUBLE #returns a double time structure (dbr_time_double) + self.CY_DBR_GR_STRING =DBR_GR_STRING #returns a graphic string structure (dbr_gr_string) + self.CY_DBR_GR_SHORT =DBR_GR_SHORT #returns a graphic short structure (dbr_gr_short) + self.CY_DBR_GR_INT =DBR_GR_INT #returns a graphic short structure (dbr_gr_int) + self.CY_DBR_GR_FLOAT =DBR_GR_FLOAT #returns a graphic float structure (dbr_gr_float) + self.CY_DBR_GR_ENUM =DBR_GR_ENUM #returns a graphic enum structure (dbr_gr_enum) + self.CY_DBR_GR_CHAR =DBR_GR_CHAR #returns a graphic char structure (dbr_gr_char) + self.CY_DBR_GR_LONG =DBR_GR_LONG #returns a graphic long structure (dbr_gr_long) + self.CY_DBR_GR_DOUBLE =DBR_GR_DOUBLE #returns a graphic double structure (dbr_gr_double) + self.CY_DBR_CTRL_STRING=DBR_CTRL_STRING #returns a control string structure (dbr_ctrl_int) + self.CY_DBR_CTRL_SHORT =DBR_CTRL_SHORT #returns a control short structure (dbr_ctrl_short) + self.CY_DBR_CTRL_INT =DBR_CTRL_INT #returns a control short structure (dbr_ctrl_int) + self.CY_DBR_CTRL_FLOAT =DBR_CTRL_FLOAT #returns a control float structure (dbr_ctrl_float) + self.CY_DBR_CTRL_ENUM =DBR_CTRL_ENUM #returns a control enum structure (dbr_ctrl_enum) + self.CY_DBR_CTRL_CHAR =DBR_CTRL_CHAR #returns a control char structure (dbr_ctrl_char) + self.CY_DBR_CTRL_LONG =DBR_CTRL_LONG #returns a control long structure (dbr_ctrl_long) + self.CY_DBR_CTRL_DOUBLE=DBR_CTRL_DOUBLE #returns a control double structure (dbr_ctrl_double) + + #ctypedef enum ChannelRequestPolicyKind: + self.WITHOUT_CALLBACK = WITHOUT_CALLBACK + self.WITH_CALLBACK_DEFAULT = WITH_CALLBACK_DEFAULT + self.WITH_CALLBACK_USER_SUPPLIED = WITH_CALLBACK_USER_SUPPLIED + + #ChannelFlushSendBufferPolicyKind: + self.WITH_FLUSH_IO = WITH_FLUSH_IO + self.WITH_PEND_IO = WITH_PEND_IO + self.WITH_PEND_EVENT = WITH_PEND_EVENT + self.WITH_POLL = WITH_POLL + + #ChannelWhenToFlushSendBufferPolicyKind: + self.FLUSH_AUTOMATIC =FLUSH_AUTOMATIC + self.FLUSH_NOW =FLUSH_NOW + self.FLUSH_AFTER_EACH_CHANNEL_CREATION =FLUSH_AFTER_EACH_CHANNEL_CREATION + self.FLUSH_AFTER_EACH_CHANNEL_SUBSCRIPTION=FLUSH_AFTER_EACH_CHANNEL_SUBSCRIPTION + self.FLUSH_AFTER_EACH_MESSAGE =FLUSH_AFTER_EACH_MESSAGE + self.FLUSH_AFTER_EACH_GROUP_CREATION =FLUSH_AFTER_EACH_GROUP_CREATION + self.FLUSH_DESIGNATED_TO_CLIENT =FLUSH_DESIGNATED_TO_CLIENT + + #ChannelGetCacheWaitPolicyKind: + self.GET_CACHE_NO_CHECK = GET_CACHE_NO_CHECK + self.GET_CACHE_NO_WAIT = GET_CACHE_NO_WAIT + self.GET_CACHE_NOW = GET_CACHE_NOW + self.GET_CACHE_WAIT = GET_CACHE_WAIT + + #ChannelGetActionWhenMonitorPolicyKind: + self.GET_FROM_CACHE = GET_FROM_CACHE + self.GET_FROM_IOC = GET_FROM_IOC + + + #ChannelRequestDataTypePolicyKind: + self.NATIVE_DATATYPE = NATIVE_DATATYPE + self.LOWEST_DATATYPE = LOWEST_DATATYPE # The smaller in byte size of type requested and native datatype + + #ChannelWaitForResponsePolicyKind: + self.BLOCKING =BLOCKING + self.WAIT =WAIT + self.NON_BLOCKING =NON_BLOCKING + self.NO_WAIT =NO_WAIT + + #StatusMessageKind: + self.NO_MESSAGE =NO_MESSAGE + self.PRE_REQUEST =PRE_REQUEST + self.FROM_REQUEST =FROM_REQUEST + self.FROM_PEND =FROM_PEND + self.FROM_CALLBACK=FROM_CALLBACK + self.FROM_MESSAGE =FROM_MESSAGE + + #CallbackProgressKind: + self.NOT_INITIATED=NOT_INITIATED + self.PENDING =PENDING + self.COMPLETE =COMPLETE + return + + + +cdef class SFDBPMData: + cdef readonly list x + cdef readonly list y + cdef readonly list q + cdef readonly list Energy + cdef readonly list xStatus + cdef readonly list yStatus + cdef readonly list qStatus + cdef readonly list EnergyStatus + + #cdef readonly list offs_x + #cdef readonly list offs_y + + cdef readonly bint isAllXOK + cdef readonly bint isAllYOK + cdef readonly bint isAllQOK + cdef readonly bint isAllOK + cdef readonly list device + cdef readonly int status + + def __cinit__(self): + self.isAllOK =False + self.isAllXOK=False + self.isAllYOK=False + self.isAllQOK=False + self.x=[] + self.y=[] + self.q=[] + self.Energy=[] + self.xStatus=[] + self.yStatus=[] + self.qStatus=[] + self.EnergyStatus=[] + self.device=[] + + #self.offs_x=[] + #self.offs_y=[] + + + +cdef class channelInfo: + cdef readonly long channelID + cdef readonly bint connectFlag + cdef readonly string hostName + cdef readonly unsigned int nelem #native + cdef readonly int dataType #native + cdef readonly unsigned short accessRead #0 or 1 + cdef readonly unsigned short accessWrite #0 or 1 + cdef readonly string className #dbr_class_name_t + cdef readonly int connectionState #as given by CA_OP_ + cdef readonly int cafeConnectionState #as given by cafe_cs_state + cdef readonly string connectionStateAsString #as given by CA_OP_ + cdef readonly string cafeConnectionStateAsString #as given by cafe_cs_state + cdef CAFEDataTypeCode cdt + cdef CAFEStatusCode csc + cdef CAOPCodes caop + + def __cinit__(self): + self.channelID=0 + self.connectFlag=False + self.hostName=(("")).encode('UTF-8') + self.nelem=0 + self.dataType=ICAFE_TYPENOTCONN + self.accessRead=0 + self.accessWrite=0 + self.className=(("")).encode('UTF-8') + self.connectionState=ICAFE_CA_OP_CONN_DOWN + self.cafeConnectionState=ICAFE_CS_NEVER_CONN + self.connectionStateAsString=(('ICAFE_CA_OP_CONN_DOWN')).encode('UTF-8') + self.cafeConnectionStateAsString=(('ICAFE_CS_NEVER_CONN')).encode('UTF-8') + + def show(self): + print ("channelID = %s" % hex(self.channelID)) + print ("connectFlag = %d" % self.connectFlag) + print ("hostName = %s" % self.hostName) + print ("nelem = %d" % self.nelem) + print ("dataType = %s (%d)" % (self.cdt.message(self.dataType), self.dataType)) + print ("accessRead = %d" % self.accessRead) + print ("accessWrite = %d" % self.accessWrite) + print ("className = %s" % self.className) + #print ("connectionState = %s (%d)" % (self.connectionStateAsString, self.connectionState)) + #print ("cafeConnectionState = %s (%d)" % (self.cafeConnectionStateAsString,self.cafeConnectionState)) + print ("connectionState = %s (%d)" % (self.caop.message(self.connectionState),self.connectionState)) + print ("cafeConnectionState = %s (%d)" % (self.csc.message(self.cafeConnectionState),self.cafeConnectionState)) + return + + + +################################################################################## +cdef class _epicsTimeStampAsDate: + cdef epicsTime *_time + cdef local_tm_nano_sec local + cdef list etsDate + def __cinit__(self, epicsTimeStamp ts): + self._time = new epicsTime(ts) + #This gives warning: dereferencing type-punned pointer will break strict-aliasing rules + self.local = (self._time) + + #print ("ts====== ", ts.secPastEpoch, ts.nsec) + #print ("year=== ", ( ( (&(&self.local).ansi_tm).tm_year) + 1900)) + + self.etsDate=[] + self.etsDate.append( (self.local.ansi_tm.tm_year + 1900)) + self.etsDate.append( (self.local.ansi_tm.tm_mon + 1)) + self.etsDate.append( self.local.ansi_tm.tm_mday) + self.etsDate.append( self.local.ansi_tm.tm_hour) + self.etsDate.append( self.local.ansi_tm.tm_min) + self.etsDate.append( self.local.ansi_tm.tm_sec) + self.etsDate.append( ts.nsec) + self.etsDate.append( self.local.nSec) + def get(self): + return self.etsDate + + +################################################################################## + +################################################################################## +cdef class pvctrl: + cdef readonly unsigned int nelem + cdef readonly int alarmStatus + cdef readonly int alarmSeverity + cdef readonly unsigned short precision + cdef readonly string units + cdef readonly unsigned short noEnumStrings + cdef readonly list enumStrings + cdef readonly upperDisplayLimit + cdef readonly lowerDisplayLimit + cdef readonly upperAlarmLimit + cdef readonly upperWarningLimit + cdef readonly lowerWarningLimit + cdef readonly lowerAlarmLimit + cdef readonly upperControlLimit + cdef readonly lowerControlLimit + cdef readonly list value + cdef readonly int status + cdef readonly tuple pythonVersion + + + def __cinit__(self): + self.nelem= 1 + self.alarmStatus=-1 + self.alarmSeverity=-1 + self.precision=0 + self.units=(("")).encode('UTF-8') + self.noEnumStrings=0 + self.enumStrings=[] + self.upperDisplayLimit=0 + self.lowerDisplayLimit=0 + self.upperAlarmLimit=0 + self.lowerAlarmLimit=0 + self.upperControlLimit=0 + self.lowerControlLimit=0 + self.value=[] + self.status=1 + self.pythonVersion=sys.version_info[0:4] + + def show(self): + self.showPrint(self.nelem) + return + + def showMax(self, nelem): + if nelem > self.nelem: + #print ("----------------------" + #print ("Note: Max. Nelem =", self.nelem + #print ("----------------------" + nelem=self.nelem + self.showPrint(nelem) + return + + + cdef showPrint(self, nelem): + cdef unsigned int i + #is self.value[0] a list + if nelem==1: + if isinstance (self.value[0], list): + if self.pythonVersion[0] < 3: + print ("value =", self.value[0][0] ) + + else: + print ("value = ", self.value[0][0], end="" ) + else: + if self.pythonVersion[0] < 3: + print ("value =", self.value[0] ) + + else: + print ("value =", self.value[0] , end="" ) + else: + print ("value = ", end="") + if self.pythonVersion[0] < 3: + if isinstance (self.value[0], list): + for i in range(0, nelem): + print (self.value[0][i],"[%d]" %i ) + else: + for i in range(0, nelem): + print (self.value[i],"[%d]" %i ) + + else: + if isinstance (self.value[0], list): + for i in range(0, nelem): + print (self.value[0][i],"[%d]" %i, end=" ") + else: + for i in range(0, nelem): + print (self.value[i],"[%d]" %i, end=" ") + + print ("") + print ("status = %d" % self.status) + print ("alarmStatus = %d" % self.alarmStatus) + print ("alarmSeverity = %d" % self.alarmSeverity) + print ("precision = %d" % self.precision) + print ("units = %s" % self.units) + print ("noEnumStrings = %d" % self.noEnumStrings) + + if self.noEnumStrings > 0: + print ("enumStrings =",) + for i in range(0, self.noEnumStrings): + print (self.enumStrings[i],"[%s]" %i,) + print ("") + + print ("upperDisplayLimit = %f" % self.upperDisplayLimit) + print ("lowerDisplayLimit = %f" % self.lowerDisplayLimit) + print ("upperAlarmLimit = %f" % self.upperAlarmLimit) + print ("lowerAlarmLimit = %f" % self.lowerAlarmLimit) + print ("upperWarningLimit = %f" % self.upperWarningLimit) + print ("lowerWarningLimit = %f" % self.lowerWarningLimit) + print ("upperControlLimit = %f" % self.upperControlLimit) + print ("lowerControlLimit = %f" % self.lowerControlLimit) + + return +################################################################################## + +cdef class CyCafeException: + cdef readonly str type + cdef readonly str source + cdef readonly int handle + cdef readonly str pv + cdef readonly int errorCode + cdef readonly str errorText + cdef readonly str errorInfo + + def __cinit__(self, _type='cycafe', _source=None, _handle=-1, _pv=None, _ec=-1, _et=None, _ei=None): + self.type =_type + self.source=_source + self.handle=_handle + self.pv =_pv + self.errorCode =_ec + self.errorText =_et + self.errorInfo =_ei + + def show(self): + print ("------CyCafeException-----------------------------------------------------") + print ("raised from CyCafe method:",self.source) + if (self.handle!=-1): + print ("name=",self.pv,"(handle=",self.handle,") reports the following error:") + print ("errorCode:",self.errorCode,"errorText:",self.errorText,"\nerrorInfo:",self.errorInfo) + elif self.type=='cafe': + print ("name=",self.pv,"(handle=",self.handle,") reports the following error:") + print ("errorCode:",self.errorCode,"errorText:",self.errorText,"\nerrorInfo:",self.errorInfo) + else: + print ("errorInfo:",self.errorInfo) + print ("------------------------------------------------------------------------") + return + + def reveal(self): + print ("------CyCafeException-----------------------------------------------------") + if(self.type): + print (".type =",self.type) + print (".source =",self.source) + if (self.handle!=-1): + print (".handle =",self.handle) + if (self.pv): + print (".pv =",self.pv) + if (self.errorCode != -1): + print (".errorCode=",self.errorCode) + if (self.errorText): + print (".errorText=",self.errorText) + print (".errorInfo=",self.errorInfo) + print ("------------------------------------------------------------------------") + return + + +cdef class monitorpolicy: + cdef readonly chtype dataType + cdef readonly chtype dbrDataType + cdef readonly DBR_TYPE cafeDbrType + cdef readonly unsigned int nelem + cdef readonly unsigned int mask + #cdef readonly pCallback handler + cdef readonly unsigned int userArgs + #cdef readonly evid eventID + cdef readonly int status + cdef readonly unsigned int monid + cdef readonly bint maskHasDBE_PROPERTY + cdef readonly bint maskHasDBE_VALUE + cdef readonly bint maskHasDBE_LOG + cdef readonly bint maskHasDBE_ALARM + + def __cinit__(self): + self.monid=0 + #self.dataType=None + #self.dbrDataType=None + #self.cafeDbrType=None + self.nelem=1 + #self.mask=None + #self.userArgs=None + self.status=ICAFE_NORMAL + self.maskHasDBE_PROPERTY=False + self.maskHasDBE_VALUE =False + self.maskHasDBE_LOG =False + self.maskHasDBE_ALARM =False + + def show(self): + print("monid =", self.monid) + print("datatype =", self.dataType) + print("dbrDataType=", self.dbrDataType) + print("cafeDbrType=", self.cafeDbrType) + print("nelem =", self.nelem) + print("mask =", self.mask) + print("userArgs =", self.userArgs) + print("status =", self.status) + print("maskHasDBE_PROPERTY=", self.maskHasDBE_PROPERTY) + print("maskHasDBE_VALUE =", self.maskHasDBE_VALUE) + print("maskHasDBE_LOG =", self.maskHasDBE_LOG) + print("maskHasDBE_ALARM =", self.maskHasDBE_ALARM) + return + + + +################################################################################## +cdef class pvdata: + cdef readonly unsigned int nelem + cdef readonly int alarmStatus + cdef readonly int alarmSeverity + cdef readonly list ts + cdef readonly list tsDate + cdef readonly list value + cdef readonly int status + + cdef readonly tuple pythonVersion + + def __cinit__(self): + self.nelem= 1 + self.alarmStatus=-1 + self.alarmSeverity=-1 + self.ts=[] + self.tsDate=[] + self.value=[] + self.status=1 + self.pythonVersion=sys.version_info[0:4] + + def show(self): + self.showPrint(self.nelem) + return + + def showMax(self, nelem): + if nelem > self.nelem: + #print ("----------------------" + #print ("Note: Max. Nelem =", self.nelem + #print ("----------------------" + nelem=self.nelem + self.showPrint(nelem) + return + + cdef showPrint(self, nelem): + cdef unsigned int i + #is self.value[0] a list + + if self.pythonVersion[0] < 3: + + if nelem==1: + if isinstance (self.value[0], list): + print ("value =", self.value[0][0] ) + else: + print ("value =", self.value[0] ) + else: + print ("value = "), + if isinstance (self.value[0], list): + for i in range(0, nelem): + print (self.value[0][i],"[%d]" %i ) + else: + for i in range(0, nelem): + print (self.value[i],"[%d]" %i ) + + else: + + if nelem==1: + if isinstance (self.value[0], list): + print ("value =", self.value[0][0], end="") + else: + print ("value =", self.value[0], end="") + else: + print ("value = ", end="") + if isinstance (self.value[0], list): + for i in range(0, nelem): + print (self.value[0][i],"[%d]" %i , end=" ") + else: + for i in range(0, nelem): + print (self.value[i],"[%d]" %i , end=" ") + + + print ("") + print ("status = %d" % self.status) + #if self.alarmStatus != -1: + print ("alarmStatus = %d" % self.alarmStatus) + print ("alarmSeverity = %d" % self.alarmSeverity) + #if self.ts[0] != 0: + print ("ts =", self.ts[0], self.ts[1]) + print ("tsDate =", self.tsDate[0], self.tsDate[1], \ + self.tsDate[2], self.tsDate[3],\ + self.tsDate[4], self.tsDate[5], self.tsDate[6]) + return + +################################################################################## + + + + +################################################################################## +cdef class pvgroup: + cdef public list pvdata + cdef public unsigned int npv + cdef public string name + cdef readonly int groupStatus + cdef public unsigned int groupHandle + cpdef public bint rule + cpdef public bint hasAlarm + cpdef public bint hasTS + + cdef tuple pythonVersion + + def __cinit__(self): + self.groupStatus=ICAFE_NORMAL + self.rule=True + self.hasAlarm=True + self.hasTS=True + self.pythonVersion=sys.version_info[0:4] + return + + def show(self): + self.showPrint(npv=self.npv, grouplist=None) + return + + def showWithPV(self,glist): + if len(glist) != self.npv: + print ("ERROR: GROUP MEMBER MISMATCH!!") + print (glist, "has", len(glist), "members while group has", self.npv,"!!") + return + self.showPrint(self.npv, grouplist=glist) + return + + def showMax(self, _npv): + if _npv > self.npv: + #print ("----------------------" + #print ("Note: Max. Npv =", self.npv + #print ("----------------------" + _npv=self.npv + self.showPrint(npv=_npv, grouplist=None) + return + + cdef showPrint(self, npv, grouplist): + print ("GROUP NAME = ", self.name) + print ("GROUP HANDLE = ", self.groupHandle) + print ("GROUP STATUS = ", self.groupStatus) + cdef unsigned int i,j + #if nelem==1: + # print "value =", self.value[0], + #else: + + for i in range(0, npv): + print ("Member: ", i, "---------------------------------") + if grouplist: + print ("PV =", grouplist[i]) + + if self.pythonVersion[0] < 3: + + print ("value = " ) + for j in range(0, len(self.pvdata[i].value)): + print (self.pvdata[i].value[j],"[%d]"%j ) + + else: + + print ("value = " ,end="") + for j in range(0, len(self.pvdata[i].value)): + print (self.pvdata[i].value[j],"[%d]"%j, end=" ") + + print ("") + print ("status = %d" % self.pvdata[i].status) + print ("alarmStatus = %d" % self.pvdata[i].alarmStatus) + print ("alarmSeverity = %d" % self.pvdata[i].alarmSeverity) + print ("ts =", self.pvdata[i].ts[0], self.pvdata[i].ts[1]) + print ("tsDate =", self.pvdata[i].tsDate[0], self.pvdata[i].tsDate[1], \ + self.pvdata[i].tsDate[2], self.pvdata[i].tsDate[3],\ + self.pvdata[i].tsDate[4], self.pvdata[i].tsDate[5], self.pvdata[i].tsDate[6]) + print ("--------------------------------------------") + return + + + ''' + cdef showPrintWithPVName(self, npv, pvlist): + print ("GROUP NAME = ", self.name) + print ("GROUP HANDLE = ", self.groupHandle) + print ("GROUP STATUS = ", self.groupStatus) + cdef unsigned int i,j + + for i in range(0, npv): + print ("pv =", pvlist[i]) + for j in range(0, len(self.pvdata[i].value)): + print (self.pvdata[i].value[j],"[%d]" %j,) + print ("") + print ("status = %d" % self.pvdata[i].status) + print ("alarmStatus = %d" % self.pvdata[i].alarmStatus) + print ("alarmSeverity = %d" % self.pvdata[i].alarmSeverity) + print ("ts =", self.pvdata[i].ts[0], self.pvdata[i].tsDate[1]) + print ("tsDate =", self.pvdata[i].tsDate[0], self.pvdata[i].tsDate[1], \ + self.pvdata[i].tsDate[2], self.pvdata[i].tsDate[3],\ + self.pvdata[i].tsDate[4], self.pvdata[i].tsDate[5], self.pvdata[i].tsDate[6]) + return + ''' +################################################################################## + + + +################################################################################## +cdef getMatchedDataType(dt, dtn): + #dt: input from user + #dtn: native type + #dtcheck: matching data type for pvd convert method + + cdef unsigned int dtcheck=dtn; + + if dt in ['uchar','uint8']: + dtcheck=CAFE_CHAR + elif dt in ['np.uint8']: + dtcheck=CAFE_CHAR + elif dt in ['ushort','uint16']: + dtcheck=CAFE_USHORT + elif dt in ['np.ushort','np.uint16']: + dtcheck=CAFE_USHORT + elif dt in ['short','int16','int8','bool','byte']: + dtcheck=CAFE_SHORT + elif dt in ['np.short','np.int16','np.int8','np.bool_', 'np.byte']: + dtcheck=CAFE_SHORT + elif dt in ['int','int_','uint','ushort','int32','uint32']: + dtcheck=CAFE_LONG + elif dt in ['np.intc','np.int_','np.long','np.ushort','np.int32','np.uint32']: + dtcheck=CAFE_LONG + elif dt in ['double', 'float', 'float_','float64', 'int64', 'uint64']: + dtcheck=CAFE_DOUBLE + elif dt in ['np.float_','np.float64', 'np.long', 'np.ulong','np.int64','np.uint64']: + dtcheck=CAFE_DOUBLE + elif dt in ['float16','float32']: + dtcheck=CAFE_FLOAT + elif dt in ['np.float16','np.float32']: + dtcheck=CAFE_FLOAT + elif dt in ['string','str','unicode','string_','str_','unicode_']: + dtcheck=CAFE_STRING + elif dt in ['np.string','np.str','np.unicode','np.string_','np.str_','np.unicode_']: + dtcheck=CAFE_STRING + elif dt in ['native','']: + dtcheck=dtn #need a line here + else: + print ("Valid input parameters for data type are variations of: 'int', 'float', 'str', or 'native'") + print ("Data to be presented in native data type") + + return dtcheck +################################################################################## + + + +################################################################################# + +#cdef pvdata p1 = pvdata() +#cdef pvctrl c1 = pvctrl() + + +################################################################################# + +cdef pvdata PVDataHolderToStruct(PVDataHolder pvd, dt=None): + + #global p1 + cdef pvdata p1 = pvdata() + + cdef unsigned int dtn = pvd.getDataType(); + cdef unsigned int dtcheck=dtn + cdef localList=[] + + if dt: + dtcheck=getMatchedDataType(dt, dtn) + + if dtcheck==CAFE_STRING: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsString(i)) + elif dtcheck==CAFE_SHORT: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) #getAsShort(i) + elif dtcheck==CAFE_FLOAT: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsDouble(i)) #getAsFloat(i) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + #if self._c_cafe.isEnum(handle)==1: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsString(i)) + #else: + # for i in range(0, pvd.getNelem()): + # localList.append(pvd.getAsLong(i)) #getAsUShort(i) + elif dtcheck==CAFE_CHAR: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) # pvd.getAsChar(i) + elif dtcheck==CAFE_LONG: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) + elif dtcheck==CAFE_DOUBLE: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsDouble(i)) + else: + localList.append(0) + #print ("This line in PyCafe def getDataHolderToStruct should never appear!" + #print ("No Data! Error. Is channel connected?" + + + + p1.value=localList + p1.status=pvd.getStatus() + p1.nelem=pvd.getNelem() + p1.alarmStatus=pvd.getAlarmStatus() + p1.alarmSeverity=pvd.getAlarmSeverity() + + pvd._etsNorm=pvd.getEpicsTimeStampAsUInt32() + + cpdef ll=[] + ll.append((pvd._etsNorm).secPastEpoch) + ll.append((pvd._etsNorm).nsec) + p1.ts=ll + + pvd._etsDate=pvd.getEpicsTimeStampAsDate() + + cpdef ld=[] + ld.append( (pvd._etsDate).year ) + ld.append( (pvd._etsDate).mon ) + ld.append( (pvd._etsDate).day ) + ld.append( (pvd._etsDate).hour ) + ld.append( (pvd._etsDate).min ) + ld.append( (pvd._etsDate).sec ) + ld.append( (pvd._etsDate).nsec ) + p1.tsDate=ld + + + + return p1 +################################################################################## + + + +################################################################################# + +cdef pvctrl PVCtrlHolderToStruct(PVCtrlHolder pvc, dt=None): + + #global c1 + cdef pvctrl c1 = pvctrl() + + cdef unsigned int dtn = pvc.getDataType(); + + cdef unsigned int dtcheck=dtn + + cdef localList=[] + + if dt: + dtcheck=getMatchedDataType(dt, dtn) + + if dtcheck==CAFE_STRING: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsString(i)) + elif dtcheck==CAFE_SHORT: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) #getAsShort(i) + elif dtcheck==CAFE_FLOAT: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsDouble(i)) #getAsFloat(i) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + #if self._c_cafe.isEnum(handle)==1: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsString(i)) + #else: + # for i in range(0, pvd.getNelem()): + # localList.append(pvd.getAsLong(i)) #getAsUShort(i) + elif dtcheck==CAFE_CHAR: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) # pvd.getAsChar(i) + elif dtcheck==CAFE_LONG: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) + elif dtcheck==CAFE_DOUBLE: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsDouble(i)) + else: + localList.append(0) + #print ("This line in PyCafe def getDataHolderToStruct should never appear!" + #print ("No Data! Error. Is channel connected?" + c1.value=localList + c1.status=pvc.getStatus() + c1.nelem=pvc.getNelem() + c1.alarmStatus=pvc.getAlarmStatus() + c1.alarmSeverity=pvc.getAlarmSeverity() + + c1.precision=pvc.getPrecision() + c1.noEnumStrings=pvc.getNoEnumStrings() + + enumList=[] + for i in range(0, pvc.getNoEnumStrings()): + enumList.append(pvc.getEnumStrings()[i]) + + c1.enumStrings=enumList + + c1.units=pvc.getUnitsAsString() + + c1.upperDisplayLimit=pvc.getUpperDispLimit_AsDouble() + c1.lowerDisplayLimit=pvc.getLowerDispLimit_AsDouble() + c1.upperAlarmLimit =pvc.getUpperAlarmLimit_AsDouble() + c1.upperWarningLimit=pvc.getUpperWarningLimit_AsDouble() + c1.lowerWarningLimit=pvc.getLowerWarningLimit_AsDouble() + c1.lowerAlarmLimit =pvc.getLowerAlarmLimit_AsDouble() + c1.upperControlLimit=pvc.getUpperCtrlLimit_AsDouble() + c1.lowerControlLimit=pvc.getLowerCtrlLimit_AsDouble() + + return c1 +################################################################################## + + +################################################################################# + +cdef channelInfo channelRegaliaToStruct(ChannelRegalia cr): + + cdef channelInfo ci = channelInfo() + + + ci.channelID = ( cr.getChannelID()) + ci.connectFlag=cr.getConnectFlag() + ci.hostName =cr.getHostNameAsString() + ci.dataType =cr.getDataType() + ci.className =cr.getClassNameAsString() + ci.accessRead =cr.getAccessRead() + ci.accessWrite=cr.getAccessWrite() + ci.nelem =cr.getNelem() + ci.connectionState =cr.getConnectionState() + ci.cafeConnectionState=cr.getCafeConnectionState() + ci.connectionStateAsString =cr.getConnectionStateAsString() + ci.cafeConnectionStateAsString =cr.getCafeConnectionStateAsString() + return ci +################################################################################# + + +################################################################################# +''' +cdef SFDBPMData dbpmHolderToStruct(DBPMKeeper d): + cdef SFDBPMData dbpm = SFDBPMData() + + cdef unsigned int i + + #double [::1] mvDouble + #mvDouble = np.empty(d.getX().size(), dtype=np.float64) + #for ij in range(0, d.getX().size()): + # mvDouble[ij]=d.getX()[i] + #dbpm.x=np.array(mvDouble) + + for i in range(0,d.getX().size()): + + dbpm.x.append(d.getX()[i].getValue()) + dbpm.y.append(d.getY()[i].getValue()) + dbpm.q.append(d.getQ()[i].getValue()) + dbpm.Energy.append(d.getEnergy()[i].getValue()) + dbpm.xStatus.append(d.getX()[i].getStatus()) + dbpm.yStatus.append(d.getY()[i].getStatus()) + dbpm.qStatus.append(d.getQ()[i].getStatus()) + dbpm.EnergyStatus.append(d.getEnergy()[i].getStatus()) + + dbpm.isAllXOK = d.getIsAllXOK() + dbpm.isAllYOK = d.getIsAllYOK() + dbpm.isAllQOK = d.getIsAllQOK() + dbpm.isAllOK = d.getIsAllOK() + dbpm.status = d.getStatus() + return dbpm +''' +################################################################################# diff --git a/PyCafeDefs_pub.pxi b/PyCafeDefs_pub.pxi new file mode 100644 index 0000000..6b829c6 --- /dev/null +++ b/PyCafeDefs_pub.pxi @@ -0,0 +1,848 @@ + +def show(): + print "cafe=PyCafe.CyCafe()" + print "cyca=PyCafe.CyCa()" + print "cafe.init()" + print "cafe.openNoWait()" + print "=cafe.open()" + print "cafe.openNowAndWait(timeout)" + print "cafe.openNow()" + print "cafe.close(handlePV=)" + print "cafe.closeChannels()" + print "cafe.allConnected()" + print "cafe.isConnected(handlePV=)" + print "cafe.printDisconnected()" + print "cafe.printHandles()" + print "cafe.printHandle(handlePV=)" + + print "cafe.getStatus(handlePV=)" + print "cafe.getAlarmStatusSeverity(handlePV=)" + print "cafe.getTimeStamp(handlePV=)" + print "cafe.getTimeStampDate(handlePV=)" + print "cafe.checkForHandle()" + print "cafe.checkForHandleList()" + print "cafe.checkForGroupHandle()" + print "cafe.getPVNameFromHandle(int)" + print "cafe.getHandleFromPVName(str)" + print "cafe.getChannelInfo(handlePV=)" + print "cafe.setDbrBase(handlePV=, unsigned int) #dbrBase.DBR_XXX" + print "cafe.getDbrBase(handlePV=)" + + print "cafe.getNonBlocking(handlePV=)" #followed by getCache + print "cafe.get(handlePV=)" # return in native type + print "cafe.get(handlePV=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getInt(handlePV=)" + print "cafe.getFloathandlePV=)" + print "cafe.getStr(handlePV=)" + + print "cafe.getList(handlePV=)" # return List in native type + print "cafe.getList(handlePV=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getIntList(handlePV=)" + print "cafe.getFloatList(handlePV=)" + print "cafe.getStrList(handlePV=)" + + # returns Memoryview in native type, except for when dt='str' which returns a List + # returns np.array if asnumpy=True + print "cafe.getArray(handlePV=)" + print "cafe.getArray(handlePV=, dt=<'int','float','str','native'(default)>)" + print "cafe.getIntArray(handlePV=,asnumpy=)" + print "cafe.getFloatArray(handlePV=,asnumpy=)" + + + print "cafe.getPV(handlePV=)" # return PVData in native type + print "cafe.getPV(handlePV=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getPVInt(handlePV=)" + print "cafe.getPVFloat(handlePV=)" + print "cafe.getPVStr(handlePV=)" + + print "cafe.getPVList(handleList=)" # return Array of PVData in native type + print "cafe.getPVList(handleList=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getPVIntList(handleList=)" + print "cafe.getPVFloatList(handleList=)" + print "cafe.getPVStrList(handleList=)" + + print "cafe.getScalarList(handleList=)" # return List in native type + print "cafe.getScalarList(handleList=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getIntScalarList(handleList=)" + print "cafe.getFloatScalarList(handleList=)" + print "cafe.getStrScalarList(handleList=)" + + print "cafe.getPVCache(handlePV=)" # return PVData in native type + print "cafe.getPVCache(handlePV=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getPVIntCache(handlePV=)" + print "cafe.getPVFloatCache(handlePV=)" + print "cafe.getPVStrCache(handlePV=)" + + + # returns Memoryview in native type, except for when dt='str' which returns a List + # returns np.array if asnumpy=True + print "cafe.getArrayCache(handlePV=)" + print "cafe.getArrayCache(handlePV=, dt=<'int','float','str','native'(default)>)" + print "cafe.getIntArrayCache(handlePV=,asnumpy=)" + print "cafe.getFloatArrayCache(handlePV=,asnumpy=)" + + print "cafe.getCtrl(handlePV=)" + print "cafe.getCtrl(handlePV=, dt='native' (default) else <'int','float','str'>)" + print "cafe.getCtrlCache(handlePV=)" + print "cafe.getCtrlCache(handlePV=, dt='native' (default) else <'int','float','str'>)" + + print "mpid=cafe.monitorStart(handlePV=), cb=None, dbr=None, mask=DBE_VALUE|DBE_LOG|DBE_ALARM)" + print "cafe.monitorStop(handlePV=, mpID=None)" + print "cafe.monitorStopAll(handlePV=)" + + print "cafe.getNoMonitors(handlePV=)" + + print "cafe.set(handlePV=, valSet)" + print "cafe.setScalarList(handleList=, valList)" + print "cafe.setAndMatch(handlePVSet=, valSet=, handlePVMatch=, \ + tolerance= , timeout=, printFlag=)" + #Synchronous groups + print "handleList[]=cafe.defineGroup(gname, pvList)" + print "list[]=cafe.PVGroupValuesToList(pvgroup)" + print "vectorList,status,statusList = cafe.getGroup(self, ghandleName, dt='native')" + print "pvdataList[],status = cafe.getPVGroup(self, ghandleName, dt='native')" + print "cafe.setGroup(ghandleName, vectorList)" + + return + + +cdef int PYCAFE_PRINT_HIGH=9 +cdef int PYCAFE_PRINT_MED=5 +cdef int PYCAFE_PRINT_LOW=1 + +cdef int PYCAFE_PRINT_LEVEL=PYCAFE_PRINT_MED + +ctypedef shared_ptr[vector [double]] vdouble_ptr +ctypedef shared_ptr[vector [float]] vfloat_ptr + +cdef object py_cb = None +cdef object py_cb_handle = None +cdef object py_cb_ctrl = None + + +''' +def py_cb(pvdata pv1, unsigned int handle, str pvname): + print "PV:", pvname, " Handle:", handle + pv1.showMax(10) + return + +def py_cb_handle(unsigned int handle): + print " Handle:", handle + return + +#Add control callback! + +def py_cb_ctrl(pvctrl c1, unsigned int handle, str pvname): + print "PV:", pvname, " Handle:", handle + c1.showMax(10) + return +''' + +#***********api*************** + +cdef public void py_cb_wrapper(PVDataHolder pvd, unsigned int handle, string pvname) with gil: + cdef pvdata pv1 = PVDataHolderToStruct(pvd) + py_cb(pv1, handle, pvname) + with nogil: + return + +cdef public void py_cb_ctrl_wrapper(PVCtrlHolder pvc, unsigned int handle, string pvname) with gil: + cdef pvctrl c1 = PVCtrlHolderToStruct(pvc) + py_cb_ctrl(c1, handle, pvname) + with nogil: + return + +cdef public void py_cb_handle_wrapper(unsigned int handle) with gil: + + py_cb_handle(handle) + + with nogil: + return + + +cdef public void py_cb_handle_monid_wrapper(unsigned int handle, unsigned long monid) with gil: + + + cbobjt=monDictGlobal[monid] + + cbobjt(handle) + + with nogil: + return + + +#***********api*************** +''' +cdef object callbackHandlerMonitor = None + + +cdef void callbackHandlerMonitor_wrapper(event_handler_args args) with gil: + handle= args.usr + py_cb_handle(handle) + with nogil: + return +''' +#Correct memory management a la KWSmith p.190 +cdef class _finalizer: + cdef void *_data + def __dealloc__(self): + if self._data is not NULL: + free(self._data) + return + +cdef void set_base(cnp.ndarray arr, void * carr): + cdef _finalizer fin = _finalizer() + fin._data = carr + cnp.set_array_base(arr, fin) + return + +cdef class CyCa: + cpdef readonly unsigned int CY_DBE_VALUE + cpdef readonly unsigned int CY_DBE_LOG + cpdef readonly unsigned int CY_DBE_ARCHIVE + cpdef readonly unsigned int CY_DBE_ALARM + cpdef readonly unsigned int CY_DBE_PROPERTY + cpdef readonly unsigned int CY_DBR_PRIMITIVE + cpdef readonly unsigned int CY_DBR_PLAIN + cpdef readonly unsigned int CY_DBR_STS + cpdef readonly unsigned int CY_DBR_TIME + cpdef readonly unsigned int CY_DBR_GR + cpdef readonly unsigned int CY_DBR_CTRL + cpdef readonly unsigned int CY_DBR_PUT + cpdef readonly unsigned int CY_DBR_STSACK + cpdef readonly unsigned int CY_DBR_CLASS + cpdef readonly unsigned int CY_DBR_NONE + cpdef readonly unsigned int CY_DBR_STRING #returns a NULL terminated string + cpdef readonly unsigned int CY_DBR_SHORT #returns an unsigned short + cpdef readonly unsigned int CY_DBR_INT #returns an unsigned short + cpdef readonly unsigned int CY_DBR_FLOAT #returns an IEEE floating point value + cpdef readonly unsigned int CY_DBR_ENUM #returns an unsigned short which is the enum item + cpdef readonly unsigned int CY_DBR_CHAR #returns an unsigned char + cpdef readonly unsigned int CY_DBR_LONG #returns an unsigned long + cpdef readonly unsigned int CY_DBR_DOUBLE #returns a double precision floating point number + cpdef readonly unsigned int CY_DBR_STS_STRING #returns a string status structure (dbr_sts_string) + cpdef readonly unsigned int CY_DBR_STS_SHORT #returns a short status structure (dbr_sts_short) + cpdef readonly unsigned int CY_DBR_STS_INT #returns a short status structure (dbr_sts_int) + cpdef readonly unsigned int CY_DBR_STS_FLOAT #returns a float status structure (dbr_sts_float) + cpdef readonly unsigned int CY_DBR_STS_ENUM #returns an enum status structure (dbr_sts_enum) + cpdef readonly unsigned int CY_DBR_STS_CHAR #returns a char status structure (dbr_sts_char) + cpdef readonly unsigned int CY_DBR_STS_LONG #returns a long status structure (dbr_sts_long) + cpdef readonly unsigned int CY_DBR_STS_DOUBLE #returns a double status structure (dbr_sts_double) + cpdef readonly unsigned int CY_DBR_TIME_STRING #returns a string time structure (dbr_time_string) + cpdef readonly unsigned int CY_DBR_TIME_SHORT #returns a short time structure (dbr_time_short) + cpdef readonly unsigned int CY_DBR_TIME_INT #returns a short time structure (dbr_time_short) + cpdef readonly unsigned int CY_DBR_TIME_FLOAT #returns a float time structure (dbr_time_float) + cpdef readonly unsigned int CY_DBR_TIME_ENUM #returns an enum time structure (dbr_time_enum) + cpdef readonly unsigned int CY_DBR_TIME_CHAR #returns a char time structure (dbr_time_char) + cpdef readonly unsigned int CY_DBR_TIME_LONG #returns a long time structure (dbr_time_long) + cpdef readonly unsigned int CY_DBR_TIME_DOUBLE #returns a double time structure (dbr_time_double) + cpdef readonly unsigned int CY_DBR_GR_STRING #returns a graphic string structure (dbr_gr_string) + cpdef readonly unsigned int CY_DBR_GR_SHORT #returns a graphic short structure (dbr_gr_short) + cpdef readonly unsigned int CY_DBR_GR_INT #returns a graphic short structure (dbr_gr_int) + cpdef readonly unsigned int CY_DBR_GR_FLOAT #returns a graphic float structure (dbr_gr_float) + cpdef readonly unsigned int CY_DBR_GR_ENUM #returns a graphic enum structure (dbr_gr_enum) + cpdef readonly unsigned int CY_DBR_GR_CHAR #returns a graphic char structure (dbr_gr_char) + cpdef readonly unsigned int CY_DBR_GR_LONG #returns a graphic long structure (dbr_gr_long) + cpdef readonly unsigned int CY_DBR_GR_DOUBLE #returns a graphic double structure (dbr_gr_double) + cpdef readonly unsigned int CY_DBR_CTRL_STRING #returns a control string structure (dbr_ctrl_int) + cpdef readonly unsigned int CY_DBR_CTRL_SHORT #returns a control short structure (dbr_ctrl_short) + cpdef readonly unsigned int CY_DBR_CTRL_INT #returns a control short structure (dbr_ctrl_int) + cpdef readonly unsigned int CY_DBR_CTRL_FLOAT #returns a control float structure (dbr_ctrl_float) + cpdef readonly unsigned int CY_DBR_CTRL_ENUM #returns a control enum structure (dbr_ctrl_enum) + cpdef readonly unsigned int CY_DBR_CTRL_CHAR #returns a control char structure (dbr_ctrl_char) + cpdef readonly unsigned int CY_DBR_CTRL_LONG #returns a control long structure (dbr_ctrl_long) + cpdef readonly unsigned int CY_DBR_CTRL_DOUBLE #returns a control double structure (dbr_ctrl_double) + + def __cinit__(self): + self.CY_DBE_VALUE =DBE_VALUE + self.CY_DBE_LOG =DBE_LOG + self.CY_DBE_ARCHIVE =DBE_ARCHIVE + self.CY_DBE_ALARM =DBE_ALARM + self.CY_DBE_PROPERTY =DBE_PROPERTY + self.CY_DBR_PRIMITIVE =DBR_PRIMITIVE + self.CY_DBR_PLAIN =DBR_PLAIN + self.CY_DBR_STS =DBR_STS + self.CY_DBR_TIME =DBR_TIME + self.CY_DBR_GR =DBR_GR + self.CY_DBR_CTRL =DBR_CTRL + self.CY_DBR_PUT =DBR_PUT # DBR_PUT_ACKT and DBR_PUT_ACKS Write only - used from global alarm acknowledge. + self.CY_DBR_STSACK =DBR_STSACK # is DBR_STSACK_STRING + self.CY_DBR_CLASS =DBR_CLASS # is DBR_CLASS_NAME, + self.CY_DBR_NONE =DBR_NONE + self.CY_DBR_STRING =DBR_STRING + self.CY_DBR_SHORT =DBR_SHORT #returns an unsigned short + self.CY_DBR_INT =DBR_INT #returns an unsigned short + self.CY_DBR_FLOAT =DBR_FLOAT #returns an IEEE floating point value + self.CY_DBR_ENUM =DBR_ENUM #returns an unsigned short which is the enum item + self.CY_DBR_CHAR =DBR_CHAR #returns an unsigned char + self.CY_DBR_LONG =DBR_LONG #returns an unsigned long + self.CY_DBR_DOUBLE =DBR_DOUBLE #returns a double precision floating point number + self.CY_DBR_STS_STRING=DBR_STS_STRING #returns a string status structure (dbr_sts_string) + self.CY_DBR_STS_SHORT =DBR_STS_SHORT #returns a short status structure (dbr_sts_short) + self.CY_DBR_STS_INT =DBR_STS_INT #returns a short status structure (dbr_sts_int) + self.CY_DBR_STS_FLOAT =DBR_STS_FLOAT #returns a float status structure (dbr_sts_float) + self.CY_DBR_STS_ENUM =DBR_STS_ENUM #returns an enum status structure (dbr_sts_enum) + self.CY_DBR_STS_CHAR =DBR_STS_CHAR #returns a char status structure (dbr_sts_char) + self.CY_DBR_STS_LONG =DBR_STS_LONG #returns a long status structure (dbr_sts_long) + self.CY_DBR_STS_DOUBLE=DBR_STS_DOUBLE #returns a double status structure (dbr_sts_double) + self.CY_DBR_TIME_STRING=DBR_TIME_STRING #returns a string time structure (dbr_time_string) + self.CY_DBR_TIME_SHORT =DBR_TIME_SHORT #returns a short time structure (dbr_time_short) + self.CY_DBR_TIME_INT =DBR_TIME_INT #returns a short time structure (dbr_time_short) + self.CY_DBR_TIME_FLOAT =DBR_TIME_FLOAT #returns a float time structure (dbr_time_float) + self.CY_DBR_TIME_ENUM =DBR_TIME_ENUM #returns an enum time structure (dbr_time_enum) + self.CY_DBR_TIME_CHAR =DBR_TIME_CHAR #returns a char time structure (dbr_time_char) + self.CY_DBR_TIME_LONG =DBR_TIME_LONG #returns a long time structure (dbr_time_long) + self.CY_DBR_TIME_DOUBLE=DBR_TIME_DOUBLE #returns a double time structure (dbr_time_double) + self.CY_DBR_GR_STRING =DBR_GR_STRING #returns a graphic string structure (dbr_gr_string) + self.CY_DBR_GR_SHORT =DBR_GR_SHORT #returns a graphic short structure (dbr_gr_short) + self.CY_DBR_GR_INT =DBR_GR_INT #returns a graphic short structure (dbr_gr_int) + self.CY_DBR_GR_FLOAT =DBR_GR_FLOAT #returns a graphic float structure (dbr_gr_float) + self.CY_DBR_GR_ENUM =DBR_GR_ENUM #returns a graphic enum structure (dbr_gr_enum) + self.CY_DBR_GR_CHAR =DBR_GR_CHAR #returns a graphic char structure (dbr_gr_char) + self.CY_DBR_GR_LONG =DBR_GR_LONG #returns a graphic long structure (dbr_gr_long) + self.CY_DBR_GR_DOUBLE =DBR_GR_DOUBLE #returns a graphic double structure (dbr_gr_double) + self.CY_DBR_CTRL_STRING=DBR_CTRL_STRING #returns a control string structure (dbr_ctrl_int) + self.CY_DBR_CTRL_SHORT =DBR_CTRL_SHORT #returns a control short structure (dbr_ctrl_short) + self.CY_DBR_CTRL_INT =DBR_CTRL_INT #returns a control short structure (dbr_ctrl_int) + self.CY_DBR_CTRL_FLOAT =DBR_CTRL_FLOAT #returns a control float structure (dbr_ctrl_float) + self.CY_DBR_CTRL_ENUM =DBR_CTRL_ENUM #returns a control enum structure (dbr_ctrl_enum) + self.CY_DBR_CTRL_CHAR =DBR_CTRL_CHAR #returns a control char structure (dbr_ctrl_char) + self.CY_DBR_CTRL_LONG =DBR_CTRL_LONG #returns a control long structure (dbr_ctrl_long) + self.CY_DBR_CTRL_DOUBLE=DBR_CTRL_DOUBLE #returns a control double structure (dbr_ctrl_double) + return + + + +cdef class channelInfo: + cdef readonly long channelID + cdef readonly bint connectFlag + cdef readonly string hostName + cdef readonly unsigned int nelem #native + cdef readonly int dataType; #native + cdef readonly unsigned short accessRead; #0 or 1 + cdef readonly unsigned short accessWrite; #0 or 1 + cdef readonly string className; #dbr_class_name_t + cdef readonly int connectionState; #as given by CA_OP_ + cdef readonly int cafeConnectionState; #as given by cafe_cs_state + cdef readonly string connectionStateAsString; #as given by CA_OP_ + cdef readonly string cafeConnectionStateAsString; #as given by cafe_cs_state + cdef CAFEDataTypeCode cdt + cdef CAFEStatusCode csc + cdef CAOPCodes caop + + def __cinit__(self): + self.channelID=0 + self.connectFlag=False + self.hostName='' + self.nelem=0 + self.dataType=ICAFE_TYPENOTCONN + self.accessRead=0 + self.accessWrite=0 + self.className='' + self.connectionState=ICAFE_CA_OP_CONN_DOWN + self.cafeConnectionState=ICAFE_CS_NEVER_CONN + self.connectionStateAsString='ICAFE_CA_OP_CONN_DOWN' + self.cafeConnectionStateAsString='ICAFE_CS_NEVER_CONN' + + def show(self): + print ("channelID = %x" % self.channelID) + print ("connectFlag = %d" % self.connectFlag) + print ("hostName = %s" % self.hostName) + print ("nelem = %d" % self.nelem) + print ("dataType = %s (%d)" % (self.cdt.message(self.dataType), self.dataType)) + print ("accessRead = %d" % self.accessRead) + print ("accessWrite = %d" % self.accessWrite) + print ("className = %s" % self.className) + #print ("connectionState = %s (%d)" % (self.connectionStateAsString, self.connectionState)) + #print ("cafeConnectionState = %s (%d)" % (self.cafeConnectionStateAsString,self.cafeConnectionState)) + print ("connectionState = %s (%d)" % (self.caop.message(self.connectionState),self.connectionState)) + print ("cafeConnectionState = %s (%d)" % (self.csc.message(self.cafeConnectionState),self.cafeConnectionState)) + return + + + +################################################################################## +cdef class _epicsTimeStampAsDate: + cdef epicsTime *_time + cdef local_tm_nano_sec local + cdef list etsDate + def __cinit__(self, epicsTimeStamp ts): + self._time = new epicsTime(ts) + self.local = (self._time) + + print "ts====== ", ts.secPastEpoch, ts.nsec + + print "year=== ", ( ( (&(&self.local).ansi_tm).tm_year) + 1900) + + self.etsDate=[] + self.etsDate.append( (self.local.ansi_tm.tm_year + 1900)) + self.etsDate.append( (self.local.ansi_tm.tm_mon + 1)) + self.etsDate.append( self.local.ansi_tm.tm_mday) + self.etsDate.append( self.local.ansi_tm.tm_hour) + self.etsDate.append( self.local.ansi_tm.tm_min) + self.etsDate.append( self.local.ansi_tm.tm_sec) + self.etsDate.append( ts.nsec) + self.etsDate.append( self.local.nSec) + def get(self): + return self.etsDate + + +################################################################################## + +################################################################################## +cdef class pvctrl: + cdef readonly unsigned int nelem + cdef readonly int alarmStatus + cdef readonly int alarmSeverity + cdef readonly unsigned short precision + cdef readonly string units + cdef readonly unsigned short noEnumStrings + cdef readonly list enumStrings + cdef readonly upperDisplayLimit + cdef readonly lowerDisplayLimit + cdef readonly upperAlarmLimit + cdef readonly upperWarningLimit + cdef readonly lowerWarningLimit + cdef readonly lowerAlarmLimit + cdef readonly upperControlLimit + cdef readonly lowerControlLimit + cdef readonly list value + cdef readonly int status + + def __cinit__(self): + self.nelem= 1 + self.alarmStatus=-1 + self.alarmSeverity=-1 + self.precision=0 + self.units="" + self.noEnumStrings=0 + self.enumStrings=[] + self.upperDisplayLimit=0 + self.lowerDisplayLimit=0 + self.upperAlarmLimit=0 + self.lowerAlarmLimit=0 + self.upperControlLimit=0 + self.lowerControlLimit=0 + self.value=[] + self.status=1 + + + def show(self): + self.showPrint(self.nelem) + return + + def showMax(self, nelem): + if nelem > self.nelem: + #print "----------------------" + #print "Note: Max. Nelem =", self.nelem + #print "----------------------" + nelem=self.nelem + self.showPrint(nelem) + return + + cdef showPrint(self, nelem): + cdef unsigned int i + #is self.value[0] a list + if nelem==1: + if isinstance (self.value[0], list): + print "value =", self.value[0][0], + else: + print "value =", self.value[0], + else: + print "values =", + if isinstance (self.value[0], list): + for i in range(0, nelem): + print self.value[0][i],"[%d]" %i, + else: + for i in range(0, nelem): + print self.value[i],"[%d]" %i, + print "" + print ("status = %d" % self.status) + print ("alarmStatus = %d" % self.alarmStatus) + print ("alarmSeverity = %d" % self.alarmSeverity) + print ("precision = %d" % self.precision) + print ("units = %s" % self.units) + print ("noEnumStrings = %d" % self.noEnumStrings) + + if self.noEnumStrings > 0: + print "enumStrings =", + for i in range(0, self.noEnumStrings): + print self.enumStrings[i],"[%s]" %i, + print "" + + print ("upperDisplayLimit = %f" % self.upperDisplayLimit) + print ("lowerDisplayLimit = %f" % self.lowerDisplayLimit) + print ("upperAlarmLimit = %f" % self.upperAlarmLimit) + print ("lowerAlarmLimit = %f" % self.lowerAlarmLimit) + print ("upperWarningLimit = %f" % self.upperWarningLimit) + print ("lowerWarningLimit = %f" % self.lowerWarningLimit) + print ("upperControlLimit = %f" % self.upperControlLimit) + print ("lowerControlLimit = %f" % self.lowerControlLimit) + + return +################################################################################## + + +################################################################################## +cdef class pvdata: + cdef readonly unsigned int nelem + cdef readonly int alarmStatus + cdef readonly int alarmSeverity + cdef readonly list ts + cdef readonly list tsDate + cdef readonly list value + cdef readonly int status + + + def __cinit__(self): + self.nelem= 1 + + self.alarmStatus=-1 + self.alarmSeverity=-1 + self.ts=[] + self.tsDate=[] + self.value=[] + self.status=1 + + + def show(self): + self.showPrint(self.nelem) + return + + def showMax(self, nelem): + if nelem > self.nelem: + #print "----------------------" + #print "Note: Max. Nelem =", self.nelem + #print "----------------------" + nelem=self.nelem + self.showPrint(nelem) + return + + cdef showPrint(self, nelem): + cdef unsigned int i + #is self.value[0] a list + + if nelem==1: + if isinstance (self.value[0], list): + print "value =", self.value[0][0], + else: + print "value =", self.value[0], + else: + print "values =", + if isinstance (self.value[0], list): + for i in range(0, nelem): + print self.value[0][i],"[%d]" %i, + else: + for i in range(0, nelem): + print self.value[i],"[%d]" %i, + print "" + print ("status = %d" % self.status) + #if self.alarmStatus != -1: + print ("alarmStatus = %d" % self.alarmStatus) + print ("alarmSeverity = %d" % self.alarmSeverity) + #if self.ts[0] != 0: + print "ts =", self.ts[0], self.ts[1] + print "tsDate =", self.tsDate[0], self.tsDate[1], \ + self.tsDate[2], self.tsDate[3],\ + self.tsDate[4], self.tsDate[5], self.tsDate[6] + return + +################################################################################## + + + + +################################################################################## +cdef class pvgroup: + cdef readonly list pvdata + cdef readonly unsigned int npv + cdef readonly string name + cdef readonly int groupStatus + cdef readonly unsigned int groupHandle + + def __cinit__(self): + self.groupStatus=ICAFE_NORMAL + return + + def show(self): + self.showPrint(npv=self.npv, grouplist=None) + return + + def showWithPV(self,glist): + if len(glist) != self.npv: + print "ERROR: GROUP MEMBER MISMATCH!!" + print glist, "has", len(glist), "members while group has", self.npv,"!!" + return + self.showPrint(self.npv, grouplist=glist) + return + + + def showMax(self, _npv): + if _npv > self.npv: + #print "----------------------" + #print "Note: Max. Npv =", self.npv + #print "----------------------" + _npv=self.npv + self.showPrint(npv=_npv, grouplist=None) + return + + cdef showPrint(self, npv, grouplist): + print "GROUP NAME = ", self.name + print "GROUP HANDLE = ", self.groupHandle + print "GROUP STATUS = ", self.groupStatus + cdef unsigned int i,j + #if nelem==1: + # print "value =", self.value[0], + #else: + + + for i in range(0, npv): + print "Member: ", i, "---------------------------------" + if grouplist: + print "PV =", grouplist[i] + + print "values =", + for j in range(0, len(self.pvdata[i].value)): + print self.pvdata[i].value[j],"[%d]" %j, + print "" + print ("status = %d" % self.pvdata[i].status) + print ("alarmStatus = %d" % self.pvdata[i].alarmStatus) + print ("alarmSeverity = %d" % self.pvdata[i].alarmSeverity) + print "ts =", self.pvdata[i].ts[0], self.pvdata[i].tsDate[1] + print "tsDate =", self.pvdata[i].tsDate[0], self.pvdata[i].tsDate[1], \ + self.pvdata[i].tsDate[2], self.pvdata[i].tsDate[3],\ + self.pvdata[i].tsDate[4], self.pvdata[i].tsDate[5], self.pvdata[i].tsDate[6] + print "--------------------------------------------" + return + + + ''' + cdef showPrintWithPVName(self, npv, pvlist): + print "GROUP NAME = ", self.name + print "GROUP HANDLE = ", self.groupHandle + print "GROUP STATUS = ", self.groupStatus + cdef unsigned int i,j + + for i in range(0, npv): + print "pv =", pvlist[i] + for j in range(0, len(self.pvdata[i].value)): + print self.pvdata[i].value[j],"[%d]" %j, + print "" + print ("status = %d" % self.pvdata[i].status) + print ("alarmStatus = %d" % self.pvdata[i].alarmStatus) + print ("alarmSeverity = %d" % self.pvdata[i].alarmSeverity) + print "ts =", self.pvdata[i].ts[0], self.pvdata[i].tsDate[1] + print "tsDate =", self.pvdata[i].tsDate[0], self.pvdata[i].tsDate[1], \ + self.pvdata[i].tsDate[2], self.pvdata[i].tsDate[3],\ + self.pvdata[i].tsDate[4], self.pvdata[i].tsDate[5], self.pvdata[i].tsDate[6] + return + ''' +################################################################################## + + + +################################################################################## +cdef getMatchedDataType(dt, dtn): + #dt: input from user + #dtn: native type + #dtcheck: matching data type for pvd convert method + + cdef unsigned int dtcheck=dtn; + + if dt in ['int','long','short','uint','ulong','ushort','int32','int64','uint32','uint64']: + dtcheck=CAFE_LONG + elif dt=='double': + dtcheck=CAFE_DOUBLE + elif dt=='float': + dtcheck=CAFE_DOUBLE + elif dt in ['string','str']: + dtcheck=CAFE_STRING + elif dt in ['native','']: + dtcheck=dtn #need a line here + else: + print "Valid input parameters for data type are: 'int', 'float', 'str', or 'native'" + print "Data to be presented in native data type" + + return dtcheck +################################################################################## + + + +################################################################################# + +#cdef pvdata p1 = pvdata() +#cdef pvctrl c1 = pvctrl() + + +################################################################################# + +cdef pvdata PVDataHolderToStruct(PVDataHolder pvd, dt=None): + + #global p1 + cdef pvdata p1 = pvdata() + + cdef unsigned int dtn = pvd.getDataType(); + cdef unsigned int dtcheck=dtn + cdef localList=[] + + if dt: + dtcheck=getMatchedDataType(dt, dtn) + + if dtcheck==CAFE_STRING: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsString(i)) + elif dtcheck==CAFE_SHORT: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) #getAsShort(i) + elif dtcheck==CAFE_FLOAT: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsDouble(i)) #getAsFloat(i) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + #if self._c_cafe.isEnum(handle)==1: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsString(i)) + #else: + # for i in range(0, pvd.getNelem()): + # localList.append(pvd.getAsLong(i)) #getAsUShort(i) + elif dtcheck==CAFE_CHAR: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) # pvd.getAsChar(i) + elif dtcheck==CAFE_LONG: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsLong(i)) + elif dtcheck==CAFE_DOUBLE: + for i in range(0, pvd.getNelem()): + localList.append(pvd.getAsDouble(i)) + else: + localList.append(0) + #print "This line in PyCafe def getDataHolderToStruct should never appear!" + #print "No Data! Error. Is channel connected?" + + p1.value=localList + p1.status=pvd.getStatus() + p1.nelem=pvd.getNelem() + p1.alarmStatus=pvd.getAlarmStatus() + p1.alarmSeverity=pvd.getAlarmSeverity() + + pvd._etsNorm=pvd.getEpicsTimeStampAsUInt32() + + cpdef ll=[] + ll.append((pvd._etsNorm).secPastEpoch) + ll.append((pvd._etsNorm).nsec) + p1.ts=ll + + pvd._etsDate=pvd.getEpicsTimeStampAsDate() + + cpdef ld=[] + ld.append( (pvd._etsDate).year ) + ld.append( (pvd._etsDate).mon ) + ld.append( (pvd._etsDate).day ) + ld.append( (pvd._etsDate).hour ) + ld.append( (pvd._etsDate).min ) + ld.append( (pvd._etsDate).sec ) + ld.append( (pvd._etsDate).nsec ) + p1.tsDate=ld + + return p1 +################################################################################## + + + +################################################################################# + +cdef pvctrl PVCtrlHolderToStruct(PVCtrlHolder pvc, dt=None): + + #global c1 + cdef pvctrl c1 = pvctrl() + + cdef unsigned int dtn = pvc.getDataType(); + + cdef unsigned int dtcheck=dtn + + cdef localList=[] + + if dt: + dtcheck=getMatchedDataType(dt, dtn) + + if dtcheck==CAFE_STRING: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsString(i)) + elif dtcheck==CAFE_SHORT: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) #getAsShort(i) + elif dtcheck==CAFE_FLOAT: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsDouble(i)) #getAsFloat(i) + elif dtcheck==CAFE_ENUM: + #if enum, string taken as native + #if self._c_cafe.isEnum(handle)==1: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsString(i)) + #else: + # for i in range(0, pvd.getNelem()): + # localList.append(pvd.getAsLong(i)) #getAsUShort(i) + elif dtcheck==CAFE_CHAR: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) # pvd.getAsChar(i) + elif dtcheck==CAFE_LONG: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsLong(i)) + elif dtcheck==CAFE_DOUBLE: + for i in range(0, pvc.getNelem()): + localList.append(pvc.getAsDouble(i)) + else: + localList.append(0) + #print "This line in PyCafe def getDataHolderToStruct should never appear!" + #print "No Data! Error. Is channel connected?" + c1.value=localList + c1.status=pvc.getStatus() + c1.nelem=pvc.getNelem() + c1.alarmStatus=pvc.getAlarmStatus() + c1.alarmSeverity=pvc.getAlarmSeverity() + + c1.precision=pvc.getPrecision() + c1.noEnumStrings=pvc.getNoEnumStrings() + + enumList=[] + for i in range(0, pvc.getNoEnumStrings()): + enumList.append(pvc.getEnumStrings()[i]) + + c1.enumStrings=enumList + + c1.units=pvc.getUnitsAsString() + + c1.upperDisplayLimit=pvc.getUpperDispLimit_AsDouble() + c1.lowerDisplayLimit=pvc.getLowerDispLimit_AsDouble() + c1.upperAlarmLimit =pvc.getUpperAlarmLimit_AsDouble() + c1.upperWarningLimit=pvc.getUpperWarningLimit_AsDouble() + c1.lowerWarningLimit=pvc.getLowerWarningLimit_AsDouble() + c1.lowerAlarmLimit =pvc.getLowerAlarmLimit_AsDouble() + c1.upperControlLimit=pvc.getUpperCtrlLimit_AsDouble() + c1.lowerControlLimit=pvc.getLowerCtrlLimit_AsDouble() + + return c1 +################################################################################## + + +################################################################################# + +cdef channelInfo channelRegaliaToStruct(ChannelRegalia cr): + + cdef channelInfo ci = channelInfo() + + ci.channelID = ( cr.getChannelID()) + ci.connectFlag=cr.getConnectFlag() + ci.hostName =cr.getHostNameAsString() + ci.dataType =cr.getDataType() + ci.className =cr.getClassNameAsString() + ci.accessRead =cr.getAccessRead() + ci.accessWrite=cr.getAccessWrite() + ci.nelem =cr.getNelem() + ci.connectionState =cr.getConnectionState() + ci.cafeConnectionState=cr.getCafeConnectionState() + ci.connectionStateAsString =cr.getConnectionStateAsString() + ci.cafeConnectionStateAsString =cr.getCafeConnectionStateAsString() + return ci +################################################################################# + diff --git a/cNodes.xml b/cNodes.xml new file mode 100644 index 0000000..200fd08 --- /dev/null +++ b/cNodes.xml @@ -0,0 +1,3230 @@ + + + Collection of Nodes at SwissFEL + + X + Y + X0 + Y0 + REF-X + REF-Y + REFOFF-X + REFOFF-Y + REFORB-X + REFORB-Y + SET-GAIN + I + FB-STAT + FB-ENABLE + STAT + ENABLE + + + SINEG01-DBPM340 + + + SINSB01-DBPM150 + + + SINSB02-DBPM150 + + + SINLH01-DBPM060 + + + SINLH02-DBPM210 + + + SINLH02-DBPM240 + + + SINLH03-DBPM010 + + + SINLH03-DBPM050 + + + SINLH03-DBPM090 + + + SINSB03-DBPM120 + + + SINSB03-DBPM220 + + + SINSB04-DBPM120 + + + SINSB04-DBPM220 + + + SINSB05-DBPM120 + + + SINSB05-DBPM220 + + + SINXB01-DBPM120 + + + SINBC01-DBPM010 + + + SINBC01-DBPM030 + + + SINBC01-DBPM080 + + + SINBC01-DBPM100 + + + SINBC02-DBPM140 + + + SINBC02-DBPM320 + + + SINDI01-DBPM010 + + + SINDI01-DBPM060 + + + SINDI02-DBPM010 + + + SINDI02-DBPM040 + + + SINDI02-DBPM080 + + + S10CB01-DBPM220 + + + S10CB01-DBPM420 + + + S10CB02-DBPM220 + + + S10CB02-DBPM420 + + + S10DI01-DBPM110 + + + S10CB03-DBPM220 + + + S10CB03-DBPM420 + + + S10CB04-DBPM220 + + + S10CB04-DBPM420 + + + S10CB05-DBPM220 + + + S10CB05-DBPM420 + + + S10CB06-DBPM220 + + + S10CB06-DBPM420 + + + S10CB07-DBPM220 + + + S10CB07-DBPM420 + + + S10CB08-DBPM220 + + + S10CB08-DBPM420 + + + S10CB09-DBPM220 + + + S10BC01-DBPM010 + + + S10BC01-DBPM050 + + + S10BC01-DBPM090 + + + S10BC02-DBPM140 + + + S10BC02-DBPM320 + + + S10MA01-DBPM010 + + + S10MA01-DBPM060 + + + S10MA01-DBPM120 + + + S20CB01-DBPM420 + + + S20CB02-DBPM420 + + + S20CB03-DBPM420 + + + S20SY01-DBPM010 + + + S20SY01-DBPM040 + + + S20SY01-DBPM060 + + + S20SY02-DBPM080 + + + S20SY02-DBPM120 + + + S20SY02-DBPM150 + + + S20SY03-DBPM010 + + + S20SY03-DBPM040 + + + S20SY03-DBPM080 + + + S30CB01-DBPM420 + + + S30CB02-DBPM420 + + + S30CB03-DBPM420 + + + S30CB04-DBPM420 + + + S30CB05-DBPM420 + + + S30CB06-DBPM420 + + + S30CB07-DBPM420 + + + S30CB08-DBPM420 + + + S30CB09-DBPM420 + + + S30CB10-DBPM420 + + + S30CB11-DBPM420 + + + S30CB12-DBPM420 + + + S30CB13-DBPM420 + + + S30CB14-DBPM420 + + + S30CB15-DBPM420 + + + SARCL01-DBPM010 + + + SARCL01-DBPM060 + + + SARCL01-DBPM120 + + + SARCL01-DBPM150 + + + SARCL02-DBPM110 + + + SARCL02-DBPM220 + + + SARCL02-DBPM260 + + + SARCL02-DBPM330 + + + SARCL02-DBPM470 + + + SARMA01-DBPM040 + + + SARMA01-DBPM100 + + + SARMA02-DBPM010 + + + SARMA02-DBPM020 + + + SARMA02-DBPM040 + + + SARMA02-DBPM110 + + + SARUN01-DBPM070 + + + SARUN02-DBPM070 + + + SARUN03-DBPM070 + + + SARUN04-DBPM070 + + + SARUN05-DBPM070 + + + SARUN06-DBPM070 + + + SARUN07-DBPM070 + + + SARUN08-DBPM070 + + + SARUN09-DBPM070 + + + SARUN10-DBPM070 + + + SARUN11-DBPM070 + + + SARUN12-DBPM070 + + + SARUN13-DBPM070 + + + SARUN14-DBPM070 + + + SARUN15-DBPM070 + + + SARUN16-DBPM070 + + + SARUN17-DBPM070 + + + SARUN18-DBPM070 + + + SARUN19-DBPM070 + + + SARUN20-DBPM070 + + + SATSY01-DBPM010 + + + SATSY01-DBPM060 + + + SATSY01-DBPM100 + + + SATSY01-DBPM240 + + + SATSY01-DBPM290 + + + SATSY02-DBPM020 + + + SATSY02-DBPM210 + + + SATSY03-DBPM030 + + + SATSY03-DBPM060 + + + SATSY03-DBPM090 + + + SATSY03-DBPM120 + + + SATCL01-DBPM140 + + + SATDI01-DBPM030 + + + SATDI01-DBPM060 + + + SATDI01-DBPM210 + + + SATDI01-DBPM240 + + + SATDI01-DBPM270 + + + SATDI01-DBPM310 + + + SATCB01-DBPM220 + + + SATCB01-DBPM420 + + + SATCB02-DBPM220 + + + SATCB02-DBPM420 + + + SATMA01-DBPM010 + + + SATMA01-DBPM020 + + + SATMA01-DBPM040 + + + S10BD01-DBPM020 + + + SARBD01-DBPM040 + + + SARBD02-DBPM010 + + + SARBD02-DBPM040 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MCRX120 + + + SINEG01-MCRX160 + + + SINEG01-MCRX180 + + + SINEG01-MCRX200 + + + SINEG01-MCRX220 + + + SINSB01-MCRX010 + + + SINSB02-MCRX010 + + + SINLH01-MCRX020 + + + SINLH01-MCRX050 + + + SINLH02-MCRX010 + + + SINLH02-MCRX100 + + + SINLH02-MCRX200 + + + SINLH02-MCRX300 + + + SINLH02-MCRX400 + + + SINLH02-MCRX410 + + + SINLH03-MCRX040 + + + SINLH03-MCRX080 + + + SINSB03-MCRX130 + + + SINSB03-MCRX230 + + + SINSB04-MCRX130 + + + SINSB04-MCRX230 + + + SINSB05-MCRX130 + + + SINSB05-MCRX230 + + + SINBC01-MCRX020 + + + SINBC01-MCRX050 + + + SINBC01-MCRX070 + + + SINBC01-MCRX090 + + + SINBC01-MCRX110 + + + SINBC02-MCRX100 + + + SINBC02-MCRX200 + + + SINBC02-MCRX300 + + + SINBC02-MCRX400 + + + SINDI01-MCRX020 + + + SINDI01-MCRX070 + + + SINDI02-MCRX020 + + + SINDI02-MCRX030 + + + SINDI02-MCRX050 + + + SINDI02-MCRX060 + + + SINDI02-MCRX090 + + + S10CB01-MCRX230 + + + S10CB01-MCRX430 + + + S10CB02-MCRX230 + + + S10CB02-MCRX430 + + + S10DI01-MCRX100 + + + S10DI01-MCRX120 + + + S10CB03-MCRX230 + + + S10CB03-MCRX430 + + + S10CB04-MCRX230 + + + S10CB04-MCRX430 + + + S10CB05-MCRX230 + + + S10CB05-MCRX430 + + + S10CB06-MCRX230 + + + S10CB06-MCRX430 + + + S10CB07-MCRX230 + + + S10CB07-MCRX430 + + + S10CB08-MCRX230 + + + S10CB08-MCRX430 + + + S10CB09-MCRX230 + + + S10BC01-MCRX020 + + + S10BC01-MCRX040 + + + S10BC01-MCRX060 + + + S10BC01-MCRX080 + + + S10BC01-MCRX100 + + + S10BC02-MCRX100 + + + S10BC02-MCRX200 + + + S10BC02-MCRX300 + + + S10BC02-MCRX400 + + + S10MA01-MCRX020 + + + S10MA01-MCRX050 + + + S10MA01-MCRX070 + + + S10MA01-MCRX100 + + + S10MA01-MCRX110 + + + S10MA01-MCRX130 + + + S20CB01-MCRX430 + + + S20CB02-MCRX430 + + + S20CB03-MCRX430 + + + S20SY01-MCRX020 + + + S20SY01-MCRX030 + + + S20SY01-MCRX050 + + + S20SY01-MCRX080 + + + S20SY02-MCRX060 + + + S20SY02-MCRX090 + + + S20SY02-MCRX130 + + + S20SY02-MCRX170 + + + S20SY03-MCRX020 + + + S20SY03-MCRX030 + + + S20SY03-MCRX050 + + + S20SY03-MCRX060 + + + S20SY03-MCRX100 + + + S30CB01-MCRX430 + + + S30CB02-MCRX430 + + + S30CB03-MCRX430 + + + S30CB04-MCRX430 + + + S30CB05-MCRX430 + + + S30CB06-MCRX430 + + + S30CB07-MCRX430 + + + S30CB08-MCRX430 + + + S30CB09-MCRX430 + + + S30CB10-MCRX430 + + + S30CB11-MCRX430 + + + S30CB12-MCRX430 + + + S30CB13-MCRX430 + + + S30CB14-MCRX430 + + + S30CB15-MCRX430 + + + SARCL01-MCRX020 + + + SARCL01-MCRX040 + + + SARCL01-MCRX070 + + + SARCL01-MCRX090 + + + SARCL01-MCRX130 + + + SARCL01-MCRX180 + + + SARCL02-MCRX100 + + + SARCL02-MCRX120 + + + SARCL02-MCRX200 + + + SARCL02-MCRX230 + + + SARCL02-MCRX240 + + + SARCL02-MCRX320 + + + SARCL02-MCRX340 + + + SARCL02-MCRX400 + + + SARCL02-MCRX450 + + + SARCL02-MCRX480 + + + SARCL02-MCRX500 + + + SARMA01-MCRX020 + + + SARMA01-MCRX050 + + + SARMA01-MCRX070 + + + SARMA01-MCRX110 + + + SARMA01-MCRX130 + + + SARMA02-MCRX050 + + + SARMA02-MCRX120 + + + SARUN01-MCRX080 + + + SARUN02-MCRX080 + + + SARUN03-MCRX010 + + + SARUN03-MCRX040 + + + SARUN03-MCRX080 + + + SARUN04-MCRX010 + + + SARUN04-MCRX040 + + + SARUN04-MCRX080 + + + SARUN05-MCRX010 + + + SARUN05-MCRX040 + + + SARUN05-MCRX080 + + + SARUN06-MCRX010 + + + SARUN06-MCRX040 + + + SARUN06-MCRX080 + + + SARUN07-MCRX010 + + + SARUN07-MCRX040 + + + SARUN07-MCRX080 + + + SARUN08-MCRX010 + + + SARUN08-MCRX040 + + + SARUN08-MCRX080 + + + SARUN09-MCRX010 + + + SARUN09-MCRX040 + + + SARUN09-MCRX080 + + + SARUN10-MCRX010 + + + SARUN10-MCRX040 + + + SARUN10-MCRX080 + + + SARUN11-MCRX010 + + + SARUN11-MCRX040 + + + SARUN11-MCRX080 + + + SARUN12-MCRX010 + + + SARUN12-MCRX040 + + + SARUN12-MCRX080 + + + SARUN13-MCRX010 + + + SARUN13-MCRX040 + + + SARUN13-MCRX080 + + + SARUN14-MCRX010 + + + SARUN14-MCRX040 + + + SARUN14-MCRX080 + + + SARUN15-MCRX010 + + + SARUN15-MCRX040 + + + SARUN15-MCRX080 + + + SARUN16-MCRX080 + + + SARUN17-MCRX080 + + + SARUN18-MCRX080 + + + SARUN19-MCRX080 + + + SARUN20-MCRX080 + + + SATSY01-MCRX020 + + + SATSY01-MCRX040 + + + SATSY01-MCRX070 + + + SATSY01-MCRX090 + + + SATSY01-MCRX210 + + + SATSY01-MCRX230 + + + SATSY01-MCRX260 + + + SATSY01-MCRX280 + + + SATSY01-MCRX300 + + + SATSY02-MCRX010 + + + SATSY02-MCRX110 + + + SATSY02-MCRX120 + + + SATSY02-MCRX230 + + + SATSY03-MCRX010 + + + SATSY03-MCRX040 + + + SATSY03-MCRX070 + + + SATSY03-MCRX100 + + + SATSY03-MCRX130 + + + SATCL01-MCRX100 + + + SATCL01-MCRX120 + + + SATCL01-MCRX130 + + + SATCL01-MCRX180 + + + SATCL01-MCRX190 + + + SATCL01-MCRX300 + + + SATDI01-MCRX040 + + + SATDI01-MCRX050 + + + SATDI01-MCRX220 + + + SATDI01-MCRX230 + + + SATDI01-MCRX250 + + + SATDI01-MCRX260 + + + SATDI01-MCRX280 + + + SATDI01-MCRX300 + + + SATCB01-MCRX230 + + + SATCB01-MCRX430 + + + SATCB02-MCRX230 + + + SATCB02-MCRX430 + + + SATMA01-MCRX050 + + + SARBD01-MCRX020 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MCRY120 + + + SINEG01-MCRY160 + + + SINEG01-MCRY180 + + + SINEG01-MCRY200 + + + SINEG01-MCRY220 + + + SINSB01-MCRY010 + + + SINSB02-MCRY010 + + + SINLH01-MCRY020 + + + SINLH01-MCRY050 + + + SINLH02-MCRY010 + + + SINLH02-MCRY410 + + + SINLH03-MCRY040 + + + SINLH03-MCRY080 + + + SINSB03-MCRY130 + + + SINSB03-MCRY230 + + + SINSB04-MCRY130 + + + SINSB04-MCRY230 + + + SINSB05-MCRY130 + + + SINSB05-MCRY230 + + + SINBC01-MCRY020 + + + SINBC01-MCRY050 + + + SINBC01-MCRY070 + + + SINBC01-MCRY090 + + + SINBC01-MCRY110 + + + SINDI01-MCRY020 + + + SINDI01-MCRY070 + + + SINDI02-MCRY020 + + + SINDI02-MCRY030 + + + SINDI02-MCRY050 + + + SINDI02-MCRY060 + + + SINDI02-MCRY090 + + + S10CB01-MCRY230 + + + S10CB01-MCRY430 + + + S10CB02-MCRY230 + + + S10CB02-MCRY430 + + + S10DI01-MCRY120 + + + S10CB03-MCRY230 + + + S10CB03-MCRY430 + + + S10CB04-MCRY230 + + + S10CB04-MCRY430 + + + S10CB05-MCRY230 + + + S10CB05-MCRY430 + + + S10CB06-MCRY230 + + + S10CB06-MCRY430 + + + S10CB07-MCRY230 + + + S10CB07-MCRY430 + + + S10CB08-MCRY230 + + + S10CB08-MCRY430 + + + S10CB09-MCRY230 + + + S10BC01-MCRY020 + + + S10BC01-MCRY040 + + + S10BC01-MCRY060 + + + S10BC01-MCRY080 + + + S10BC01-MCRY100 + + + S10MA01-MCRY020 + + + S10MA01-MCRY050 + + + S10MA01-MCRY070 + + + S10MA01-MCRY110 + + + S10MA01-MCRY130 + + + S20CB01-MCRY430 + + + S20CB02-MCRY430 + + + S20CB03-MCRY430 + + + S20SY01-MCRY020 + + + S20SY01-MCRY030 + + + S20SY01-MCRY050 + + + S20SY01-MCRY080 + + + S20SY02-MCRY060 + + + S20SY02-MCRY090 + + + S20SY02-MCRY130 + + + S20SY02-MCRY170 + + + S20SY03-MCRY020 + + + S20SY03-MCRY030 + + + S20SY03-MCRY050 + + + S20SY03-MCRY060 + + + S20SY03-MCRY100 + + + S30CB01-MCRY430 + + + S30CB02-MCRY430 + + + S30CB03-MCRY430 + + + S30CB04-MCRY430 + + + S30CB05-MCRY430 + + + S30CB06-MCRY430 + + + S30CB07-MCRY430 + + + S30CB08-MCRY430 + + + S30CB09-MCRY430 + + + S30CB10-MCRY430 + + + S30CB11-MCRY430 + + + S30CB12-MCRY430 + + + S30CB13-MCRY430 + + + S30CB14-MCRY430 + + + S30CB15-MCRY430 + + + SARCL01-MCRY020 + + + SARCL01-MCRY040 + + + SARCL01-MCRY070 + + + SARCL01-MCRY090 + + + SARCL01-MCRY130 + + + SARCL01-MCRY180 + + + SARCL02-MCRY120 + + + SARCL02-MCRY230 + + + SARCL02-MCRY240 + + + SARCL02-MCRY320 + + + SARCL02-MCRY340 + + + SARCL02-MCRY450 + + + SARCL02-MCRY480 + + + SARMA01-MCRY020 + + + SARMA01-MCRY050 + + + SARMA01-MCRY070 + + + SARMA01-MCRY110 + + + SARMA01-MCRY130 + + + SARMA02-MCRY050 + + + SARMA02-MCRY120 + + + SARUN01-MCRY080 + + + SARUN02-MCRY080 + + + SARUN03-MCRY010 + + + SARUN03-MCRY040 + + + SARUN03-MCRY080 + + + SARUN04-MCRY010 + + + SARUN04-MCRY040 + + + SARUN04-MCRY080 + + + SARUN05-MCRY010 + + + SARUN05-MCRY040 + + + SARUN05-MCRY080 + + + SARUN06-MCRY010 + + + SARUN06-MCRY040 + + + SARUN06-MCRY080 + + + SARUN07-MCRY010 + + + SARUN07-MCRY040 + + + SARUN07-MCRY080 + + + SARUN08-MCRY010 + + + SARUN08-MCRY040 + + + SARUN08-MCRY080 + + + SARUN09-MCRY010 + + + SARUN09-MCRY040 + + + SARUN09-MCRY080 + + + SARUN10-MCRY010 + + + SARUN10-MCRY040 + + + SARUN10-MCRY080 + + + SARUN11-MCRY010 + + + SARUN11-MCRY040 + + + SARUN11-MCRY080 + + + SARUN12-MCRY010 + + + SARUN12-MCRY040 + + + SARUN12-MCRY080 + + + SARUN13-MCRY010 + + + SARUN13-MCRY040 + + + SARUN13-MCRY080 + + + SARUN14-MCRY010 + + + SARUN14-MCRY040 + + + SARUN14-MCRY080 + + + SARUN15-MCRY010 + + + SARUN15-MCRY040 + + + SARUN15-MCRY080 + + + SARUN16-MCRY080 + + + SARUN17-MCRY080 + + + SARUN18-MCRY080 + + + SARUN19-MCRY080 + + + SARUN20-MCRY080 + + + SATSY01-MCRY020 + + + SATSY01-MCRY040 + + + SATSY01-MCRY070 + + + SATSY01-MCRY090 + + + SATSY01-MCRY210 + + + SATSY01-MCRY230 + + + SATSY01-MCRY260 + + + SATSY01-MCRY280 + + + SATSY01-MCRY300 + + + SATSY02-MCRY010 + + + SATSY02-MCRY100 + + + SATSY02-MCRY110 + + + SATSY02-MCRY120 + + + SATSY02-MCRY200 + + + SATSY02-MCRY230 + + + SATSY03-MCRY010 + + + SATSY03-MCRY040 + + + SATSY03-MCRY070 + + + SATSY03-MCRY100 + + + SATSY03-MCRY130 + + + SATCL01-MCRY120 + + + SATCL01-MCRY130 + + + SATCL01-MCRY180 + + + SATCL01-MCRY190 + + + SATDI01-MCRY040 + + + SATDI01-MCRY050 + + + SATDI01-MCRY220 + + + SATDI01-MCRY230 + + + SATDI01-MCRY250 + + + SATDI01-MCRY260 + + + SATDI01-MCRY280 + + + SATDI01-MCRY300 + + + SATCB01-MCRY230 + + + SATCB01-MCRY430 + + + SATCB02-MCRY230 + + + SATCB02-MCRY430 + + + SATMA01-MCRY050 + + + SARBD01-MCRY020 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MSOL010 + + + SINEG01-MSOL130 + + + SINSB01-MSOL110 + + + SINSB01-MSOL120 + + + SINSB01-MSOL130 + + + SINSB01-MSOL140 + + + SINSB02-MSOL110 + + + SINSB02-MSOL120 + + + SINSB02-MSOL130 + + + SINSB02-MSOL140 + + + + Collection of Nodes at SwissFEL + + + SINEG01-MCOR120 + + + SINEG01-MCOR160 + + + SINEG01-MCOR180 + + + SINEG01-MCOR200 + + + SINEG01-MCOR220 + + + SINSB01-MCOR010 + + + SINSB02-MCOR010 + + + S20SY02-MCOR060 + + + S20SY02-MCOR090 + + + S20SY02-MCOR130 + + + S20SY02-MCOR170 + + + SARCL01-MCOR040 + + + SARCL01-MCOR070 + + + SARCL01-MCOR090 + + + SARCL01-MCOR130 + + + SARCL01-MCOR180 + + + SARCL02-MCOR120 + + + SARCL02-MCOR230 + + + SARCL02-MCOR240 + + + SARCL02-MCOR320 + + + SARCL02-MCOR340 + + + SARCL02-MCOR450 + + + SARCL02-MCOR480 + + + SARMA01-MCOR020 + + + SARMA01-MCOR050 + + + SARMA01-MCOR070 + + + SARMA01-MCOR110 + + + SARMA01-MCOR130 + + + SARUN03-MCOR010 + + + SARUN03-MCOR040 + + + SARUN04-MCOR010 + + + SARUN04-MCOR040 + + + SARUN05-MCOR010 + + + SARUN05-MCOR040 + + + SARUN06-MCOR010 + + + SARUN06-MCOR040 + + + SARUN07-MCOR010 + + + SARUN07-MCOR040 + + + SARUN08-MCOR010 + + + SARUN08-MCOR040 + + + SARUN09-MCOR010 + + + SARUN09-MCOR040 + + + SARUN10-MCOR010 + + + SARUN10-MCOR040 + + + SARUN11-MCOR010 + + + SARUN11-MCOR040 + + + SARUN12-MCOR010 + + + SARUN12-MCOR040 + + + SARUN13-MCOR010 + + + SARUN13-MCOR040 + + + SARUN14-MCOR010 + + + SARUN14-MCOR040 + + + SARUN15-MCOR010 + + + SARUN15-MCOR040 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + DEGAUSS + + + SINEG01-MQUA140 + + + SINEG01-MQUA150 + + + SINEG01-MQUA310 + + + SINEG01-MQUA320 + + + SINLH01-MQUA020 + + + SINLH01-MQUA030 + + + SINLH01-MQUA040 + + + SINLH01-MQUA050 + + + SINLH01-MQUA070 + + + SINLH02-MQUA010 + + + SINLH02-MQUA410 + + + SINLH03-MQUA030 + + + SINLH03-MQUA040 + + + SINLH03-MQUA060 + + + SINLH03-MQUA080 + + + SINSB03-MQUA130 + + + SINSB03-MQUA230 + + + SINSB04-MQUA130 + + + SINSB04-MQUA230 + + + SINSB05-MQUA130 + + + SINSB05-MQUA230 + + + SINBC01-MQUA020 + + + SINBC01-MQUA050 + + + SINBC01-MQUA070 + + + SINBC01-MQUA090 + + + SINBC01-MQUA110 + + + SINBC02-MQUA110 + + + SINBC02-MQUA120 + + + SINBC02-MQUA340 + + + SINBC02-MQUA350 + + + SINDI01-MQUA020 + + + SINDI01-MQUA030 + + + SINDI01-MQUA070 + + + SINDI02-MQUA020 + + + SINDI02-MQUA030 + + + SINDI02-MQUA050 + + + SINDI02-MQUA060 + + + SINDI02-MQUA070 + + + SINDI02-MQUA090 + + + S10CB01-MQUA230 + + + S10CB01-MQUA430 + + + S10CB02-MQUA230 + + + S10CB02-MQUA430 + + + S10DI01-MQUA030 + + + S10DI01-MQUA120 + + + S10CB03-MQUA230 + + + S10CB03-MQUA430 + + + S10CB04-MQUA230 + + + S10CB04-MQUA430 + + + S10CB05-MQUA230 + + + S10CB05-MQUA430 + + + S10CB06-MQUA230 + + + S10CB06-MQUA430 + + + S10CB07-MQUA230 + + + S10CB07-MQUA430 + + + S10CB08-MQUA230 + + + S10CB08-MQUA430 + + + S10CB09-MQUA230 + + + S10BC01-MQUA020 + + + S10BC01-MQUA040 + + + S10BC01-MQUA060 + + + S10BC01-MQUA080 + + + S10BC01-MQUA100 + + + S10BC02-MQUA110 + + + S10BC02-MQUA120 + + + S10BC02-MQUA340 + + + S10BC02-MQUA350 + + + S10MA01-MQUA020 + + + S10MA01-MQUA050 + + + S10MA01-MQUA070 + + + S10MA01-MQUA110 + + + S10MA01-MQUA130 + + + S20CB01-MQUA430 + + + S20CB02-MQUA430 + + + S20CB03-MQUA430 + + + S20SY01-MQUA020 + + + S20SY01-MQUA030 + + + S20SY01-MQUA050 + + + S20SY01-MQUA080 + + + S20SY02-MQUA070 + + + S20SY02-MQUA100 + + + S20SY02-MQUA140 + + + S20SY02-MQUA180 + + + S20SY03-MQUA020 + + + S20SY03-MQUA030 + + + S20SY03-MQUA050 + + + S20SY03-MQUA060 + + + S20SY03-MQUA100 + + + S30CB01-MQUA430 + + + S30CB02-MQUA430 + + + S30CB03-MQUA430 + + + S30CB04-MQUA430 + + + S30CB05-MQUA430 + + + S30CB06-MQUA430 + + + S30CB07-MQUA430 + + + S30CB08-MQUA430 + + + S30CB09-MQUA430 + + + S30CB10-MQUA430 + + + S30CB11-MQUA430 + + + S30CB12-MQUA430 + + + S30CB13-MQUA430 + + + S30CB14-MQUA430 + + + S30CB15-MQUA430 + + + SARCL01-MQUA020 + + + SARCL01-MQUA050 + + + SARCL01-MQUA080 + + + SARCL01-MQUA100 + + + SARCL01-MQUA140 + + + SARCL01-MQUA190 + + + SARCL02-MQUA130 + + + SARCL02-MQUA150 + + + SARCL02-MQUA160 + + + SARCL02-MQUA210 + + + SARCL02-MQUA250 + + + SARCL02-MQUA300 + + + SARCL02-MQUA310 + + + SARCL02-MQUA350 + + + SARCL02-MQUA420 + + + SARCL02-MQUA430 + + + SARCL02-MQUA460 + + + SARMA01-MQUA010 + + + SARMA01-MQUA060 + + + SARMA01-MQUA080 + + + SARMA01-MQUA120 + + + SARMA01-MQUA140 + + + SARMA02-MQUA050 + + + SARMA02-MQUA120 + + + SARUN01-MQUA080 + + + SARUN02-MQUA080 + + + SARUN03-MQUA020 + + + SARUN03-MQUA050 + + + SARUN03-MQUA080 + + + SARUN04-MQUA020 + + + SARUN04-MQUA050 + + + SARUN04-MQUA080 + + + SARUN05-MQUA020 + + + SARUN05-MQUA050 + + + SARUN05-MQUA080 + + + SARUN06-MQUA020 + + + SARUN06-MQUA050 + + + SARUN06-MQUA080 + + + SARUN07-MQUA020 + + + SARUN07-MQUA050 + + + SARUN07-MQUA080 + + + SARUN08-MQUA020 + + + SARUN08-MQUA050 + + + SARUN08-MQUA080 + + + SARUN09-MQUA020 + + + SARUN09-MQUA050 + + + SARUN09-MQUA080 + + + SARUN10-MQUA020 + + + SARUN10-MQUA050 + + + SARUN10-MQUA080 + + + SARUN11-MQUA020 + + + SARUN11-MQUA050 + + + SARUN11-MQUA080 + + + SARUN12-MQUA020 + + + SARUN12-MQUA050 + + + SARUN12-MQUA080 + + + SARUN13-MQUA020 + + + SARUN13-MQUA050 + + + SARUN13-MQUA080 + + + SARUN14-MQUA020 + + + SARUN14-MQUA050 + + + SARUN14-MQUA080 + + + SARUN15-MQUA020 + + + SARUN15-MQUA050 + + + SARUN15-MQUA080 + + + SARUN16-MQUA080 + + + SARUN17-MQUA080 + + + SARUN18-MQUA080 + + + SARUN19-MQUA080 + + + SARUN20-MQUA080 + + + SATSY01-MQUA020 + + + SATSY01-MQUA030 + + + SATSY01-MQUA040 + + + SATSY01-MQUA070 + + + SATSY01-MQUA090 + + + SATSY01-MQUA210 + + + SATSY01-MQUA230 + + + SATSY01-MQUA260 + + + SATSY01-MQUA270 + + + SATSY01-MQUA280 + + + SATSY01-MQUA300 + + + SATSY02-MQUA010 + + + SATSY02-MQUA110 + + + SATSY02-MQUA120 + + + SATSY02-MQUA230 + + + SATSY03-MQUA010 + + + SATSY03-MQUA040 + + + SATSY03-MQUA070 + + + SATSY03-MQUA100 + + + SATSY03-MQUA130 + + + SATCL01-MQUA120 + + + SATCL01-MQUA130 + + + SATCL01-MQUA180 + + + SATCL01-MQUA190 + + + SATDI01-MQUA040 + + + SATDI01-MQUA050 + + + SATDI01-MQUA220 + + + SATDI01-MQUA230 + + + SATDI01-MQUA250 + + + SATDI01-MQUA260 + + + SATDI01-MQUA280 + + + SATDI01-MQUA300 + + + SATCB01-MQUA230 + + + SATCB01-MQUA430 + + + SATCB02-MQUA230 + + + SATCB02-MQUA430 + + + SATMA01-MQUA050 + + + S10BD01-MQUA010 + + + SARBD01-MQUA020 + + + SARBD02-MQUA030 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + DEGAUSS + + + SINEG01-MBND300 + + + SINLH02-MBND100 + + + SINLH02-MBND200 + + + SINLH02-MBND300 + + + SINLH02-MBND400 + + + SINBC02-MBND100 + + + SINBC02-MBND200 + + + SINBC02-MBND300 + + + SINBC02-MBND400 + + + S10DI01-MBND100 + + + S10BC02-MBND100 + + + S10BC02-MBND200 + + + S10BC02-MBND300 + + + S10BC02-MBND400 + + + S10MA01-MBND100 + + + S20SY02-MBND200 + + + SARCL02-MBND100 + + + SARCL02-MBND200 + + + SARCL02-MBND400 + + + SARCL02-MBND500 + + + SARMA02-MBND100 + + + SATSY01-MBND200 + + + SATSY01-MBND400 + + + SATSY02-MBND100 + + + SATSY02-MBND200 + + + SATCL01-MBND100 + + + SATCL01-MBND300 + + + SATMA01-MBND100 + + + SARBD01-MBND100 + + + SARBD01-MBND200 + + + + Collection of Nodes at SwissFEL + + CAV-AMPLT-AVG + CAV-POWER-AVG + CAV-PHASE-AVG + + + SINEG01-RGUN100 + + + + Collection of Nodes at SwissFEL + + FOR-AMPLT-AVG + FOR-POWER-AVG + FOR-PHASE-AVG + + + SINEG01-RWVG100 + + + SINSB01-RWVG100 + + + SINSB02-RWVG100 + + + SINSB03-RWVG100 + + + SINSB04-RWVG100 + + + SINXB01-RWVG100 + + + SINDI01-RWVG100 + + + S10CB01-RWVG100 + + + S10CB01-RWVG300 + + + S10CB02-RWVG100 + + + S10CB02-RWVG300 + + + S10CB03-RWVG100 + + + S10CB03-RWVG300 + + + S10CB04-RWVG100 + + + S10CB04-RWVG300 + + + S10CB05-RWVG100 + + + S10CB05-RWVG300 + + + S10CB06-RWVG100 + + + S10CB06-RWVG300 + + + S10CB07-RWVG100 + + + S10CB07-RWVG300 + + + S10CB08-RWVG100 + + + S10CB08-RWVG300 + + + S10CB09-RWVG100 + + + S10CB09-RWVG300 + + + S20CB01-RWVG100 + + + S20CB01-RWVG300 + + + S20CB02-RWVG100 + + + S20CB02-RWVG300 + + + S20CB03-RWVG100 + + + S20CB03-RWVG300 + + + S20CB04-RWVG100 + + + S20CB04-RWVG300 + + + S30CB01-RWVG100 + + + S30CB01-RWVG300 + + + S30CB02-RWVG100 + + + S30CB02-RWVG300 + + + S30CB03-RWVG100 + + + S30CB03-RWVG300 + + + S30CB04-RWVG100 + + + S30CB04-RWVG300 + + + S30CB05-RWVG100 + + + S30CB05-RWVG300 + + + S30CB06-RWVG100 + + + S30CB06-RWVG300 + + + S30CB07-RWVG100 + + + S30CB07-RWVG300 + + + S30CB08-RWVG100 + + + S30CB08-RWVG300 + + + S30CB09-RWVG100 + + + S30CB09-RWVG300 + + + S30CB10-RWVG100 + + + S30CB10-RWVG300 + + + S30CB11-RWVG100 + + + S30CB11-RWVG300 + + + S30CB12-RWVG100 + + + S30CB12-RWVG300 + + + S30CB13-RWVG100 + + + S30CB13-RWVG300 + + + S30CB14-RWVG100 + + + + Collection of Nodes at SwissFEL + + CAV-AMPLT-AVG + CAV-POWER-AVG + CAV-PHASE-AVG + + + SINSB01-RACC100 + + + SINSB02-RACC100 + + + SINSB03-RACC100 + + + SINSB03-RACC200 + + + SINSB04-RACC100 + + + SINSB04-RACC200 + + + SINXB01-RACC100 + + + SINXB01-RACC200 + + + S10CB01-RACC100 + + + S10CB01-RACC200 + + + S10CB01-RACC300 + + + S10CB01-RACC400 + + + S10CB02-RACC100 + + + S10CB02-RACC200 + + + S10CB02-RACC300 + + + S10CB02-RACC400 + + + S10CB03-RACC100 + + + S10CB03-RACC200 + + + S10CB03-RACC300 + + + S10CB03-RACC400 + + + S10CB04-RACC100 + + + S10CB04-RACC200 + + + S10CB04-RACC300 + + + S10CB04-RACC400 + + + S10CB05-RACC100 + + + S10CB05-RACC200 + + + S10CB05-RACC300 + + + S10CB05-RACC400 + + + S10CB06-RACC100 + + + S10CB06-RACC200 + + + S10CB06-RACC300 + + + S10CB06-RACC400 + + + S10CB07-RACC100 + + + S10CB07-RACC200 + + + S10CB07-RACC300 + + + S10CB07-RACC400 + + + S10CB08-RACC100 + + + S10CB08-RACC200 + + + S10CB08-RACC300 + + + S10CB08-RACC400 + + + S10CB09-RACC100 + + + S10CB09-RACC200 + + + S10CB09-RACC300 + + + S10CB09-RACC400 + + + S20CB01-RACC100 + + + S20CB01-RACC200 + + + S20CB01-RACC300 + + + S20CB01-RACC400 + + + S20CB02-RACC100 + + + S20CB02-RACC200 + + + S20CB02-RACC300 + + + S20CB02-RACC400 + + + S20CB03-RACC100 + + + S20CB03-RACC200 + + + S20CB03-RACC300 + + + S20CB03-RACC400 + + + S20CB04-RACC100 + + + S20CB04-RACC200 + + + S20CB04-RACC300 + + + S20CB04-RACC400 + + + S30CB01-RACC100 + + + S30CB01-RACC200 + + + S30CB01-RACC300 + + + S30CB01-RACC400 + + + S30CB02-RACC100 + + + S30CB02-RACC200 + + + S30CB02-RACC300 + + + S30CB02-RACC400 + + + S30CB03-RACC100 + + + S30CB03-RACC200 + + + S30CB03-RACC300 + + + S30CB03-RACC400 + + + S30CB04-RACC100 + + + S30CB04-RACC200 + + + S30CB04-RACC300 + + + S30CB04-RACC400 + + + S30CB05-RACC100 + + + S30CB05-RACC200 + + + S30CB05-RACC300 + + + S30CB05-RACC400 + + + S30CB06-RACC100 + + + S30CB06-RACC200 + + + S30CB06-RACC300 + + + S30CB06-RACC400 + + + S30CB07-RACC100 + + + S30CB07-RACC200 + + + S30CB07-RACC300 + + + S30CB07-RACC400 + + + S30CB08-RACC100 + + + S30CB08-RACC200 + + + S30CB08-RACC300 + + + S30CB08-RACC400 + + + S30CB09-RACC100 + + + S30CB09-RACC200 + + + S30CB09-RACC300 + + + S30CB09-RACC400 + + + S30CB10-RACC100 + + + S30CB10-RACC200 + + + S30CB10-RACC300 + + + S30CB10-RACC400 + + + S30CB11-RACC100 + + + S30CB11-RACC200 + + + S30CB11-RACC300 + + + S30CB11-RACC400 + + + S30CB12-RACC100 + + + S30CB12-RACC200 + + + S30CB12-RACC300 + + + S30CB12-RACC400 + + + S30CB13-RACC100 + + + S30CB13-RACC200 + + + S30CB13-RACC300 + + + S30CB13-RACC400 + + + + Collection of Nodes at SwissFEL + + GAP-READ + GAP_SP + EAB + + + SARUN03-UIND030 + + + SARUN04-UIND030 + + + SARUN05-UIND030 + + + SARUN06-UIND030 + + + SARUN07-UIND030 + + + SARUN08-UIND030 + + + SARUN09-UIND030 + + + SARUN10-UIND030 + + + SARUN11-UIND030 + + + SARUN12-UIND030 + + + SARUN13-UIND030 + + + SARUN14-UIND030 + + + SARUN15-UIND030 + + + diff --git a/examples.py b/examples.py new file mode 100644 index 0000000..eaec66d --- /dev/null +++ b/examples.py @@ -0,0 +1,1099 @@ +# python + +import time +import timeit +import numpy as np +import array +import inspect +import os +import operator +import sys +import PyCafe + + +cafe=PyCafe.CyCafe() +cyca=PyCafe.CyCa() + +############################################################## +# (1) Establishing connections to EPICS Process Variables (PVs) +# (2) Simple single channel operations +# (3) Waveforms and Arrays +# (4) Multiple scalar operations, i.e. operations on several PVs with scalar values +# (5) Multiple compound operations, i.e. operations on several PVS with either scalar values or arrays +# (6) Synchronous group operations +# (7) Control system parameters, i.e. operating limits, engineerimg units +# (8) Monitors, either with or without user supplied callbacks +# (9) Asynchronous interactions and retrieving data from Cache +#(10) Synchronous group operations, with externally defined groups +#(11) Special Methods, match, setAndMatch +#(END) Gracefully terminate CAFE +############################################################## + + +PY2=True +PY3=False + +if sys.version_info >= (3,0): + PY3=True + PY2=False + +print("This is Python Version:\n",sys.version_info) + +################################################################# +# Test channels +################################################################# +## For use in office network cao +PV1 ='ARIDI-BPM-01LE:X-AVG' +PV2 ='ARIDI-BPM-01LE:Y-AVG' +PV3 ='ARIDI-BPM-01LB:X-AVG' +PV4 ='ARIDI-BPM-01LB:Y-AVG' +PVWF1='ARIDI-BPM-01LE:WF-INT-2' +PVWF2='ARIDI-BPM-01LB:WF-INT-2' +PVWF3='ARIDI-BPM-01SE:WF-INT-2' +PVWF4='ARIDI-BPM-01SB:WF-INT-2' + +PVS='ARIDI-BPM-01SB:SET-ENABLE.DESC' + +PV_JOKE='PV-DOES-NOT:EXIST' + +PV_REAL='SAR-CMON-MAG4531:VOLTAGE-5' + +pvlist1 =[PV1,PV2,PV3,PV4] +pvlistWF =[PVWF1, PVWF2,PVWF3,PVWF4] +pvlistAll=[PV1,PV2,PV3,PV4,PVWF1,PVWF2,PVWF3,PVWF4,PVS,PV_JOKE] + +################################################################# + + +################################################################# +# A user supplied callback function to be (optionally) used in (8) Monitors +# (or puts and gets if required) +################################################################# +def py_callback(handle): + #operations permitted from within handle are getCache, set and close + #open, get and monitorStart are not permitted + try: + print ("") + print ("START: MONITOR CALLBACK HANDLER INVOKED FOR HANDLE:", handle) + #Usual action is to get the updated value + print ("isConnected?", cafe.isConnected(handle)); + print ("Channel=", cafe.getPVNameFromHandle(handle)) + print ("Value =", cafe.getCache(handle)) #native format + print ("Value =", cafe.getCache(handle, dt='str')) #else dt='int', dt='float' + #print ("DbrDataType =", cafe.getDbrDataTypeInCallback(handle) ) + #print ("DataType =", cafe.getDataTypeInCallback(handle) ) + #print ("DbrBase =", cafe.getDbrBaseInCallback(handle) ) + + #This retrieves all the parameters that acted as input to the monitor + #Input is handle and monitorId + monid= cafe.getMonitorIDInCallback(handle) + print ("monid ", monid) + #mp=cafe.getMonitorPolicyVector(handle, monid) + #mp.show() + + #get PVData + p1=cafe.getPVCache(handle) + p1.showMax(10) #if waveform print only first 10 elements + #alternatively: + print ("Value =", p1.value[0]) + print ("status = %d" % p1.status) + print ("alarmStatus = %d" % p1.alarmStatus) + print ("alarmSeverity = %d" % p1.alarmSeverity) + print ("ts =", p1.ts[0], p1.ts[1]) + print ("tsDate =", p1.tsDate[0], p1.tsDate[1], \ + p1.tsDate[2], p1.tsDate[3],\ + p1.tsDate[4], p1.tsDate[5], p1.tsDate[6] ) + + #Increment value - set to this channel + #newValue=1+pv.value[0] + #if newValue < 10: + # cafe.set(handle, newValue) + + except Exception as inst: + print ("ERROR IN CALLBACK HANDLER:") + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + + print ("END: MONITOR CALLBACK HANDLER COMPLETED FOR HANDLE:", handle) + print ("") + return +############################################################## + +################################################################# +# A user supplied callback function for put operations (optional) +################################################################# +def py_callback_put(handle): + print ("Put HANDLER COMPLETED FOR HANDLE:", handle) + return + +################################################################# +# A user supplied callback function for get operations (optional) +################################################################# +def py_callback_get(handle): + print ("Channel=", cafe.getPVNameFromHandle(handle)) + print ("Value =", cafe.getCache(handle)) #native format + print ("Get HANDLER COMPLETED FOR HANDLE:", handle) + return +############################################################## + + +############################################################## +#(1) Establishing connections to EPICS Process Variables (PVs) +############################################################## +#Explicitly opening channels is good practice even if only optional + + +print("INFO: pend time for open",cafe.getOpenDefaultPendTime()) +#open a single channel +try: + handleS=cafe.open(PVS); +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + +#better practice is to open all channels at once + +start=time.time() + +cafe.openPrepare() + +try: + #return list of handles + hlist1 =cafe.open(pvlist1) + hlistWF =cafe.open(pvlistWF) + hlistAll=cafe.open(pvlistAll) #Note: only one handle per channel is created +except Exception as inst: + + print(inst.args) + +cafe.openNowAndWait(0.5) #wait 500ms for channels to connect + +end=time.time() +print(end-start) + +if cafe.allConnected()==False: + cafe.printDisconnected() + +#Alternatively +if cafe.allConnected()==False: + h,pv=cafe.getDisconnectedHandles() + print("---------------------") + print("DISCONNECTED CHANNELS") + print("---------------------") + for i in range (0,len(h)): + print (h[i], " ", pv[i]) + +#Alternatively - show all handles +#cafe.printHandles() +h,pv=cafe.getHandles() +print("---------------------") +print("ALL CHANNELS") +print("---------------------") +for i in range (0,len(h)): + print (h[i], " ", pv[i]) +h,pv,state=cafe.getHandleStates() +print("---------------------") +print("ALL CHANNELS AND CONNECTION STATE") +print("---------------------") +for i in range (0,len(h)): + print (h[i], " ", pv[i], " " , state[i]) +print("") +#END (1) Establishing connections to EPICS Process Variables (PVs) +############################################################## + +############################################################## +#(2) Simple single channel operations +############################################################## +#Now perform some get/set operations + +#input to get method can be the handle to the PV, or the PV name + +#If you prefer to check on the value (which will return +#a Python None in the event of a failed operation) rather +#than catch exceptions then it is possible to turn off exceptions: + +cafe.withExceptions(False); + +#get 'ARIDI-BPM-01SB:SET-ENABLE' by handle +val=cafe.get(hlistAll[8]); +#or +val=cafe.get(PVS); +if val == None: + #print ErrorCode by calling cafe.getStatus with handle or PVName as input argument + print (cafe.getStatus(hlistAll[8])) + #or + print (cafe.getStatus(PVS)) + #print meaning of error message + cafe.printStatusIfError(hlistAll[8],cafe.getStatus(hlistAll[8])) +else: + print ("Value=",val) + +#enumValue=cafe.getEnumFromString(PVS, val) +#print ("enumValue=",enumValue) +#enumString=cafe.getStringFromEnum(PVS, enumValue) +#print ("enumString=",enumString) + + +#This channel does not exist hence None will be returned +#The status code and error message will indicate that the channel was never connected +val=cafe.get(PV_JOKE) +if val == None: + cafe.printStatusIfError(PV_JOKE,cafe.getStatus(PV_JOKE)) +else: + print ("Value=", val) + +#Now use exceptions for single channel get/set operations +cafe.withExceptions(True); + +#Now perform some get operations +try: + val=cafe.get(hlistAll[8]) + print ("Channel: ", cafe.getPVNameFromHandle(hlistAll[8])," value=", val) +except Exception as inst: + print ("ERROR IN cafe.get") + print (inst) + +#Retrun pvdata struct, i.e., val, alarms, timestamps +try: + pv=cafe.getPV(hlistAll[8]) + pv.show() +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + cafeEx.reveal() + else: + print (inst) + +#Now perform a get operations on a disconnected channel +#and catche the exception being thrown +try: + val=cafe.get(PV_JOKE) #will throw an exception + print ("Channel: ", PV_JOKE," value=", val) +except Exception as inst: + print ("ERROR IN cafe.get for channel:", PV_JOKE) + + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + else: + print (inst) + +try: + val=cafe.get(hlistAll[3]) + print ("Channel: ", pvlistAll[3]," value=", val) + #or + print ("Channel: ", cafe.getPVNameFromHandle(hlistAll[3])," value=", val) +except Exception as inst: + print ("ERROR IN cafe.get for channel:", PV_JOKE) + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + #cafeEx.show() + cafeEx.reveal() + else: + print (inst) + + +#cafe.get on a WF will return first element only (see(3) fro WFs) +try: + val=cafe.get('ARIDI-BPM-01SE:WF-INT-2') #will throw an exception + print ('ARIDI-BPM-01SE:WF-INT-2 has val=',val) +except Exception as inst: + + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + +#Now perform a set operation on a waveform + +try: + print ("set") + cafe.set(PV1, 1.234) #set by pvname; value can be in any format + print ("get") + val=cafe.get(PV1,dt='native') #dt='native' (defulat) may be omitted + print ("Value (should be 1.234) =", val) #default dt='native' + + cafe.set(hlistAll[0], [4.321]) #set by handle + val=cafe.get(PV1, dt='str') #dt='int', dt='float' are other options + print ("Value (should be 4.321) =", val) + + #get pvdata struct + pv=cafe.getPV(PV1) + pv.show() + #or + print("Value =", pv.value[0]) + print("TS =", pv.ts[0], " " , pv.ts[1]) + print("tsDate =", pv.tsDate[0], pv.tsDate[1], \ + pv.tsDate[2], pv.tsDate[3],\ + pv.tsDate[4], pv.tsDate[5], pv.tsDate[6] ) + print ("") + +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + + +#Now perform a set/get operation with user supplied callbacks +try: + cafe.setCallbackGet(hlist1[0],cb=py_callback_get) + cafe.setCallbackPut(hlist1[0],cb=py_callback_put) + + s=cafe.set(hlist1[0],7.777) + v=cafe.get(hlist1[0]) + + print("Can you see if the callback functions were called for set/get?") + print("Value should be 7.777", v) + + print("Waiting 5 seconds to allow data to be viewed") + time.sleep(5) + #return to default callbacks + cafe.setCallbackGet(hlist1[0],cb=None) + cafe.setCallbackPut(hlist1[0],cb=None) + +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + + + +#END (2) Simple single channel operations +############################################################## + +############################################################## +#(3) Waveforms and Arrays +############################################################## +try: + NWF=5 + print ('setting no of elements for wf to ', cafe.setNelem(PVWF1,4084)) + #time.sleep(5) + + #waveform as Python List + print("Waveform as a Python List and native data type") + start = time.time() + for i in range (0,NWF): + valList=cafe.getList(PVWF1, dt='native'); + end = time.time() + print (end - start) + #print (valList) + #waveform as int and as numpy + print("Waveform as a numpy and dt='float'") + start = time.time() + for i in range (0,NWF): + valNumpy=cafe.getArray(hlistWF[0], dt='native', art='numpy'); #PVWF1, + end = time.time() + print (end - start) + #print (valNumpy) + # + #cafe.setNelem(PVWF1, 5) + + #waveform as a float and as a Python array.array + print("Waveform as a Python array.array and dt='float'") + start = time.time() + for i in range (0,NWF): + valArray=cafe.getArray(hlistWF[0], dt='native', art='array') #PVWF1, + end = time.time() + print (end - start) + #print (valArray) + for i in range (0,min(10,len(valArray))): + #print (valArray[i], " [",i,"] ", sep='', end="") + print (valArray[i], " [",i,"] ",) + print (" ") + #waveform as a and as a Python memoryview + print("Waveform as a Python memoryview and dt='native' (default)") + + start = time.time() + for i in range (0,NWF): + mv=cafe.getArray(hlistWF[0], dt='native', art='memoryview'); + end = time.time() + print (end - start) + + print (type(mv)) + print (type(mv[0])) + print (mv[0]) + + + #cafe.terminate() + #exit(1) + + #ml=memoryview(mv) + #print (type(ml)) + #print (type(ml[0])) + #print (ml[0], ml[1], ml[4]) + #print (ml[2:4].tolist()) + status=cafe.set(hlistWF[0], mv) + #Did set work? Check on first element + print("Value (should be what?)=", cafe.get(PVWF1, dt='float')) + + + ''' + #for PY3 + for i in range (0,len(mv)): + print (mv[i], " ",end="") + print (" ") + ''' + + mv_a=np.ndarray(4) + + #mv_a=mv + + for i in range (0,4):#len(mv)): + mv[i]=3.456+i + #print (mv[i], " ", sep="", end="") + mv_a[i]=mv[i] + + print (" ") + + #set first element of wf using memoryview + #mv_a[0]=4.567 + #mv[0]=4.567 + + + status=cafe.set(PVWF1,mv) + #Did set work? Check on first element + print("Value (should be 1.23)=", cafe.get(PVWF1, dt='float')) + + ''' + valArrayI=cafe.getArray(PVWF1, dt='int', art='array') + print (valArrayI) + for i in range (0,min(4,len(valArrayI))): + print (valArrayI[i], " ",) + print (" ") + + + valArrayI=cafe.getArray(PVWF1, dt='int', art='array') + print (valArrayI) + for i in range (0,min(4,len(valArrayI))): + print (valArrayI[i], " ",) + print (" ") + ''' + + print ('nelemCtrl=', cafe.setNelemCtrl(PVWF1, 20) ) + + valC=cafe.getCtrl(PVWF1, dt='int') + print (valC) + #for i in range (0,min(50,len(valC.value))): + #print (valC.value[i], " [",i,"] ", sep='', end="") + #print (valC.value[i], " [",i,"] ",) + #print (" ") + + + + #set wf using array.array + valArray[0]=5.678 + status=cafe.set(PVWF1,valArray) + print("Value (should be 5.678)=", cafe.get(PVWF1, dt='float')) + + #set wf using numpy array + valNumpy[0]=6.543 + status=cafe.set(PVWF1,valNumpy) + print("Value (should be 6)=", cafe.get(PVWF1, dt='int')) + + #set wf using Python List + valList[0]='1.23' + valList[1]='2.10' + status=cafe.set(PVWF1,valList) + + vL=cafe.getList(PVWF1, dt='float') + if vL[0] != None: + print("Values (should be 1.23, 2.1)=", vL[0], vL[1]) + + +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + +############################################################## + +#cafe.terminate() +#exit(1) + +############################################################## +#(4) Multiple scalar operations +############################################################## +#Now work with multiple scalars - far far more efficient to get multiple data-sets with one call +#If a channel is not connected (or other error) then it is reported in the statusList! +#These methods do not throw exceptions + +valueList,status,statusList=cafe.getScalarList(hlist1,'str') #hlist1 or pvlist1 + +if status != cyca.ICAFE_NORMAL: + cafe.printStatusIfError(hlist1,statusList) + +for i in range (0, len(valueList)): + print (valueList[i], " [",i,"] ",) +print(" ") +if status != cyca.ICAFE_NORMAL: + for i in range (0, len(statusList)): + print (cafe.getStatusCodeAsText(statusList[i]), "[",i,"]") + print(" ") + +valueList,status,statusList=cafe.getScalarList(hlistAll,dt='float') #hlistAll or pvlistALL +print("--------------------------------------------------------") +print("valueList from cafe.getScalarList(hlistAll,dt='native') ") +print("Note the different data types appearing in the list ") +print("If a WF is among the list, only the first element is returned") +print("--------------------------------------------------------") + +a=float('2') +print ('a=', a) + +if status != cyca.ICAFE_NORMAL: + cafe.printStatusIfError(hlistAll,statusList) +''' +if PY3: + for i in range (0, len(valueList)): + print (valueList[i], " [",i,"] ", end="") + print(" ") + if status != cyca.ICAFE_NORMAL: + for i in range (0, len(statusList)): + print (cafe.getStatusCodeAsText(statusList[i]), " [",i,"] ",end="") + print(" ") +''' + +#if PY2: + +for i in range (0, len(valueList)): + print (valueList[i], " [",i,"] ",) + print(type(valueList[i])) +print(" ") +if status != cyca.ICAFE_NORMAL: + for i in range (0, len(statusList)): + print (cafe.getStatusCodeAsText(statusList[i]), " [",i,"] ") + print(" ") +print("--------------------------------------------------------") + +print("--------------------------------------------------------") +print("valueList from cafe.getScalarList(hlist1,dt='float') ") +print("Values returned should be 5.6, 6.389, 7.7, 22 ") +print("--------------------------------------------------------") +#Note that different data types are allowed within the input List +llist=[5,6.389,'7.7',22] +status,statusList=cafe.setScalarList(hlist1,llist) +valueList,status,statusList=cafe.getScalarList(hlist1,dt='float') #hlist1 or pvlist1 + +if status != cyca.ICAFE_NORMAL: + cafe.printStatusIfError(hlist1,statusList) + +for i in range (0, len(valueList)): + print (valueList[i], " [",i,"] ",) +print(" ") +print("--------------------------------------------------------") + +############################################################## + +############################################################## +#(5) Mulitple compound operations +############################################################## +print("--------------------------------------------------------") +print("valueList from cafe.getCompoundList(hlistAll,dt='native') ") +print("A WF is returned as a List within the List ") +print("--------------------------------------------------------") +val,s,sl=cafe.getCompoundList(hlistAll,dt='native') + +print(val) +print(sl) +#print one of the waveforms in above val List +''' +if PY3: + for i in range (0, len(val[4])): + print (val[4][i], end=" ") + print(" ") +''' + +mval=10 +if isinstance(val[4],(list)): + mval=len(val[4]) + + +#print 10 first elements of WF +for i in range (0, min(10,mval)): + print (val[4][i],) +print(" ") + +cafe.printStatusIfError(hlistAll, sl) +#or +''' +if PY3: + for i in range (0, len(sl)): + print (cafe.getStatusCodeAsText(sl[i]), " [",i,"] ",end=" ") + print(" ") +''' + +val[2]=0.7123 +s,sl=cafe.setCompoundList(hlistAll, val) +if (s != cyca.ICAFE_NORMAL): + cafe.printStatusIfError(hlistAll, sl) + +#readback to check that above set worked +print ("Readback value should be", val[2], " val=", cafe.get(hlistAll[2])) +print("--------------------------------------------------------") +print("--------------------------------------------------------") +############################################################## + + +############################################################## +#(6) Synchronous group operations and like +############################################################## +print("--------------------------------------------------------") +print(" Synchronous group operations ") +print("--------------------------------------------------------") + +#define a group on the fly +cafe.defineGroup('gBPM', pvlist1) + +groupHandle1=cafe.groupOpen('gBPM') +glist=cafe.groupMemberList('gBPM') + +#Return a group of PV structs +pvg =cafe.getPVGroup(groupHandle1) +pvg.show() +#or +pvg.showWithPV(glist) +#or +for i in range (0, pvg.npv): + print(glist[i], " value=", pvg.pvdata[i].value[0],) +print(" ") +print("--------------------------------------------------------") + +#extract all values from pvgroup into a list +setList=[] +setList=cafe.PVGroupValuesToList(pvg) + +#modify values +setList[0]=setList[0]+0.1234567 +setList[1]=setList[1]+0.9876543 + +#set new values +s, sL=cafe.setGroup(groupHandle1,setList) + +#readback new values +values,s,sl=cafe.getGroup(groupHandle1) #by group handle +print(values) +values,s,sl=cafe.getGroup('gBPM') #by group name +print(values) + +#Now define another group +cafe.defineGroup('gAll', pvlistAll) + +groupHandle2=cafe.groupOpen('gAll') +pvg =cafe.getPVGroup(groupHandle2) +#pvg.show() +#or +pvg.showWithPV(pvlistAll) +#or +#for i in range (0, pvg.npv): +# print(glist[i], " value=", pvg.pvdata[i].value[0],) +#print(" " +print("--------------------------------------------------------") + +values,s,sl=cafe.getGroup(groupHandle2) #by group handle +print (values) +if s != cyca.ICAFE_NORMAL: + cafe.printStatusIfError(pvlistAll, sl) + +#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) + +newValues,s,sl=cafe.getGroup(groupHandle2) #by group handle +print (newValues[0], newValues[1]) +if s != cyca.ICAFE_NORMAL: + cafe.printStatusIfError(pvlistAll, sl) + + +print("--------------------------------------------------------") +print("Note: getCompoundPVGroup does a collective asynchronous get on all group members") +print("--------------------------------------------------------") +print("Data from getCompoundPVGroup") +pvg=cafe.getCompoundPVGroup('gAll', dt='str') +pvg.showWithPV(pvlistAll) +#or +glist=cafe.groupMemberList('gAll') +pvg.showWithPV(glist) + +print ("Values of first element:") +for i in range (0, pvg.npv): + print(glist[i], " value=", pvg.pvdata[i].value[0],) +print(" ") + + +print ("Data from getCompoundPVGroup by groupHandle") +pvg=cafe.getCompoundPVGroup(groupHandle2, dt='float') +pvg.showWithPV(pvlistAll) +#or +print ("Values of first element:") +for i in range (0, pvg.npv): + print(pvlistAll[i], " value=", pvg.pvdata[i].value[0],) +print(" ") + + +############################################################## + + +############################################################## +#(7) Get Ctrl Parameters +############################################################## + +pvctrl = cafe.getCtrl (hlistAll[8]) +#or from Cache would normally suffice as we are not interested in .value +pvctrl = cafe.getCtrlCache (hlistAll[8]) +pvctrl.show() + +print (pvctrl.enumStrings) +print (pvctrl.units) #if any + +############################################################## + +cafe.withExceptions(False); + +############################################################## +#(8) Monitors +############################################################## +cafe.openMonitorPrepare(); + +#user supplied callback +m0 =cafe.monitorStart(hlist1[0], cb=py_callback, dbr=cyca.CY_DBR_PLAIN, mask=cyca.CY_DBE_VALUE|cyca.CY_DBE_ALARM) +print(m0) +#default input parameters fro dbr and mask +m1 =cafe.monitorStart(hlist1[0], cb=py_callback ) +print(m1) + + +#optional, getCache methods get from cache without pre-checks, i.e. isChannel Connected +#cafe.setGetCacheWaitPolicy(hlist[0], cyca.GET_CACHE_NO_CHECK) +#cafe.setGetCacheWaitPolicy(hlist[1], cyca.GET_CACHE_NO_CHECK) + +print ("Monitor STARTING ------------------------------------------------------------- ",m0,m1) + +cafe.openMonitorNowAndWait(1.0); + +val=-2.0 + +#watch the callbacks being invoked +for i in range (0,10): + cafe.set(hlist1[0], val+i) + #cafe.set(hlist1[1], val+i+0.373) + time.sleep(2.0) + + #print (" ") + #print ("Latest Value for channel",cafe.getPVNameFromHandle(hlist1[0]), " is", cafe.getCache(hlist1[0], dt='native')) + #print (" ") + + + +print ('getNoMonitors ' , cafe.getNoMonitors(hlist1[0])); +cafe.close(hlist1[0]) +time.sleep(2); + +#cafe.monitorStop(hlist1[0], mpid=m0) # mpid=m0 is optional and may be omitted +#cafe.monitorStop(hlist1[0]) + +#optional, getCache methods get from cache with pre-checks (back to default) +#cafe.setGetCacheWaitPolicy(hlist[0], cyca.GET_CACHE_WAIT) +#cafe.setGetCacheWaitPolicy(hlist[1], cyca.GET_CACHE_WAIT) + +cafe.terminate(); +exit(1); + + +############################################################## + +############################################################## +#(9) Asynchronous interactions and retrieving data from Cache +############################################################## + + +print("--------------------------------------------------------") +print("Asynchronous interactions and retrieving data from Cache") +print("--------------------------------------------------------") + +#Check on return value or status instead of exceptions + +cafe.withExceptions(False); +s=cafe.set(hlistAll[0],1.111789) + +s,sl=cafe.getAsyn(hlistAll) +print("status of cafe.getAsyn(hlistAll)",s) + +if s != cyca.ICAFE_NORMAL: + print(sl) + +#optional - may be omitted +s,sl=cafe.waitForBundledEvents(hlistAll) + +#will wait for callback to be invoked if above omitted +v=cafe.getCache(hlistAll[0]) +if v != None: + print("Value from Cache ", v) + +#get array +v=cafe.getArrayCache(hlistAll[4],art='numpy') +if v[0] != None: + print("Value from Cache ", v) + +pv=cafe.getPVCache(hlistAll[4]) +print (cafe.getPVNameFromHandle(hlistAll[4]),":") +pv.showMax(4) #show max 4 elements of wf + +############################################################## + +############################################################# +#(10) More on groups +############################################################## +#loads groups defined by virtual accelerator (SF network only) +#SF specific, please delete +''' +cafe.loadSFGroups() +print ("loadSFGroups") + +ll=cafe.groupList() +print ("----------------/") +print (ll ) +print ("----------------/") +inl=['MQUA080','PS-MODE'] +ll2=cafe.getChannelList(inl) #search for channels containing inl in pc name +print ("--------------------//") +print (ll2) +print ("--------------------//") +#View members of group ll[3] +gml=cafe.groupMemberList(ll[3]) +print ("------------------------///") +print (gml) +print ("------------------------///") + +''' + +#See that a number of groups have been added to the groupList +ll=cafe.groupList() +print ("----------------------------////") +print (ll) +print ("----------------------------////") + +try: + gHandle=cafe.groupOpen(ll[0]) + pvg=cafe.getPVGroup(gHandle) + #or + pvg=cafe.getPVGroup(ll[0]) + print ("--------------------------------/") + pvg.showWithPV(cafe.groupMemberList(ll[0])) #'gBRPM' + print ("--------------------------------/") + + #Start a Collective monitor on all group memebers with the same user supplied cb function + cbf=[] + for i in range (0, len(ll[0])): + cbf.append(py_callback) + s,sV=cafe.groupMonitorStartWithCBList(gHandle,cbf) + #or + #s,sV=cafe.groupMonitorStartWithCBList(ll[0],cbf) + + #Start a monitor on all group members with default callback + #If a channel is disconnected, then the monitor will start automatically on connection + s,sV=cafe.groupMonitorStart('gAll') + + val,s,sl=cafe.getGroupCache(gHandle) + #wait a tick for callbacks to complete before sets are done + time.sleep(0.5) + print ("--------------------------------/") + print ("SET to monitored channels") + print ("--------------------------------/") + for i in range (0,len(val)): + val[i]= val[i]+0.9099999 + s,sl = cafe.setGroup(gHandle,val) + time.sleep(0.5) + + s,sV=cafe.groupMonitorStop(gHandle) + s,sV=cafe.groupMonitorStop('gAll') + + +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + + +''' + +#load collections and groups from external file +cafe.loadCollectionsFromXML("Collections/collection_swissfel.xml"); +cafe.loadGroupsFromXML("Groups/group_swissfel.xml"); + +cafe.loadCollectionsFromXML ("cNodes.xml") +cafe.loadGroupsFromXML ("gDBPM.xml") + +# get static BPM data, i.e., names/positions +BPMdev, BPMpos=cafe.devicePositionMap("cDBPM") + +nDBPM=len(BPMdev) +print ("No. of DBPs devices =", nDBPM) +for i in range (0, len(BPMdev)): + print (i, " " + BPMdev[i], " " , BPMpos[i] +''' + +############################################################## +#(11) Special methods: +############################################################## +#int match(valueToReach, handleMatch, tolerance, timeout, printFlag) +#This method does not do a set, just waits until valueToReach +#for channel hlist1[0] is reached +print (" ") +print ("START cafe.match------------------------------------------------------") +try: + cafe.set(hlist1[0], 2.001) + s=cafe.match(2.34,hlist1[0],0.0011,10.0,True) + #s=cafe.match(cafe.getEnumFromString(PVS,"monitor"),hlist1[0],0.0011,10.0,True) + print ("Status of match method: ", cafe.getStatusCodeAsText(s)) +except Exception as inst: + print ("Exception for cafe match ") + print ("Status of match method: ", cafe.getStatusCodeAsText(cafe.getStatus(hlist1[0]))) +print ("END cafe.match------------------------------------------------------") + + +#int setAndMatch(handlePVtoSet, valueToSet, handlePVtoReadback, tolerance, timeout, printFlag) +#Set Channel1 followed by a readback of Channel 2 \n +#Method verifies whether or not the 2 values agree within the given tolerance and timeout +#Method returns with ECA_NORMAL as soon as a match is reached +print (" ") +print ("START cafe.setAndMatch------------------------------------------------------") +try: + cafe.set(hlist1[1], 2.0201) + s=cafe.setAndMatch(hlist1[0],2.02,hlist1[1],0.001,10.0,True) + #s=cafe.setAndMatch(hlist1[0],cafe.getEnumFromString(PVS,"monitor"),hlist1[1],0.001,1,True) + print ("Status of set and match method: ", cafe.getStatusCodeAsText(s)) +except Exception as inst: + print ("EXCEPTION AT SET AND MATCH" ) + print ("Status of set and match method: ", cafe.getStatusCodeAsText(cafe.getStatus(hlist1[0]))) +print ("END cafe.setAndMatch------------------------------------------------------") + +#Throw exception +try: + cafe.getEnumFromString(PVS,"Monitor") +except Exception as inst: + print (inst) + +#Set Channels followed by a corresponding readback of Channels \n +#Method verifies whether or not the set/readback values agree within the given tolerance and timeout \n +#Method returns with ECA_NORMAL as soon as a match is reached + +magnetSetList =['ARIMA-CV-12LB:I-SET', 'ARIMA-CV-12LE:I-SET'] +magnetReadList=['ARIMA-CV-12LB:I-READ','ARIMA-CV-12LE:I-READ'] +cafe.openPrepare() +mSetHandleList=cafe.open(magnetSetList) +mReadHandleList=cafe.open(magnetReadList) +cafe.openNowAndWait(0.4) +valInput=[] +valInput.append(3.5) +valInput.append(3.6) + + + +#int setAndMatchMany(handlePVArraytoSet, valueArrayToSet, handlePVArraytoReadback, tolerance, timeout, printFlag) +print (" ") +print ("START cafe.setAndMatchMany------------------------------------------------------") +try: + s,sL=cafe.setScalarList(mSetHandleList, valInput) + s,sL=cafe.setScalarList(mReadHandleList, [3.501,3.599]) + s=cafe.setAndMatchMany(mSetHandleList,valInput,mReadHandleList,0.002,10.0,True) + print ("Status of set and match method: ", cafe.getStatusCodeAsText(s)) + +except Exception as inst: + if isinstance(inst.args[0],PyCafe.CyCafeException): + cafeEx=inst.args[0] + cafeEx.show() + #or + cafeEx.reveal() + #or + print (cafeEx.pv,"(handle=", cafeEx.handle,")") + print (cafeEx.errorCode,":", cafeEx.errorText,cafeEx.errorInfo) + else: + print (inst) + + + + +print ("END cafe.setAndMatch------------------------------------------------------") + + + +############################################################## + + +##Test with attaching context (would do this from another thread) +print ( cafe.getStatusCodeAsText(cafe.attachContext(1)) ); +print ( cafe.getStatusCodeAsText(cafe.attachContext(999999))); + +if (cafe.attachContext(1) == cyca.CY_ECA_ISATTACHED): + print (cafe.getStatusCodeAsText(cafe.attachContext(1))); + +if (cafe.attachContext(99999) == cyca.ECAFE_NULLCONTEXT): + print (cafe.getStatusCodeAsText(cafe.attachContext(999))); + + + +############################################################## +#END Gracefully terminate CAFE +############################################################## +cafe.terminate() +exit(0) +############################################################## + + + + diff --git a/gDBPM.xml b/gDBPM.xml new file mode 100644 index 0000000..85906e1 --- /dev/null +++ b/gDBPM.xml @@ -0,0 +1,39 @@ + + + + + + + DBPM configuration + + cDBPM + X1 + + + + cDBPM + Y1 + + + cDBPM + Q1 + + + cDBPM + X1-VALID + + + cDBPM + Y1-VALID + + + cDBPM + Q1-VALID + + + cDBPM + ENERGY + + + + diff --git a/python-3.5/PyCafe.pxd b/python-3.5/PyCafe.pxd new file mode 120000 index 0000000..9c5f8ad --- /dev/null +++ b/python-3.5/PyCafe.pxd @@ -0,0 +1 @@ +../PyCafe.pxd \ No newline at end of file diff --git a/python-3.5/PyCafe.pyx b/python-3.5/PyCafe.pyx new file mode 120000 index 0000000..416c394 --- /dev/null +++ b/python-3.5/PyCafe.pyx @@ -0,0 +1 @@ +../PyCafe.pyx \ No newline at end of file diff --git a/python-3.5/PyCafeDefs.pxi b/python-3.5/PyCafeDefs.pxi new file mode 120000 index 0000000..ce7529d --- /dev/null +++ b/python-3.5/PyCafeDefs.pxi @@ -0,0 +1 @@ +../PyCafeDefs.pxi \ No newline at end of file diff --git a/python-3.5/PyCafe_api.h b/python-3.5/PyCafe_api.h new file mode 100644 index 0000000..379bf2a --- /dev/null +++ b/python-3.5/PyCafe_api.h @@ -0,0 +1,115 @@ +/* Generated by Cython 0.23.4 */ + +#ifndef __PYX_HAVE_API__PyCafe +#define __PYX_HAVE_API__PyCafe +#include "Python.h" + +static void (*__pyx_api_f_6PyCafe_py_cb_wrapper)(PVDataHolder, unsigned int, std::string) = 0; +#define py_cb_wrapper __pyx_api_f_6PyCafe_py_cb_wrapper +static void (*__pyx_api_f_6PyCafe_py_cb_ctrl_wrapper)(PVCtrlHolder, unsigned int, std::string) = 0; +#define py_cb_ctrl_wrapper __pyx_api_f_6PyCafe_py_cb_ctrl_wrapper +static void (*__pyx_api_f_6PyCafe_py_cb_handle_wrapper)(unsigned int) = 0; +#define py_cb_handle_wrapper __pyx_api_f_6PyCafe_py_cb_handle_wrapper +static void (*__pyx_api_f_6PyCafe_py_cb_handle_monid_wrapper)(unsigned int, unsigned long) = 0; +#define py_cb_handle_monid_wrapper __pyx_api_f_6PyCafe_py_cb_handle_monid_wrapper +static void (*__pyx_api_f_6PyCafe_py_cb_handle_get_wrapper)(unsigned int) = 0; +#define py_cb_handle_get_wrapper __pyx_api_f_6PyCafe_py_cb_handle_get_wrapper +static void (*__pyx_api_f_6PyCafe_py_cb_handle_put_wrapper)(unsigned int) = 0; +#define py_cb_handle_put_wrapper __pyx_api_f_6PyCafe_py_cb_handle_put_wrapper +#if !defined(__Pyx_PyIdentifier_FromString) +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) +#else + #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) +#endif +#endif + +#ifndef __PYX_HAVE_RT_ImportModule +#define __PYX_HAVE_RT_ImportModule +static PyObject *__Pyx_ImportModule(const char *name) { + PyObject *py_name = 0; + PyObject *py_module = 0; + py_name = __Pyx_PyIdentifier_FromString(name); + if (!py_name) + goto bad; + py_module = PyImport_Import(py_name); + Py_DECREF(py_name); + return py_module; +bad: + Py_XDECREF(py_name); + return 0; +} +#endif + +#ifndef __PYX_HAVE_RT_ImportFunction +#define __PYX_HAVE_RT_ImportFunction +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { + PyObject *d = 0; + PyObject *cobj = 0; + union { + void (*fp)(void); + void *p; + } tmp; + d = PyObject_GetAttrString(module, (char *)"__pyx_capi__"); + if (!d) + goto bad; + cobj = PyDict_GetItemString(d, funcname); + if (!cobj) { + PyErr_Format(PyExc_ImportError, + "%.200s does not export expected C function %.200s", + PyModule_GetName(module), funcname); + goto bad; + } +#if PY_VERSION_HEX >= 0x02070000 + if (!PyCapsule_IsValid(cobj, sig)) { + PyErr_Format(PyExc_TypeError, + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", + PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj)); + goto bad; + } + tmp.p = PyCapsule_GetPointer(cobj, sig); +#else + {const char *desc, *s1, *s2; + desc = (const char *)PyCObject_GetDesc(cobj); + if (!desc) + goto bad; + s1 = desc; s2 = sig; + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + if (*s1 != *s2) { + PyErr_Format(PyExc_TypeError, + "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)", + PyModule_GetName(module), funcname, sig, desc); + goto bad; + } + tmp.p = PyCObject_AsVoidPtr(cobj);} +#endif + *f = tmp.fp; + if (!(*f)) + goto bad; + Py_DECREF(d); + return 0; +bad: + Py_XDECREF(d); + return -1; +} +#endif + + +static int import_PyCafe(void) { + PyObject *module = 0; + module = __Pyx_ImportModule("PyCafe"); + if (!module) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_wrapper, "void (PVDataHolder, unsigned int, std::string)") < 0) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_ctrl_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_ctrl_wrapper, "void (PVCtrlHolder, unsigned int, std::string)") < 0) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_handle_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_handle_wrapper, "void (unsigned int)") < 0) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_handle_monid_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_handle_monid_wrapper, "void (unsigned int, unsigned long)") < 0) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_handle_get_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_handle_get_wrapper, "void (unsigned int)") < 0) goto bad; + if (__Pyx_ImportFunction(module, "py_cb_handle_put_wrapper", (void (**)(void))&__pyx_api_f_6PyCafe_py_cb_handle_put_wrapper, "void (unsigned int)") < 0) goto bad; + Py_DECREF(module); module = 0; + return 0; + bad: + Py_XDECREF(module); + return -1; +} + +#endif /* !__PYX_HAVE_API__PyCafe */ diff --git a/python-3.5/README_Py3_release b/python-3.5/README_Py3_release new file mode 100644 index 0000000..1ea0102 --- /dev/null +++ b/python-3.5/README_Py3_release @@ -0,0 +1,4 @@ +source /opt/gfa/python 3.5 +python setup3.5_release.py build_ext -i +export PYTHONPATH=.:/opt/gfa/cafe/python/python-3.5/pycafe-1.3.0-final-/lib +export LD_LIBRARY_PATH=./ diff --git a/python-3.5/cNodes.xml b/python-3.5/cNodes.xml new file mode 120000 index 0000000..1cf6978 --- /dev/null +++ b/python-3.5/cNodes.xml @@ -0,0 +1 @@ +../sf_ar_cNodes.xml \ No newline at end of file diff --git a/python-3.5/examples.py b/python-3.5/examples.py new file mode 120000 index 0000000..7f4266d --- /dev/null +++ b/python-3.5/examples.py @@ -0,0 +1 @@ +../examples.py \ No newline at end of file diff --git a/python-3.5/examples.sh b/python-3.5/examples.sh new file mode 100755 index 0000000..4efab8a --- /dev/null +++ b/python-3.5/examples.sh @@ -0,0 +1,7 @@ +source /opt/gfa/python 3.5 +export SFEL_OMC_PYTHONPATH=/afs/psi.ch/intranet/SF/Applications/on-line_model/default/PythonModule +export SFEL_LAYOUT_PYTHONPATH=/afs/psi.ch/intranet/SF/Applications/on-line_model/default/scripts/VA +export PYTHONPATH=.:$SFEL_LAYOUT_PYTHONPATH:$SFEL_OMC_PYTHONPATH:/opt/gfa/cafe/python/python-3.5/latest/lib +export LD_LIBRARY_PATH=/opt/gfa/cafe/python/python-3.5/latest/lib +python examples.py + diff --git a/python-3.5/examplesTest.py b/python-3.5/examplesTest.py new file mode 120000 index 0000000..cfcf70a --- /dev/null +++ b/python-3.5/examplesTest.py @@ -0,0 +1 @@ +../examplesTest.py \ No newline at end of file diff --git a/python-3.5/gDBPM.xml b/python-3.5/gDBPM.xml new file mode 120000 index 0000000..d32d8ae --- /dev/null +++ b/python-3.5/gDBPM.xml @@ -0,0 +1 @@ +../gDBPM.xml \ No newline at end of file diff --git a/python-3.5/makefile b/python-3.5/makefile new file mode 100644 index 0000000..f4cf161 --- /dev/null +++ b/python-3.5/makefile @@ -0,0 +1,36 @@ +# +# Jan Chrin +# July 2015 +# + +##### CHANGE AS APPROPRIATE ################# +#Cython Version to install +CYCAFE_VERSION=pycafe-1.3.0-final-1 + +#CAFE project base +#CAFE_BASE=${EPICS_EXTENSIONS}/CAFE +CAFE_BASE=/opt/gfa/cafe/python/python-3.5 + +CAFE_CYCAFE_BASE=${CAFE_BASE}/${CYCAFE_VERSION} + +INSTALL_PATH_AFS=/afs/psi.ch/intranet/Controls/cafe/CAFE/cycafe/$(CYCAFE_VERSION)/lib/${EPICS_HOST_ARCH} + +INSTALL_PATH= $(CAFE_CYCAFE_BASE)/lib +EXAMPLES_INSTALL_PATH= $(CAFE_CYCAFE_BASE)/examples +############################################# + + +install_local: PyCafe.cpython-35m-x86_64-linux-gnu.so + mkdir -p ${EPICS_HOST_ARCH} + cp PyCafe.cpython-35m-x86_64-linux-gnu.so ${EPICS_HOST_ARCH} + mkdir -p ${INSTALL_PATH_AFS} + cp PyCafe.cpython-35m-x86_64-linux-gnu.so ${INSTALL_PATH_AFS} + + +install_rel: PyCafe.cpython-35m-x86_64-linux-gnu.so + mkdir -p $(INSTALL_PATH) + cp PyCafe.cpython-35m-x86_64-linux-gnu.so $(INSTALL_PATH) + mkdir -p $(EXAMPLES_INSTALL_PATH) + cp examples.py $(EXAMPLES_INSTALL_PATH) + cp examples.sh $(EXAMPLES_INSTALL_PATH) + diff --git a/python-3.5/setup3.5_release.py b/python-3.5/setup3.5_release.py new file mode 100644 index 0000000..578b52c --- /dev/null +++ b/python-3.5/setup3.5_release.py @@ -0,0 +1,31 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Build import cythonize +from numpy import get_include + +#runtime_library_dirs do not override LD_LIBRARY_PATH! + +setup( + ext_modules = cythonize([Extension('PyCafe',['PyCafe.pyx'], + language="c++", + include_dirs=[ '/opt/gfa/python-3.5/latest/include/python3.5m', + '/usr/local/epics/base/include', + '/usr/local/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/python/python-3.5/pycafe-1.3.0-final-1/include', + '.', get_include()], + library_dirs=[ '/usr/local/epics/base/lib/SL6-x86_64', + '/opt/gfa/cafe/python/python-3.5/pycafe-1.3.0-final-1/lib', + '/opt/gfa/python-3.5/latest/lib' + ], + runtime_library_dirs=['/usr/local/epics/base/lib/SL6-x86_64', + '/opt/gfa/cafe/python/python-3.5/pycafe-1.3.0-final-1/lib', + '/opt/gfa/python-3.5/latest/lib' + ], + libraries=['ca','Com','dl','cafe']) + ], annotate=False, + compiler_directives={'embedsignature': False, 'language_level': 3, 'c_string_type': 'str', + 'c_string_encoding' : 'ascii', 'warning_errors' : False, 'py2_import': False, 'warn.unreachable': False, + 'remove_unreachable': False}) +) diff --git a/setup3.5_win.py b/setup3.5_win.py new file mode 100644 index 0000000..fb66fb5 --- /dev/null +++ b/setup3.5_win.py @@ -0,0 +1,48 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Build import cythonize +from numpy import get_include + +#runtime_library_dirs do not override LD_LIBRARY_PATH! +#, +# 'C:/local/boost_1_62_0/lib64-msvc-10.0/libboost_thread-vc100-mt-s-1_62.lib', +# 'C:/local/boost_1_62_0/lib64-msvc-10.0/libboost_system-vc100-mt-s-1_62.lib', +# 'C:/local/boost_1_62_0/lib64-msvc-10.0/libboost_date_time-vc100-mt-s-1_62.lib', +# 'C:/local/boost_1_62_0/lib64-msvc-10.0/libboost_chrono-vc100-mt-s-1_62.lib' + + +setup( + ext_modules = cythonize([Extension('PyCafe',['PyCafe.pyx'], + language="c++", + include_dirs=[ + 'C:/Users/chrin/AppData/Local/Continuum/Anaconda3/env/py345/include', + 'C:/epics/base-3.14.12.5/include', + 'C:/epics/base-3.14.12.5/include/os/WIN32', + 'C:/local/boost_1_62_0', + 'C:/local/boost_1_62_0/boost', + 'C:/CAFE/CAFE/cpp/include', 'C:/CAFE/CAFE/cpp','C:/Qt/qt-4.8.6-x64-msvc2010/include' + '.', get_include()], + extra_compile_args = ["-MT", "-EHsc"], + library_dirs=[ + 'C:/epics/base-3.14.12.5/lib/windows-x64', + 'C:/CAFE/CAFE/cpp', + 'C:/Users/chrin/AppData/Local/Continuum/Anaconda3/envs/py345/libs', + 'C:/local/boost_1_62_0/lib64-msvc-10.0', + 'C:/Qt/qt-4.8.6-x64-msvc2010/lib' + ], + extra_link_args=["-Release","-Manifest","-NoLogo"], + #runtime_library_dirs=['C:/epics/base-3.14.12.5/lib/windows-x64', + # 'C:/CAFE/CAFE/cpp/lib', + # 'C:/Users/chrin/AppData/Local/Continuum/Anaconda3/envs/py345/libs' + # ], + libraries=['ca','Com','cafe','python3','libboost_thread-vc100-mt-s-1_62', + 'libboost_system-vc100-mt-s-1_62','libboost_date_time-vc100-mt-s-1_62', + 'libboost_chrono-vc100-mt-s-1_62', + 'QtCore4','QtXml4' + ] + ) + ], annotate=False, + compiler_directives={'embedsignature': False, 'language_level': 3, 'c_string_type': 'str', + 'c_string_encoding' : 'ascii', 'warning_errors' : False, 'py2_import': False, 'warn.unreachable': False, + 'remove_unreachable': False}) +) diff --git a/sf_ar_cNodes.xml b/sf_ar_cNodes.xml new file mode 100644 index 0000000..e49692d --- /dev/null +++ b/sf_ar_cNodes.xml @@ -0,0 +1,2804 @@ + + + Collection of Nodes at SwissFEL + + X + Y + X0 + Y0 + REF-X + REF-Y + REFOFF-X + REFOFF-Y + REFORB-X + REFORB-Y + SET-GAIN + I + FB-STAT + FB-ENABLE + STAT + ENABLE + + + SINEG01-DBPM340 + + + SINSB01-DBPM150 + + + SINSB02-DBPM150 + + + SINLH01-DBPM060 + + + SINLH02-DBPM210 + + + SINLH02-DBPM240 + + + SINLH03-DBPM010 + + + SINLH03-DBPM050 + + + SINLH03-DBPM090 + + + SINSB03-DBPM120 + + + SINSB03-DBPM220 + + + SINSB04-DBPM120 + + + SINSB04-DBPM220 + + + SINSB05-DBPM120 + + + SINSB05-DBPM220 + + + SINXB01-DBPM120 + + + SINBC01-DBPM010 + + + SINBC01-DBPM030 + + + SINBC01-DBPM080 + + + SINBC01-DBPM100 + + + SINBC02-DBPM140 + + + SINBC02-DBPM320 + + + SINDI01-DBPM010 + + + SINDI01-DBPM060 + + + SINDI02-DBPM010 + + + SINDI02-DBPM040 + + + SINDI02-DBPM080 + + + S10CB01-DBPM220 + + + S10CB01-DBPM420 + + + S10CB02-DBPM220 + + + S10CB02-DBPM420 + + + S10DI01-DBPM110 + + + S10CB03-DBPM220 + + + S10CB03-DBPM420 + + + S10CB04-DBPM220 + + + S10CB04-DBPM420 + + + S10CB05-DBPM220 + + + S10CB05-DBPM420 + + + S10CB06-DBPM220 + + + S10CB06-DBPM420 + + + S10CB07-DBPM220 + + + S10CB07-DBPM420 + + + S10CB08-DBPM220 + + + S10CB08-DBPM420 + + + S10CB09-DBPM220 + + + S10BC01-DBPM010 + + + S10BC01-DBPM050 + + + S10BC01-DBPM090 + + + S10BC02-DBPM140 + + + S10BC02-DBPM320 + + + S10MA01-DBPM010 + + + S10MA01-DBPM060 + + + S10MA01-DBPM120 + + + S20CB01-DBPM420 + + + S20CB02-DBPM420 + + + S20CB03-DBPM420 + + + S20SY01-DBPM010 + + + S20SY01-DBPM040 + + + S20SY01-DBPM060 + + + S20SY02-DBPM080 + + + S20SY02-DBPM120 + + + S20SY02-DBPM150 + + + S20SY03-DBPM010 + + + S20SY03-DBPM040 + + + S20SY03-DBPM080 + + + S30CB01-DBPM420 + + + S30CB02-DBPM420 + + + S30CB03-DBPM420 + + + S30CB04-DBPM420 + + + S30CB05-DBPM420 + + + S30CB06-DBPM420 + + + S30CB07-DBPM420 + + + S30CB08-DBPM420 + + + S30CB09-DBPM420 + + + S30CB10-DBPM420 + + + S30CB11-DBPM420 + + + S30CB12-DBPM420 + + + S30CB13-DBPM420 + + + S30CB14-DBPM420 + + + S30CB15-DBPM420 + + + SARCL01-DBPM010 + + + SARCL01-DBPM060 + + + SARCL01-DBPM120 + + + SARCL01-DBPM150 + + + SARCL02-DBPM110 + + + SARCL02-DBPM220 + + + SARCL02-DBPM260 + + + SARCL02-DBPM330 + + + SARCL02-DBPM470 + + + SARMA01-DBPM040 + + + SARMA01-DBPM100 + + + SARMA02-DBPM010 + + + SARMA02-DBPM020 + + + SARMA02-DBPM040 + + + SARMA02-DBPM110 + + + SARUN01-DBPM070 + + + SARUN02-DBPM070 + + + SARUN03-DBPM070 + + + SARUN04-DBPM070 + + + SARUN05-DBPM070 + + + SARUN06-DBPM070 + + + SARUN07-DBPM070 + + + SARUN08-DBPM070 + + + SARUN09-DBPM070 + + + SARUN10-DBPM070 + + + SARUN11-DBPM070 + + + SARUN12-DBPM070 + + + SARUN13-DBPM070 + + + SARUN14-DBPM070 + + + SARUN15-DBPM070 + + + SARUN16-DBPM070 + + + SARUN17-DBPM070 + + + SARUN18-DBPM070 + + + SARUN19-DBPM070 + + + SARUN20-DBPM070 + + + S10BD01-DBPM020 + + + SARBD01-DBPM040 + + + SARBD02-DBPM010 + + + SARBD02-DBPM040 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MCRX120 + + + SINEG01-MCRX160 + + + SINEG01-MCRX180 + + + SINEG01-MCRX200 + + + SINEG01-MCRX220 + + + SINSB01-MCRX010 + + + SINSB02-MCRX010 + + + SINLH01-MCRX020 + + + SINLH01-MCRX050 + + + SINLH02-MCRX010 + + + SINLH02-MCRX100 + + + SINLH02-MCRX200 + + + SINLH02-MCRX300 + + + SINLH02-MCRX400 + + + SINLH02-MCRX410 + + + SINLH03-MCRX040 + + + SINLH03-MCRX080 + + + SINSB03-MCRX130 + + + SINSB03-MCRX230 + + + SINSB04-MCRX130 + + + SINSB04-MCRX230 + + + SINSB05-MCRX130 + + + SINSB05-MCRX230 + + + SINBC01-MCRX020 + + + SINBC01-MCRX050 + + + SINBC01-MCRX070 + + + SINBC01-MCRX090 + + + SINBC01-MCRX110 + + + SINBC02-MCRX100 + + + SINBC02-MCRX200 + + + SINBC02-MCRX300 + + + SINBC02-MCRX400 + + + SINDI01-MCRX020 + + + SINDI01-MCRX070 + + + SINDI02-MCRX020 + + + SINDI02-MCRX030 + + + SINDI02-MCRX050 + + + SINDI02-MCRX060 + + + SINDI02-MCRX090 + + + S10CB01-MCRX230 + + + S10CB01-MCRX430 + + + S10CB02-MCRX230 + + + S10CB02-MCRX430 + + + S10DI01-MCRX100 + + + S10DI01-MCRX120 + + + S10CB03-MCRX230 + + + S10CB03-MCRX430 + + + S10CB04-MCRX230 + + + S10CB04-MCRX430 + + + S10CB05-MCRX230 + + + S10CB05-MCRX430 + + + S10CB06-MCRX230 + + + S10CB06-MCRX430 + + + S10CB07-MCRX230 + + + S10CB07-MCRX430 + + + S10CB08-MCRX230 + + + S10CB08-MCRX430 + + + S10CB09-MCRX230 + + + S10BC01-MCRX020 + + + S10BC01-MCRX040 + + + S10BC01-MCRX060 + + + S10BC01-MCRX080 + + + S10BC01-MCRX100 + + + S10BC02-MCRX100 + + + S10BC02-MCRX200 + + + S10BC02-MCRX300 + + + S10BC02-MCRX400 + + + S10MA01-MCRX020 + + + S10MA01-MCRX050 + + + S10MA01-MCRX070 + + + S10MA01-MCRX100 + + + S10MA01-MCRX110 + + + S10MA01-MCRX130 + + + S20CB01-MCRX430 + + + S20CB02-MCRX430 + + + S20CB03-MCRX430 + + + S20SY01-MCRX020 + + + S20SY01-MCRX030 + + + S20SY01-MCRX050 + + + S20SY01-MCRX080 + + + S20SY02-MCRX060 + + + S20SY02-MCRX090 + + + S20SY02-MCRX130 + + + S20SY02-MCRX170 + + + S20SY03-MCRX020 + + + S20SY03-MCRX030 + + + S20SY03-MCRX050 + + + S20SY03-MCRX060 + + + S20SY03-MCRX100 + + + S30CB01-MCRX430 + + + S30CB02-MCRX430 + + + S30CB03-MCRX430 + + + S30CB04-MCRX430 + + + S30CB05-MCRX430 + + + S30CB06-MCRX430 + + + S30CB07-MCRX430 + + + S30CB08-MCRX430 + + + S30CB09-MCRX430 + + + S30CB10-MCRX430 + + + S30CB11-MCRX430 + + + S30CB12-MCRX430 + + + S30CB13-MCRX430 + + + S30CB14-MCRX430 + + + S30CB15-MCRX430 + + + SARCL01-MCRX020 + + + SARCL01-MCRX040 + + + SARCL01-MCRX070 + + + SARCL01-MCRX090 + + + SARCL01-MCRX130 + + + SARCL01-MCRX180 + + + SARCL02-MCRX100 + + + SARCL02-MCRX120 + + + SARCL02-MCRX200 + + + SARCL02-MCRX230 + + + SARCL02-MCRX240 + + + SARCL02-MCRX320 + + + SARCL02-MCRX340 + + + SARCL02-MCRX400 + + + SARCL02-MCRX450 + + + SARCL02-MCRX480 + + + SARCL02-MCRX500 + + + SARMA01-MCRX020 + + + SARMA01-MCRX050 + + + SARMA01-MCRX070 + + + SARMA01-MCRX110 + + + SARMA01-MCRX130 + + + SARMA02-MCRX050 + + + SARMA02-MCRX120 + + + SARUN01-MCRX080 + + + SARUN02-MCRX080 + + + SARUN03-MCRX010 + + + SARUN03-MCRX040 + + + SARUN03-MCRX080 + + + SARUN04-MCRX010 + + + SARUN04-MCRX040 + + + SARUN04-MCRX080 + + + SARUN05-MCRX010 + + + SARUN05-MCRX040 + + + SARUN05-MCRX080 + + + SARUN06-MCRX010 + + + SARUN06-MCRX040 + + + SARUN06-MCRX080 + + + SARUN07-MCRX010 + + + SARUN07-MCRX040 + + + SARUN07-MCRX080 + + + SARUN08-MCRX010 + + + SARUN08-MCRX040 + + + SARUN08-MCRX080 + + + SARUN09-MCRX010 + + + SARUN09-MCRX040 + + + SARUN09-MCRX080 + + + SARUN10-MCRX010 + + + SARUN10-MCRX040 + + + SARUN10-MCRX080 + + + SARUN11-MCRX010 + + + SARUN11-MCRX040 + + + SARUN11-MCRX080 + + + SARUN12-MCRX010 + + + SARUN12-MCRX040 + + + SARUN12-MCRX080 + + + SARUN13-MCRX010 + + + SARUN13-MCRX040 + + + SARUN13-MCRX080 + + + SARUN14-MCRX010 + + + SARUN14-MCRX040 + + + SARUN14-MCRX080 + + + SARUN15-MCRX010 + + + SARUN15-MCRX040 + + + SARUN15-MCRX080 + + + SARUN16-MCRX080 + + + SARUN17-MCRX080 + + + SARUN18-MCRX080 + + + SARUN19-MCRX080 + + + SARUN20-MCRX080 + + + SARBD01-MCRX020 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MCRY120 + + + SINEG01-MCRY160 + + + SINEG01-MCRY180 + + + SINEG01-MCRY200 + + + SINEG01-MCRY220 + + + SINSB01-MCRY010 + + + SINSB02-MCRY010 + + + SINLH01-MCRY020 + + + SINLH01-MCRY050 + + + SINLH02-MCRY010 + + + SINLH02-MCRY410 + + + SINLH03-MCRY040 + + + SINLH03-MCRY080 + + + SINSB03-MCRY130 + + + SINSB03-MCRY230 + + + SINSB04-MCRY130 + + + SINSB04-MCRY230 + + + SINSB05-MCRY130 + + + SINSB05-MCRY230 + + + SINBC01-MCRY020 + + + SINBC01-MCRY050 + + + SINBC01-MCRY070 + + + SINBC01-MCRY090 + + + SINBC01-MCRY110 + + + SINDI01-MCRY020 + + + SINDI01-MCRY070 + + + SINDI02-MCRY020 + + + SINDI02-MCRY030 + + + SINDI02-MCRY050 + + + SINDI02-MCRY060 + + + SINDI02-MCRY090 + + + S10CB01-MCRY230 + + + S10CB01-MCRY430 + + + S10CB02-MCRY230 + + + S10CB02-MCRY430 + + + S10DI01-MCRY120 + + + S10CB03-MCRY230 + + + S10CB03-MCRY430 + + + S10CB04-MCRY230 + + + S10CB04-MCRY430 + + + S10CB05-MCRY230 + + + S10CB05-MCRY430 + + + S10CB06-MCRY230 + + + S10CB06-MCRY430 + + + S10CB07-MCRY230 + + + S10CB07-MCRY430 + + + S10CB08-MCRY230 + + + S10CB08-MCRY430 + + + S10CB09-MCRY230 + + + S10BC01-MCRY020 + + + S10BC01-MCRY040 + + + S10BC01-MCRY060 + + + S10BC01-MCRY080 + + + S10BC01-MCRY100 + + + S10MA01-MCRY020 + + + S10MA01-MCRY050 + + + S10MA01-MCRY070 + + + S10MA01-MCRY110 + + + S10MA01-MCRY130 + + + S20CB01-MCRY430 + + + S20CB02-MCRY430 + + + S20CB03-MCRY430 + + + S20SY01-MCRY020 + + + S20SY01-MCRY030 + + + S20SY01-MCRY050 + + + S20SY01-MCRY080 + + + S20SY02-MCRY060 + + + S20SY02-MCRY090 + + + S20SY02-MCRY130 + + + S20SY02-MCRY170 + + + S20SY03-MCRY020 + + + S20SY03-MCRY030 + + + S20SY03-MCRY050 + + + S20SY03-MCRY060 + + + S20SY03-MCRY100 + + + S30CB01-MCRY430 + + + S30CB02-MCRY430 + + + S30CB03-MCRY430 + + + S30CB04-MCRY430 + + + S30CB05-MCRY430 + + + S30CB06-MCRY430 + + + S30CB07-MCRY430 + + + S30CB08-MCRY430 + + + S30CB09-MCRY430 + + + S30CB10-MCRY430 + + + S30CB11-MCRY430 + + + S30CB12-MCRY430 + + + S30CB13-MCRY430 + + + S30CB14-MCRY430 + + + S30CB15-MCRY430 + + + SARCL01-MCRY020 + + + SARCL01-MCRY040 + + + SARCL01-MCRY070 + + + SARCL01-MCRY090 + + + SARCL01-MCRY130 + + + SARCL01-MCRY180 + + + SARCL02-MCRY120 + + + SARCL02-MCRY230 + + + SARCL02-MCRY240 + + + SARCL02-MCRY320 + + + SARCL02-MCRY340 + + + SARCL02-MCRY450 + + + SARCL02-MCRY480 + + + SARMA01-MCRY020 + + + SARMA01-MCRY050 + + + SARMA01-MCRY070 + + + SARMA01-MCRY110 + + + SARMA01-MCRY130 + + + SARMA02-MCRY050 + + + SARMA02-MCRY120 + + + SARUN01-MCRY080 + + + SARUN02-MCRY080 + + + SARUN03-MCRY010 + + + SARUN03-MCRY040 + + + SARUN03-MCRY080 + + + SARUN04-MCRY010 + + + SARUN04-MCRY040 + + + SARUN04-MCRY080 + + + SARUN05-MCRY010 + + + SARUN05-MCRY040 + + + SARUN05-MCRY080 + + + SARUN06-MCRY010 + + + SARUN06-MCRY040 + + + SARUN06-MCRY080 + + + SARUN07-MCRY010 + + + SARUN07-MCRY040 + + + SARUN07-MCRY080 + + + SARUN08-MCRY010 + + + SARUN08-MCRY040 + + + SARUN08-MCRY080 + + + SARUN09-MCRY010 + + + SARUN09-MCRY040 + + + SARUN09-MCRY080 + + + SARUN10-MCRY010 + + + SARUN10-MCRY040 + + + SARUN10-MCRY080 + + + SARUN11-MCRY010 + + + SARUN11-MCRY040 + + + SARUN11-MCRY080 + + + SARUN12-MCRY010 + + + SARUN12-MCRY040 + + + SARUN12-MCRY080 + + + SARUN13-MCRY010 + + + SARUN13-MCRY040 + + + SARUN13-MCRY080 + + + SARUN14-MCRY010 + + + SARUN14-MCRY040 + + + SARUN14-MCRY080 + + + SARUN15-MCRY010 + + + SARUN15-MCRY040 + + + SARUN15-MCRY080 + + + SARUN16-MCRY080 + + + SARUN17-MCRY080 + + + SARUN18-MCRY080 + + + SARUN19-MCRY080 + + + SARUN20-MCRY080 + + + SARBD01-MCRY020 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + + + SINEG01-MSOL010 + + + SINEG01-MSOL130 + + + SINSB01-MSOL110 + + + SINSB01-MSOL120 + + + SINSB01-MSOL130 + + + SINSB01-MSOL140 + + + SINSB02-MSOL110 + + + SINSB02-MSOL120 + + + SINSB02-MSOL130 + + + SINSB02-MSOL140 + + + + Collection of Nodes at SwissFEL + + + SINEG01-MCOR120 + + + SINEG01-MCOR160 + + + SINEG01-MCOR180 + + + SINEG01-MCOR200 + + + SINEG01-MCOR220 + + + SINSB01-MCOR010 + + + SINSB02-MCOR010 + + + S20SY02-MCOR060 + + + S20SY02-MCOR090 + + + S20SY02-MCOR130 + + + S20SY02-MCOR170 + + + SARCL01-MCOR040 + + + SARCL01-MCOR070 + + + SARCL01-MCOR090 + + + SARCL01-MCOR130 + + + SARCL01-MCOR180 + + + SARCL02-MCOR120 + + + SARCL02-MCOR230 + + + SARCL02-MCOR240 + + + SARCL02-MCOR320 + + + SARCL02-MCOR340 + + + SARCL02-MCOR450 + + + SARCL02-MCOR480 + + + SARMA01-MCOR020 + + + SARMA01-MCOR050 + + + SARMA01-MCOR070 + + + SARMA01-MCOR110 + + + SARMA01-MCOR130 + + + SARUN03-MCOR010 + + + SARUN03-MCOR040 + + + SARUN04-MCOR010 + + + SARUN04-MCOR040 + + + SARUN05-MCOR010 + + + SARUN05-MCOR040 + + + SARUN06-MCOR010 + + + SARUN06-MCOR040 + + + SARUN07-MCOR010 + + + SARUN07-MCOR040 + + + SARUN08-MCOR010 + + + SARUN08-MCOR040 + + + SARUN09-MCOR010 + + + SARUN09-MCOR040 + + + SARUN10-MCOR010 + + + SARUN10-MCOR040 + + + SARUN11-MCOR010 + + + SARUN11-MCOR040 + + + SARUN12-MCOR010 + + + SARUN12-MCOR040 + + + SARUN13-MCOR010 + + + SARUN13-MCOR040 + + + SARUN14-MCOR010 + + + SARUN14-MCOR040 + + + SARUN15-MCOR010 + + + SARUN15-MCOR040 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + DEGAUSS + + + SINEG01-MQUA140 + + + SINEG01-MQUA150 + + + SINEG01-MQUA310 + + + SINEG01-MQUA320 + + + SINLH01-MQUA020 + + + SINLH01-MQUA030 + + + SINLH01-MQUA040 + + + SINLH01-MQUA050 + + + SINLH01-MQUA070 + + + SINLH02-MQUA010 + + + SINLH02-MQUA410 + + + SINLH03-MQUA030 + + + SINLH03-MQUA040 + + + SINLH03-MQUA060 + + + SINLH03-MQUA080 + + + SINSB03-MQUA130 + + + SINSB03-MQUA230 + + + SINSB04-MQUA130 + + + SINSB04-MQUA230 + + + SINSB05-MQUA130 + + + SINSB05-MQUA230 + + + SINBC01-MQUA020 + + + SINBC01-MQUA050 + + + SINBC01-MQUA070 + + + SINBC01-MQUA090 + + + SINBC01-MQUA110 + + + SINBC02-MQUA110 + + + SINBC02-MQUA120 + + + SINBC02-MQUA340 + + + SINBC02-MQUA350 + + + SINDI01-MQUA020 + + + SINDI01-MQUA030 + + + SINDI01-MQUA070 + + + SINDI02-MQUA020 + + + SINDI02-MQUA030 + + + SINDI02-MQUA050 + + + SINDI02-MQUA060 + + + SINDI02-MQUA070 + + + SINDI02-MQUA090 + + + S10CB01-MQUA230 + + + S10CB01-MQUA430 + + + S10CB02-MQUA230 + + + S10CB02-MQUA430 + + + S10DI01-MQUA030 + + + S10DI01-MQUA120 + + + S10CB03-MQUA230 + + + S10CB03-MQUA430 + + + S10CB04-MQUA230 + + + S10CB04-MQUA430 + + + S10CB05-MQUA230 + + + S10CB05-MQUA430 + + + S10CB06-MQUA230 + + + S10CB06-MQUA430 + + + S10CB07-MQUA230 + + + S10CB07-MQUA430 + + + S10CB08-MQUA230 + + + S10CB08-MQUA430 + + + S10CB09-MQUA230 + + + S10BC01-MQUA020 + + + S10BC01-MQUA040 + + + S10BC01-MQUA060 + + + S10BC01-MQUA080 + + + S10BC01-MQUA100 + + + S10BC02-MQUA110 + + + S10BC02-MQUA120 + + + S10BC02-MQUA340 + + + S10BC02-MQUA350 + + + S10MA01-MQUA020 + + + S10MA01-MQUA050 + + + S10MA01-MQUA070 + + + S10MA01-MQUA110 + + + S10MA01-MQUA130 + + + S20CB01-MQUA430 + + + S20CB02-MQUA430 + + + S20CB03-MQUA430 + + + S20SY01-MQUA020 + + + S20SY01-MQUA030 + + + S20SY01-MQUA050 + + + S20SY01-MQUA080 + + + S20SY02-MQUA070 + + + S20SY02-MQUA100 + + + S20SY02-MQUA140 + + + S20SY02-MQUA180 + + + S20SY03-MQUA020 + + + S20SY03-MQUA030 + + + S20SY03-MQUA050 + + + S20SY03-MQUA060 + + + S20SY03-MQUA100 + + + S30CB01-MQUA430 + + + S30CB02-MQUA430 + + + S30CB03-MQUA430 + + + S30CB04-MQUA430 + + + S30CB05-MQUA430 + + + S30CB06-MQUA430 + + + S30CB07-MQUA430 + + + S30CB08-MQUA430 + + + S30CB09-MQUA430 + + + S30CB10-MQUA430 + + + S30CB11-MQUA430 + + + S30CB12-MQUA430 + + + S30CB13-MQUA430 + + + S30CB14-MQUA430 + + + S30CB15-MQUA430 + + + SARCL01-MQUA020 + + + SARCL01-MQUA050 + + + SARCL01-MQUA080 + + + SARCL01-MQUA100 + + + SARCL01-MQUA140 + + + SARCL01-MQUA190 + + + SARCL02-MQUA130 + + + SARCL02-MQUA150 + + + SARCL02-MQUA160 + + + SARCL02-MQUA210 + + + SARCL02-MQUA250 + + + SARCL02-MQUA300 + + + SARCL02-MQUA310 + + + SARCL02-MQUA350 + + + SARCL02-MQUA420 + + + SARCL02-MQUA430 + + + SARCL02-MQUA460 + + + SARMA01-MQUA010 + + + SARMA01-MQUA060 + + + SARMA01-MQUA080 + + + SARMA01-MQUA120 + + + SARMA01-MQUA140 + + + SARMA02-MQUA050 + + + SARMA02-MQUA120 + + + SARUN01-MQUA080 + + + SARUN02-MQUA080 + + + SARUN03-MQUA020 + + + SARUN03-MQUA050 + + + SARUN03-MQUA080 + + + SARUN04-MQUA020 + + + SARUN04-MQUA050 + + + SARUN04-MQUA080 + + + SARUN05-MQUA020 + + + SARUN05-MQUA050 + + + SARUN05-MQUA080 + + + SARUN06-MQUA020 + + + SARUN06-MQUA050 + + + SARUN06-MQUA080 + + + SARUN07-MQUA020 + + + SARUN07-MQUA050 + + + SARUN07-MQUA080 + + + SARUN08-MQUA020 + + + SARUN08-MQUA050 + + + SARUN08-MQUA080 + + + SARUN09-MQUA020 + + + SARUN09-MQUA050 + + + SARUN09-MQUA080 + + + SARUN10-MQUA020 + + + SARUN10-MQUA050 + + + SARUN10-MQUA080 + + + SARUN11-MQUA020 + + + SARUN11-MQUA050 + + + SARUN11-MQUA080 + + + SARUN12-MQUA020 + + + SARUN12-MQUA050 + + + SARUN12-MQUA080 + + + SARUN13-MQUA020 + + + SARUN13-MQUA050 + + + SARUN13-MQUA080 + + + SARUN14-MQUA020 + + + SARUN14-MQUA050 + + + SARUN14-MQUA080 + + + SARUN15-MQUA020 + + + SARUN15-MQUA050 + + + SARUN15-MQUA080 + + + SARUN16-MQUA080 + + + SARUN17-MQUA080 + + + SARUN18-MQUA080 + + + SARUN19-MQUA080 + + + SARUN20-MQUA080 + + + S10BD01-MQUA010 + + + SARBD01-MQUA020 + + + SARBD02-MQUA030 + + + + Collection of Nodes at SwissFEL + + I-SET + I-READ + PS-MODE + DEGAUSS + + + SINEG01-MBND300 + + + SINLH02-MBND100 + + + SINLH02-MBND200 + + + SINLH02-MBND300 + + + SINLH02-MBND400 + + + SINBC02-MBND100 + + + SINBC02-MBND200 + + + SINBC02-MBND300 + + + SINBC02-MBND400 + + + S10DI01-MBND100 + + + S10BC02-MBND100 + + + S10BC02-MBND200 + + + S10BC02-MBND300 + + + S10BC02-MBND400 + + + S10MA01-MBND100 + + + S20SY02-MBND200 + + + SARCL02-MBND100 + + + SARCL02-MBND200 + + + SARCL02-MBND400 + + + SARCL02-MBND500 + + + SARMA02-MBND100 + + + SARBD01-MBND100 + + + SARBD01-MBND200 + + + + Collection of Nodes at SwissFEL + + CAV-AMPLT-AVG + CAV-POWER-AVG + CAV-PHASE-AVG + + + SINEG01-RGUN100 + + + + Collection of Nodes at SwissFEL + + FOR-AMPLT-AVG + FOR-POWER-AVG + FOR-PHASE-AVG + + + SINEG01-RWVG100 + + + SINSB01-RWVG100 + + + SINSB02-RWVG100 + + + SINSB03-RWVG100 + + + SINSB04-RWVG100 + + + SINXB01-RWVG100 + + + SINDI01-RWVG100 + + + S10CB01-RWVG100 + + + S10CB01-RWVG300 + + + S10CB02-RWVG100 + + + S10CB02-RWVG300 + + + S10CB03-RWVG100 + + + S10CB03-RWVG300 + + + S10CB04-RWVG100 + + + S10CB04-RWVG300 + + + S10CB05-RWVG100 + + + S10CB05-RWVG300 + + + S10CB06-RWVG100 + + + S10CB06-RWVG300 + + + S10CB07-RWVG100 + + + S10CB07-RWVG300 + + + S10CB08-RWVG100 + + + S10CB08-RWVG300 + + + S10CB09-RWVG100 + + + S10CB09-RWVG300 + + + S20CB01-RWVG100 + + + S20CB01-RWVG300 + + + S20CB02-RWVG100 + + + S20CB02-RWVG300 + + + S20CB03-RWVG100 + + + S20CB03-RWVG300 + + + S20CB04-RWVG100 + + + S20CB04-RWVG300 + + + S30CB01-RWVG100 + + + S30CB01-RWVG300 + + + S30CB02-RWVG100 + + + S30CB02-RWVG300 + + + S30CB03-RWVG100 + + + S30CB03-RWVG300 + + + S30CB04-RWVG100 + + + S30CB04-RWVG300 + + + S30CB05-RWVG100 + + + S30CB05-RWVG300 + + + S30CB06-RWVG100 + + + S30CB06-RWVG300 + + + S30CB07-RWVG100 + + + S30CB07-RWVG300 + + + S30CB08-RWVG100 + + + S30CB08-RWVG300 + + + S30CB09-RWVG100 + + + S30CB09-RWVG300 + + + S30CB10-RWVG100 + + + S30CB10-RWVG300 + + + S30CB11-RWVG100 + + + S30CB11-RWVG300 + + + S30CB12-RWVG100 + + + S30CB12-RWVG300 + + + S30CB13-RWVG100 + + + S30CB13-RWVG300 + + + S30CB14-RWVG100 + + + + Collection of Nodes at SwissFEL + + CAV-AMPLT-AVG + CAV-POWER-AVG + CAV-PHASE-AVG + + + SINSB01-RACC100 + + + SINSB02-RACC100 + + + SINSB03-RACC100 + + + SINSB03-RACC200 + + + SINSB04-RACC100 + + + SINSB04-RACC200 + + + SINXB01-RACC100 + + + SINXB01-RACC200 + + + S10CB01-RACC100 + + + S10CB01-RACC200 + + + S10CB01-RACC300 + + + S10CB01-RACC400 + + + S10CB02-RACC100 + + + S10CB02-RACC200 + + + S10CB02-RACC300 + + + S10CB02-RACC400 + + + S10CB03-RACC100 + + + S10CB03-RACC200 + + + S10CB03-RACC300 + + + S10CB03-RACC400 + + + S10CB04-RACC100 + + + S10CB04-RACC200 + + + S10CB04-RACC300 + + + S10CB04-RACC400 + + + S10CB05-RACC100 + + + S10CB05-RACC200 + + + S10CB05-RACC300 + + + S10CB05-RACC400 + + + S10CB06-RACC100 + + + S10CB06-RACC200 + + + S10CB06-RACC300 + + + S10CB06-RACC400 + + + S10CB07-RACC100 + + + S10CB07-RACC200 + + + S10CB07-RACC300 + + + S10CB07-RACC400 + + + S10CB08-RACC100 + + + S10CB08-RACC200 + + + S10CB08-RACC300 + + + S10CB08-RACC400 + + + S10CB09-RACC100 + + + S10CB09-RACC200 + + + S10CB09-RACC300 + + + S10CB09-RACC400 + + + S20CB01-RACC100 + + + S20CB01-RACC200 + + + S20CB01-RACC300 + + + S20CB01-RACC400 + + + S20CB02-RACC100 + + + S20CB02-RACC200 + + + S20CB02-RACC300 + + + S20CB02-RACC400 + + + S20CB03-RACC100 + + + S20CB03-RACC200 + + + S20CB03-RACC300 + + + S20CB03-RACC400 + + + S20CB04-RACC100 + + + S20CB04-RACC200 + + + S20CB04-RACC300 + + + S20CB04-RACC400 + + + S30CB01-RACC100 + + + S30CB01-RACC200 + + + S30CB01-RACC300 + + + S30CB01-RACC400 + + + S30CB02-RACC100 + + + S30CB02-RACC200 + + + S30CB02-RACC300 + + + S30CB02-RACC400 + + + S30CB03-RACC100 + + + S30CB03-RACC200 + + + S30CB03-RACC300 + + + S30CB03-RACC400 + + + S30CB04-RACC100 + + + S30CB04-RACC200 + + + S30CB04-RACC300 + + + S30CB04-RACC400 + + + S30CB05-RACC100 + + + S30CB05-RACC200 + + + S30CB05-RACC300 + + + S30CB05-RACC400 + + + S30CB06-RACC100 + + + S30CB06-RACC200 + + + S30CB06-RACC300 + + + S30CB06-RACC400 + + + S30CB07-RACC100 + + + S30CB07-RACC200 + + + S30CB07-RACC300 + + + S30CB07-RACC400 + + + S30CB08-RACC100 + + + S30CB08-RACC200 + + + S30CB08-RACC300 + + + S30CB08-RACC400 + + + S30CB09-RACC100 + + + S30CB09-RACC200 + + + S30CB09-RACC300 + + + S30CB09-RACC400 + + + S30CB10-RACC100 + + + S30CB10-RACC200 + + + S30CB10-RACC300 + + + S30CB10-RACC400 + + + S30CB11-RACC100 + + + S30CB11-RACC200 + + + S30CB11-RACC300 + + + S30CB11-RACC400 + + + S30CB12-RACC100 + + + S30CB12-RACC200 + + + S30CB12-RACC300 + + + S30CB12-RACC400 + + + S30CB13-RACC100 + + + S30CB13-RACC200 + + + S30CB13-RACC300 + + + S30CB13-RACC400 + + + + Collection of Nodes at SwissFEL + + GAP-READ + GAP_SP + EAB + + + SINLH02-UIND230 + + + SARUN03-UIND030 + + + SARUN04-UIND030 + + + SARUN05-UIND030 + + + SARUN06-UIND030 + + + SARUN07-UIND030 + + + SARUN08-UIND030 + + + SARUN09-UIND030 + + + SARUN10-UIND030 + + + SARUN11-UIND030 + + + SARUN12-UIND030 + + + SARUN13-UIND030 + + + SARUN14-UIND030 + + + SARUN15-UIND030 + + +