Ejemplo n.º 1
0
    def set_pv_value(self, name, value, wait=False, timeout=TIMEOUT):
        """Set the PV to a value.
           When getting a PV value this call should be used, unless there is a special requirement.

        Parameters:
            name - the PV name
            value - the value to set
            wait - wait for the value to be set before returning
        """
        name = MYPVPREFIX + ':' + name
        if name not in CACHE.keys():
            chan = CaChannel(name)
            chan.setTimeout(TIMEOUT)
            #Try to connect - throws if cannot
            chan.searchw()
            CACHE[name] = chan
        else:
            chan = CACHE[name]
        if wait:
            chan.putw(value)
        else:

            def putCB(epics_args, user_args):
                #Do nothing in the callback
                pass

            ftype = chan.field_type()
            ecount = chan.element_count()
            chan.array_put_callback(value, ftype, ecount, putCB)
            chan.flush_io()
Ejemplo n.º 2
0
class pv():
    # Wrapper for associating CaChannel class to specific PV using its name 
    def __init__(self, pvname):
        try:
            self.pv = CaChannel()
            self.pv.searchw(pvname)
            self.alarm_status = "n/a"	# used to store severity provided by callback
            self.alarm_severity = "n/a"	# used to store severity provided by callback
        except :
            raise Exception("****** PV not found - "+pvname+" ******")
        #return pv
  
    # Wrapper for putw() function - writing a value to PV and waiting for input records to scan (update their value)
    def write(self, *args):
        try:
            if len(args) == 2:  # arguments: value, scan_time
                self.pv.putw(args[0])
                time.sleep(args[1])
            if len(args) == 3:  # arguments: value, scan_time, type
                if args[2] == "STRING":
                    self.pv.putw(args[0],ca.DBR_STRING)
                else:
                    raise Exception("Type "+ str(args[3]) +" not recognized")
                time.sleep(args[1])
            print("***W: Set  PV "+self.pv.name()+" to    "+str(args[0]))
        except:
            print("Could not set PV "+self.pv.name()+" to "+str(args[0]))
    
    # Similar to write() except it does not print output when successfully sets the value
    # Useful for setUp and tearDown methods
    def write_silent(self, *args):
        try:
            if len(args) == 2:  # arguments: value, scan_time
                self.pv.putw(args[0])
                time.sleep(args[1])
            if len(args) == 3:  # arguments: value, scan_time, type
                if args[2] == "STRING":
                    self.pv.putw(args[0],ca.DBR_STRING)
                else:
                    raise Exception("Type "+ str(args[3]) +" not recognized")
                time.sleep(args[1])
        except:
            print("Could not set PV "+self.pv.name()+" to "+str(args[0]))
    
    # Wrapper for getw()
    def read(self, *args):
        if len(args) == 1:
            if args[0] == "STRING":
                val = self.pv.getw(ca.DBR_STRING)
            else:
                raise Exception("Type "+ str(args[3]) +" not recognized")
            print("***R: Read PV "+self.pv.name()+" value "+str(val))
            return val
        else:
            val = self.pv.getw()
            print("***R: Read PV "+self.pv.name()+" value "+str(val))
            return val
            
    # Wrapper for getw() with CALLBACK for alarm status/severity
    def read_alarm(self):
        self.pv.array_get_callback(ca.dbf_type_to_DBR_STS(self.pv.field_type()), None, Callback, self)
        self.pv.flush_io()
        for i in range(20):
            self.pv.pend_event()
    
    # Wrapper for name()
    def name(self):
        return self.pv.name()