コード例 #1
0
    def get_pv_value(self, name, to_string=False, timeout=TIMEOUT):
        """Get the current value of the PV"""
        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]
        ftype = chan.field_type()
        if ca.dbr_type_is_ENUM(ftype) or ca.dbr_type_is_CHAR(
                ftype) or ca.dbr_type_is_STRING(ftype):
            to_string = True
        if to_string:
            if ca.dbr_type_is_ENUM(ftype):
                value = chan.getw(ca.DBR_STRING)
            else:
                value = chan.getw(ca.DBR_CHAR)
            #Could see if the element count is > 1 instead
            if isinstance(value, list):
                return self._waveform2string(value)
            else:
                return str(value)
        else:
            return chan.getw()
コード例 #2
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()
コード例 #3
0
    for record in db.values():
        if rtyps and record.rtyp not in rtyps:
            continue

        # issue connect requests and wait for connection
        chans = {}
        for field in record.fields:
            chan = CaChannel(record.name + '.' + field)
            chan.search()
            chans[field] = chan
        ca.pend_io(10)

        # issue read requests and wait for completion
        for chan in chans.values():
            chan.array_get(ca.dbf_type_to_DBR_CTRL(chan.field_type()))
        ca.pend_io(10)

        # compare and print
        all_consistent = True
        for field, chan in chans.items():
            # get configured value
            config_value = record.fields[field]
            # skip those with empty config values
            if config_value == '':
                continue

            # dbr is a dict containing the channel information
            dbr = chan.getValue()
            actual_value = dbr['pv_value']
コード例 #4
0
ファイル: wrapper.py プロジェクト: EPICS-F3RP61/epics-f3rp61
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()