Ejemplo n.º 1
0
def checkName(name):
    """usage: checkName("xxx:m1.VAL")"""
    if not cadict.has_key(name):
        # Make a new entry in the PV-name dictionary
        channel = CaChannel()
        try:
            channel.searchw(name)
        except CaChannelException, status:
            print "checkName: CaChannel exception, status=", status
            raise CaChannelException, status
            return
        cadict[name] = [channel, 0]  # [channel, callback_flag]
Ejemplo n.º 2
0
def checkName(name, timeout=None, retries=None):
	"""
	usage: checkName("xxx:m1.VAL", timeout=None, retries=None)
	Intended for internal use by ca_util functions.
	"""

	global cadict, defaultTimeout, defaultRetries
	if not name:
		raise ca_utilException, EXCEPTION_NULL_NAME
		return

	if ((timeout == None) and (defaultTimeout != None)): timeout = defaultTimeout
	if (timeout == "NONE"): timeout = None

	if ((retries == None) and (defaultRetries != None)): retries = defaultRetries
	if ((retries == None) or (retries == "NONE")): retries = 0

	tries = 0
	while (not cadict.has_key(name)) and (tries <= retries):
		# Make a new entry in the PV-name dictionary
		try:
			channel = CaChannel.CaChannel()
			if (timeout != None): channel.setTimeout(timeout)
			channel.searchw(name)
			cadict[name] = cadictEntry(channel)
		except CaChannel.CaChannelException, status:
			del channel
			tries += 1
     def reconnect(self):
         try:
             self.chan=CaChannel()
             self.chan.search(self.pvName)
             self.chan.pend_io()
             if (self.chan.element_count()<1):
                 self.rPrint("No channels named "+self.pvName+" found, is the SoftIOC running?")
                 self.connected=(self.chan.state()==ca.ch_state.cs_conn)
             self.chan.add_masked_array_event(ca.DBR_STRING,1,ca.DBE_ALARM | ca.DBE_VALUE,self.alarmHandler)
 	    
         except CaChannelException, status:
             print ca.message(status)
             self.connected=0
Ejemplo n.º 4
0
def main():
    try:
        cawave = CaChannel()

        cawave.searchw('cawave')
        
        t = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19)
        l = []
        for i in range(0,500):
            l.append(i)
        #cawave.array_put(t)
        #cawave.pend_io()
        
        cawave.putw(l)
        print(cawave.getw())
        
        cawave.add_masked_array_event(None, None, ca.DBE_VALUE, getCallback, 0)
        cawave.pend_event()
        #cawave.clear_event()

    except CaChannelException as status:
        print(ca.message(status))
Ejemplo n.º 5
0
def testConnect(pv):
    '''Tests if a CaChannel connection can be established to "pv"
       @param pv:[string]
       @return: True if can connect, otherwise False'''
    result = False
    if not IMPORTED_CACHANNEL:
        return result
    try:
        #print 'testConnect:', type(pv), pv
        chan = CaChannel.CaChannel()
        chan.searchw(str(pv))
        # val = chan.getw()
        del chan
        result = True
    except (TypeError, CaChannel.CaChannelException), status:
        # python3: (TypeError, CaChannel.CaChannelException) as status
        #print 'testConnect:', status
        pass
Ejemplo n.º 6
0
 def connectw(self):
     '''initiate the connection with EPICS, standard wait for the connection'''
     if IMPORTED_CACHANNEL:
         if len(self.pv) > 0:
             self.chan = CaChannel.CaChannel()
             self.chan.searchw(str(self.pv))
