コード例 #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()
コード例 #2
0
    def reset(self):
        print ('================= RESET EPICS WAVE SETUP ===============')
        from CaChannel import CaChannel

        wavex = CaChannel()
        wavey = CaChannel()

        for chan in range(1, 3):

            if getattr(self, 'wave_%d' % (chan)).isOn():

                try:
                    pv_wave_x = getattr(self, 'wave_%d_pv_x' % (chan)).data()
                    wavex.searchw(pv_wave_x)
                except:
                    msg = 'Error on PV waveform %d x variable' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                try:
                    pv_wave_y = getattr(self, 'wave_%d_pv_y' % (chan)).data()
                    wavey.searchw(pv_wave_y)
                except:
                    msg = 'Error reading y waveform %d values' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                wavex.putw([0, 0])
                wavey.putw([0, 0])

        del wavex
        del wavey
        print ('========================================================')

        return 1
コード例 #3
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()
コード例 #4
0
    def init(self):
        print ('================= INIT EPICS WAVE SETUP ===============')
        from CaChannel import CaChannel

        wavex = CaChannel()
        wavey = CaChannel()
        trig = CaChannel()

        try:
            pv_trig_name = self.pv_trig_name.data()
            trig.searchw(pv_trig_name)
        except:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error on PV trigger variable')
            raise mdsExceptions.TclFAILED_ESSENTIAL

        # trig.searchw('NB-SIGV-GISA:REF-TR_TIME')

        try:
            trig_data = self.trig_source.data()
        except:
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Trigger time')
            raise mdsExceptions.TclFAILED_ESSENTIAL

        #print('Trigger ', trig_data)

        trig.putw(float(trig_data))

        for chan in range(1, 8):

            # wavex.searchw('NB-SIGV-GISA:PZ%d-WAVEX'%(chan))
            # wavey.searchw('NB-SIGV-GISA:PZ%d-WAVEY'%(chan))

            if getattr(self, 'wave_%d' % (chan)).isOn():

                try:
                    pv_wave_x = getattr(self, 'wave_%d_pv_x' % (chan)).data()
                    wavex.searchw(pv_wave_x)
                except:
                    msg = 'Error on PV waveform %d x variable' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                try:
                    wavex_data = getattr(self, 'wave_%d_x' % (chan)).data()
                except:
                    msg = 'Error reading x waveform %d values' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                try:
                    pv_wave_y = getattr(self, 'wave_%d_pv_y' % (chan)).data()
                    wavey.searchw(pv_wave_y)
                except:
                    msg = 'Error reading y waveform %d values' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                try:
                    wavey_data = getattr(self, 'wave_%d_y' % (chan)).data()
                except:
                    msg = 'Error reading y waveform %d values' % (chan)
                    Data.execute('DevLogErr($1,$2)', self.getNid(), msg)
                    raise mdsExceptions.TclFAILED_ESSENTIAL

                print('CH %d' % (chan))
                print('X = ', wavex_data)
                print('Y = ', wavey_data)

                wavex.putw(wavex_data)
                wavey.putw(wavey_data)

        del wavex
        del wavey
        del trig
        print ('=======================================================')

        return 1