Ejemplo n.º 7
0
 def connect(self):
     '''initiate the connection with EPICS'''
     if IMPORTED_CACHANNEL:
         if len(self.pv) > 0:
             self.chan = CaChannel.CaChannel()
             self.chan.search(str(self.pv))
 class RoboEpicsChannel:
     def __init__(self,pvName,verbose=0):
         self.MAXPUTS=10
         self.pvName=pvName
         self.status=0 # no error
         self.severity=0
         self.statusReady=0 # has a command been executed
         self.waiting=0 # is the variable overbooked
         self.putAttempts=0 # the number of times it has tried to put a variable
         self.putSuccess=0 # if the last put command was successful
         self.verbose=verbose # if epics should print everything out for alarms and all
         self.CurrentText=""
         if ((self.pvName.upper().find("ROBO")<0) & DebugMode):
             self.rPrint("Variable "+pvName+" affects beamline and will not be altered")
         self.reconnect()
     def rPrint(self,cString):
         self.CurrentText=self.pvName+": "+cString
         print self.CurrentText
     def binaryClick(self): #specific method for dealing with the binary variables that return T/F based on success in robot
 		putOK=self.rPutVal(5)
 		robotOK=self.getVal()
 		if (robotOK==5):
 			time.sleep(.12)
 			robotOK=self.getVal()
 		return (putOK & robotOK)
     def getVal(self):
         try:
             val=self.chan.getw()
         except:
             try: #try one time to reconnect
                 self.rPrint("Variable "+self.pvName+" appears to be disconnected, attempting reconnect")
                 self.reconnect()
                 val=self.chan.getw()
                 self.statusReady=0
             except:
                 self.connected=0
                 val=""
                 self.rPrint("Variable "+self.pvName+" cannot be read after 1 reconnect attempt")
         return val
 
     def putVal(self,val): #direct putval without any retry features
         try:
             if (self.waiting):
                 time.sleep(2) # give 2 seconds rest while the system is queued
             if ((self.pvName.upper().find("ROBO")<0) & DebugMode):
                 self.rPrint("Debug Mode Enabled, thus not altered")
             else:
                 self.chan.putw(val)
 		
             self.statusReady=0
             time.sleep(0.12)
             # sleep 120 ms to wait for alarm callback
             if (self.statusReady==0):
                 self.alarmUpdate()
             return self.putSuccess
         except:
             self.connected=0
 	    return 0
 
 
     def rPutVal(self,val): # the safe put function that ensures the robot accepts the command, the CAChannel package makes this trickier than needed
         self.putSuccess=0
         self.putAttempts=0
         while ((self.putSuccess<>1) & (self.putAttempts<self.MAXPUTS)):
             self.putVal(val)	
             if (self.putSuccess==0):
                 self.rPrint("Ensure Robot is on and in correct Position! Attempt "+self.putAttempts.__str__()+" of "+self.MAXPUTS.__str__())
                 tempPA=self.putAttempts
                 self.reconnect()
                 time.sleep(5)
                 self.putAttempts=tempPA
 
         if (self.putSuccess):
             if (self.verbose):
     			print self.pvName+" was successfully put"
             return 1
         else:
             self.rPrint("Put was not successful")
             return 0
     
     def statusText(self):
     	return self.pvName+" is currently "+ca.alarmStatusString(self.status)
 	
     def alarmHandler(self,epics_args,user_args):
     	# a function to handle the alarm feedback from epics telling the user what has happened
         # the primary purpose is to not allow channels to get overbooked CALC and to know if a variable has been set or nto
         self.status=epics_args["pv_status"]
         self.severity=epics_args["pv_severity"]
         self.alarmUpdate()
 	
     def alarmUpdate(self):
         self.statusReady=1
         if ((self.status<>ca.AlarmStatus.NO_ALARM) & (self.status<>ca.AlarmStatus.CALC_ALARM)):
 		
             self.putSuccess=0
             self.putAttempts+=1
             if (self.verbose):
                 print self.statusText()
             print "Variable "+self.pvName+" not successfully written after "+str(self.putAttempts)+" try"
             
             print "Alarm Severity : "+ca.alarmSeverityString(self.severity)
         else:
             self.putSuccess=1
             self.putAttempts=0
 			
         if (self.status==ca.AlarmStatus.CALC_ALARM):
             self.waiting=1
             if (self.verbose):
                 print "Variable "+self.pvName+" is currently queued!"
         if ((self.waiting==1) & (self.status==ca.AlarmStatus.NO_ALARM)):
             self.waiting=0
             if (self.verbose):
                 print "Queue Cleared!"
     def reconnect(self):
         try:
             self.chan=CaChannel()
             self.chan.search(self.pvName)
             self.chan.pend_io()
             if (self.chan.element_count()<1):
                 self.rPrint("No channels named "+self.pvName+" found, is the SoftIOC running?")
                 self.connected=(self.chan.state()==ca.ch_state.cs_conn)
             self.chan.add_masked_array_event(ca.DBR_STRING,1,ca.DBE_ALARM | ca.DBE_VALUE,self.alarmHandler)
 	    
         except CaChannelException, status:
             print ca.message(status)
             self.connected=0
Ejemplo n.º 9
0
class RealRoboEpicsChannel:
    def __init__(self,pvName,verbose=0,asString=0,vcCallback=None):
        self.MAXPUTS=10
        self.pvName=pvName
        self.asString=asString
        self.curValue=0
        self.lastPoll=0
        self.status=0 # no error
        self.severity=0
        self.statusReady=0 # has a command been executed
        self.waiting=0 # is the variable overbooked
        self.putAttempts=0 # the number of times it has tried to put a variable
        self.putSuccess=0 # if the last put command was successful
        self.verbose=verbose # if epics should print everything out for alarms and all
        self.CurrentText=""
        self.vcCallback=vcCallback # the callback should the value change feed with (chname,newVal,oldVal)
        
        if ((self.pvName.upper().find("ROBO")<0) & DebugMode):
            self.rPrint("Variable "+pvName+" affects beamline and will not be altered")
        self.reconnect()
    def rPrint(self,cString):
        self.CurrentText=self.pvName+": "+cString
        print self.CurrentText
    def binaryClick(self): #specific method for dealing with the binary variables that return T/F based on success in robot
		putOK=self.rPutVal(5)
		robotOK=self.getVal()
		if (robotOK==5):
			time.sleep(.12)
			robotOK=self.getVal()
		if (ReadOnly):
			putOK=1
			robotOK=1
		return (putOK & robotOK)
    def getVal(self):
        
        try:
            cTime=time.time()
            if (cTime-self.lastPoll)>0.2: # prevent double polling
                
                val=self.chgetw()
                self.curValue=val
                self.lastPoll=cTime
            else:
                val=self.curValue
        except:
            try: #try one time to reconnect
                self.rPrint("Variable "+self.pvName+" appears to be disconnected, attempting reconnect")
                self.reconnect()
                val=self.chgetw()
                self.statusReady=0
            except:
                self.connected=0
                val=""
                self.rPrint("Variable "+self.pvName+" cannot be read after 1 reconnect attempt")
        return val
    def chgetw(self):
        if self.asString==1:
            return str(self.chan.getw(ca.DBF_STRING))
        else:
            return self.chan.getw()
    def putVal(self,iVal): #direct putval without any retry features
        self.lastPoll=0
        
        # crop string when it is too long
        val=iVal
        if type(iVal)==type(''):
            if len(iVal)>40:
                val=iVal[0:39]
                print 'String was cropped :'+str(val)
                
        try:
            if (self.waiting):
                time.sleep(2) # give 2 seconds rest while the system is queued
            if ((self.pvName.upper().find("ROBO")<0) & DebugMode):
                self.rPrint("Debug Mode Enabled, thus not altered")
            else:
                if not ReadOnly:
                    self.curValue=val # default assumption is the value will be loaded
                    self.chan.putw(val)
		
            self.statusReady=0
            time.sleep(0.12)
            # sleep 120 ms to wait for alarm callback
            if (self.statusReady==0):
                self.alarmUpdate()
            return self.putSuccess
        except:
            self.connected=0
	    return 0


    def rPutVal(self,val): # the safe put function that ensures the robot accepts the command, the CAChannel package makes this trickier than needed
        self.putSuccess=0
        self.putAttempts=0
        self.lastPoll=0
        while ((self.putSuccess<>1) & (self.putAttempts<self.MAXPUTS)):
            self.putVal(val)	
            if (self.putSuccess==0):
                self.rPrint("Ensure Robot is on and in correct Position! Attempt "+self.putAttempts.__str__()+" of "+self.MAXPUTS.__str__())
                tempPA=self.putAttempts
                self.reconnect()
                time.sleep(5)
                self.putAttempts=tempPA

        if (self.putSuccess):
            if (self.verbose):
    			print self.pvName+" was successfully put"
            return 1
        else:
            self.rPrint("Put was not successful")
            return 0
    
    def statusText(self):
    	return self.pvName+" is currently "+ca.alarmStatusString(self.status)
	
    def vcHandler(self,epics_args,user_args):
        # A function to handle value change callbacks
        newValue=epics_args['pv_value']
        self.lastPoll=time.time() 
        if newValue!=self.curValue:
            # It is different from what we set it to, ick
            self.curValue=newValue
            self.vcCallback.__call__(self.pvName,newValue,self.curValue)
            
        
           
    def alarmHandler(self,epics_args,user_args):
    	# a function to handle the alarm feedback from epics telling the user what has happened
        # the primary purpose is to not allow channels to get overbooked CALC and to know if a variable has been set or nto
        self.status=epics_args["pv_status"]
        self.severity=epics_args["pv_severity"]
        self.alarmUpdate()
	
    def alarmUpdate(self):
        self.statusReady=1
        if ((self.status<>ca.AlarmStatus.NO_ALARM) & (self.status<>ca.AlarmStatus.CALC_ALARM)):
		
            self.putSuccess=0
            self.putAttempts+=1
            if (self.verbose):
                print self.statusText()
            if not (self.pvName.upper()=='ARIDI-PCT:CURRENT'): 
                print "Variable "+self.pvName+" not successfully written after "+str(self.putAttempts)+" try"
                print "Alarm Severity : "+ca.alarmSeverityString(self.severity)
        else:
            self.putSuccess=1
            self.putAttempts=0
			
        if (self.status==ca.AlarmStatus.CALC_ALARM):
            self.waiting=1
            if (self.verbose):
                print "Variable "+self.pvName+" is currently queued!"
        if ((self.waiting==1) & (self.status==ca.AlarmStatus.NO_ALARM)):
            self.waiting=0
            if (self.verbose):
                print "Queue Cleared!"
    def reconnect(self):
        try:
            self.chan=CaChannel()
            self.chan.search(self.pvName)
            self.chan.pend_io()
            if (self.chan.element_count()<1):
                self.rPrint("No channels named "+self.pvName+" found, is the SoftIOC running?")
                self.connected=(self.chan.state()==ca.ch_state.cs_conn)
            self.chan.add_masked_array_event(ca.DBR_STRING,None,ca.DBE_ALARM,self.alarmHandler)
            self.rebind(self.vcCallback)
        except CaChannelException, status:
            print ca.message(status)
            self.connected=0
Ejemplo n.º 10
0
from CaChannel import *
import time

FastScan   = 'X15U1:test:scan1'
SlowScan   = 'X15U1:test:scan2' ######this is should be changed
SISPrefix  = 'X15USIS:'
FastMotor  = 'X15U1:EH:MAN1:X'
SlowMotor  = 'X15U1:EH:MAN7:Z'
xMAPPrefix = '15UdxpXMAP:'
FileName   = 'Scan11'      ##### this is should be changed, the better way is the same as the file name of savedata 
FastSpeed  = 1.0
SlowSpeed  = 0.15


NumSlow=CaChannel()
NumFast=CaChannel()
xmapPixels=CaChannel()
sisEraseStart=CaChannel()
sisPixels=CaChannel()
sisPreScale=CaChannel()
xmapEraseStart=CaChannel()
xmapState=CaChannel()
FastScanBusy=CaChannel()
netCDFSaveMode=CaChannel()
netCDFNumCapture=CaChannel()
netCDFEnable=CaChannel()
netCDFCapture=CaChannel()
netCDFFileName=CaChannel()
netCDFFileNumber=CaChannel()
Zmotor=CaChannel()
Ejemplo n.º 11
0
def main():
    try:
        chan = CaChannel()
        print("search_and_connect")
        chan.search_and_connect('catest', connectCb)
        chan.flush_io()
        for i in range(20):
            chan.pend_event()
        print("put_callback")
        chan.array_put_callback(3.3, None, None, putCb)
        chan.flush_io()
        for i in range(20):
            chan.pend_event()
        print("get_callback")
        chan.array_get_callback(None, None, getCb1)
        chan.flush_io()
        for i in range(20):
            chan.pend_event()
        print("get_callback with status")
        chan.array_get_callback(ca.dbf_type_to_DBR_CTRL(chan.field_type()), None, getCb2)
        chan.flush_io()
        for i in range(20):
            chan.pend_event()
    except CaChannelException as status:
        print(ca.message(status))


    try:
        cawave = CaChannel()
        print("cawave: search_and_connect")
        cawave.search_and_connect('cawave', connectCb)
        cawave.flush_io()
        for i in range(20):
            cawave.pend_event()
        print("cawave: array_put_callback")
        l = [0,1,2,3,4,5,6,7,8,9]
        cawave.array_put_callback(l, None, None, putCb)
        cawave.flush_io()
        for i in range(20):
            cawave.pend_event()
        print("cawave: array_get_callback")
        cawave.array_get_callback(ca.dbf_type_to_DBR_CTRL(cawave.field_type()), None, getCb2)
        cawave.flush_io()
        for i in range(20):
            cawave.pend_event()
    except CaChannelException as status:
        print(ca.message(status))
Ejemplo n.º 12
0
def main():
    try:
        cawave = CaChannel()

        cawave.searchw('cawave')

        t = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
             19)
        l = []
        for i in range(0, 500):
            l.append(i)
        #cawave.array_put(t)
        #cawave.pend_io()

        cawave.putw(l)
        print(cawave.getw())

        cawave.add_masked_array_event(None, None, ca.DBE_VALUE, getCallback, 0)
        cawave.pend_event()
        #cawave.clear_event()

    except CaChannelException as status:
        print(ca.message(status))