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()
Example #2
0
        def failProcThread(self, num):
            failFlag = 0
            while procFlag[num - 1]:
                time.sleep(5)
                chan = CaChannel('ACC_RCS_RRF:RRF' + str(num) + ':LLRF:Alarm')
                chan.searchw()
                failFlag = chan.getw()

                #print("procFlag:%d"%(procFlag[num-1]))
                #print("trigFlag:%d"%(trigFlag[num-1]))
                if failFlag == 0:
                    trigFlag[num - 1] = 0
                if ((failFlag == 1) and (trigFlag[num - 1] == 0)):
                    readWavesFunc(self, num)
 def _caget(pvname, as_string=False):
     """Retrieve an EPICS PV value"""
     try:
         from CaChannel import CaChannel, CaChannelException, ca
     except ImportError:
         raise RuntimeError("CaChannel must be installed to use this algorithm. "
                            "For details, see https://www.mantidproject.org/CaChannel_In_Mantid")
     if as_string:
         dbr_type = ca.DBR_STRING
     else:
         dbr_type = None
     try:
         chan = CaChannel(pvname)
         chan.setTimeout(5.0)
         chan.searchw()
         return chan.getw(dbr_type)
     except CaChannelException as e:
         raise RuntimeError("Error reading EPICS PV \"{}\": {}".format(pvname, str(e)))
Example #4
0
 def getw(self, req_type=None, count=None, **keywords):
     """
     If :meth:`setMonitor` has not been called then this function simply calls
     :meth:`CaChannel.CaChannel.getw`.  If :meth:`setMonitor` has been called then it calls
     :meth:`CaChannel.CaChannel.pend_event` with a very short timeout, and then returns the
     PV value from the last callback.
     """
     if self.callBack.monitorState != 0:
         # This should be self.poll(), but that is generating errors
         self.pend_event(.0001)
     if self.callBack.monitorState == 2:
         self.callBack.newMonitor = 0
         if count is None:
             return self.callBack.pv_value
         else:
             return self.callBack.pv_value[0:count]
     else:
         return CaChannel.getw(self, req_type, count, **keywords)
Example #5
0
    def readWavesFunc(self, num):
        try:
            #初始化参数
            chan = CaChannel('rcsRf' + str(num) + ':wf_amp_skew.VALA')
            chan.searchw()

            #parmFile = open(r'C:\Users\HP\Desktop\Waves\ampSkew'+str(num)+'.txt', 'w', encoding='utf-8')
            parmFile = open(r'ampSkew' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_gridTunningError.VALA')
            chan.searchw()

            parmFile = open(r'gridTunningError' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_cavTunningError.VALA')
            chan.searchw()

            parmFile = open(r'cavTunningError' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_phaseError.VALA')
            chan.searchw()

            parmFile = open(r'phaseError' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_beamPhase.VALA')
            chan.searchw()

            parmFile = open(r'beamPhase' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_cavBias.VALA')
            chan.searchw()

            parmFile = open(r'cavBias' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_cavBiasFF.VALA')
            chan.searchw()

            parmFile = open(r'cavBiasFF' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_gridBias.VALA')
            chan.searchw()

            parmFile = open(r'gridBias' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_cavAmp.VALA')
            chan.searchw()

            parmFile = open(r'cavAmp' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_gridAmp.VALA')
            chan.searchw()

            parmFile = open(r'gridAmp' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_frontAmp.VALA')
            chan.searchw()

            parmFile = open(r'frontAmp' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            chan = CaChannel('rcsRf' + str(num) + ':wf_beamAmp.VALA')
            chan.searchw()

            parmFile = open(r'beamAmp' + str(num) + '.txt',
                            'w',
                            encoding='utf-8')
            parmFile.write('%s\n' % (chan.getw()))
            parmFile.close()

            #延时10s
            time.sleep(20)
            print("delay 20 s")

        except CaChannelException as e:
            print(e)
Example #6
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()
Example #7
0
        def readWavesFunc(self, num):
            try:
                trigFlag[num - 1] = 1
                file_str1 = ''
                file_str2 = ''
                file_str3 = ''
                file_str4 = ''
                file_str5 = ''
                file_str6 = ''
                file_str7 = ''
                file_str8 = ''
                file_str9 = ''
                file_str10 = ''
                time_record = time.strftime("%Y_%m_%d_%H_%M_%S")
                rf_warning_value = 0

                chan = CaChannel('rcsRf' + str(num) + ':alarm0_get')
                chan.searchw()
                llrf_warnings[0] = chan.getw()
                if (llrf_warnings[0] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[0] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm1_get')
                chan.searchw()
                llrf_warnings[1] = chan.getw()
                if (llrf_warnings[0] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[1] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm2_get')
                chan.searchw()
                llrf_warnings[2] = chan.getw()
                if (llrf_warnings[2] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[2] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm3_get')
                chan.searchw()
                llrf_warnings[3] = chan.getw()
                if (llrf_warnings[3] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[3] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm4_get')
                chan.searchw()
                llrf_warnings[4] = chan.getw()
                if (llrf_warnings[4] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[4] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm5_get')
                chan.searchw()
                llrf_warnings[5] = chan.getw()
                if (llrf_warnings[5] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[5] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm6_get')
                chan.searchw()
                llrf_warnings[6] = chan.getw()
                if (llrf_warnings[6] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[6] + ','

                chan = CaChannel('rcsRf' + str(num) + ':alarm7_get')
                chan.searchw()
                llrf_warnings[7] = chan.getw()
                if (llrf_warnings[7] == 1):
                    file_str1 = file_str1 + llrf_warnings_text[7] + '\n'

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT19:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '阳极水压欠压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT20:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '阳极水压过压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT21:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '阳极水流量' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT22:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '隔直电容水流量' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT23:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '方仓风水交换水流量' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT24:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '功放柜急停开关' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT25:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '监控柜急停开关' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT26:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '主风压节点' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT27:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '副风压节点' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT28:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '方舱冷却前侧风压节点' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT29:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str2 = file_str2 + '断路器闭锁' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT30:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '放电棒状态' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT31:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '接地开关' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT32:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '灯丝欠流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT33:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '方舱冷却后侧风压节点' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT34:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '门开关' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT35:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '帘栅电源' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT36:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '加载腔漏水' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT39:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str3 = file_str3 + '大偏流源' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT40:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '人身联锁' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT41:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '加载腔总入水过压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT42:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '末级功放帘栅过流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT43:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '反馈放大器帘栅电流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT44:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '加载腔总进水过温' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT45:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '左加载腔出水过温' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT46:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '右加载腔出水过温' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT47:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '反馈放大器V1管栅极过压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT48:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '反馈放大器V3管栅极过压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT49:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str4 = file_str4 + '反馈放大器电源' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT50:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '栅极电压' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT51:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '高压光过流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT52:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '反馈放大器阳极电流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT53:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '末级功放阳极过流' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT54:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '左加载腔出水流量' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT55:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '右加载腔出水流量' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT56:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '高压电流模块仓温度' + ','

                chan = CaChannel('ACC_RCS_RRF:RFPS' + str(num) + '::INT57:ai')
                chan.searchw()
                rf_warning_value = chan.getw()
                if (rf_warning_value == 3):
                    file_str5 = file_str5 + '反馈放大器V2管栅极过压' + ','

                chan = CaChannel('rcsRf' + str(num) + ':wf_amp_skew.VALA')
                chan.searchw()
                wf_1 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_phaseError.VALA')
                chan.searchw()
                wf_2 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) +
                                 ':wf_cavTunningError.VALA')
                chan.searchw()
                wf_3 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) +
                                 ':wf_gridTunningError.VALA')
                chan.searchw()
                wf_4 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_gridBias.VALA')
                chan.searchw()
                wf_5 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_cavBias.VALA')
                chan.searchw()
                wf_6 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_frontAmp.VALA')
                chan.searchw()
                wf_7 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_gridAmp.VALA')
                chan.searchw()
                wf_8 = chan.getw()

                chan = CaChannel('rcsRf' + str(num) + ':wf_cavAmp.VALA')
                chan.searchw()
                wf_9 = chan.getw()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\llrf_warnings' +
                    str(num) + time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write(
                    '%s\n%s\n%s\n%s\n%s\n' %
                    (file_str1, file_str2, file_str3, file_str4, file_str5))
                parmFile.close()

                parmFile = open(r'D:\eLog_Local\Software\Fail_Record\ampSkew' +
                                str(num) + time_record + '.txt',
                                'w',
                                encoding='utf-8')
                parmFile.write('%s\n' % (wf_1))
                parmFile.close()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\phaseError' +
                    str(num) + time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write('%s\n' % (wf_2))
                parmFile.close()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\cavTunningError' +
                    str(num) + time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write('%s\n' % (wf_3))
                parmFile.close()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\gridTunningError' +
                    str(num) + time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write('%s\n' % (wf_4))
                parmFile.close()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\gridBias' + str(num) +
                    time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write('%s\n' % (wf_5))
                parmFile.close()

                parmFile = open(r'D:\eLog_Local\Software\Fail_Record\cavBias' +
                                str(num) + time_record + '.txt',
                                'w',
                                encoding='utf-8')
                parmFile.write('%s\n' % (wf_6))
                parmFile.close()

                parmFile = open(
                    r'D:\eLog_Local\Software\Fail_Record\frontAmp' + str(num) +
                    time_record + '.txt',
                    'w',
                    encoding='utf-8')
                parmFile.write('%s\n' % (wf_7))
                parmFile.close()

                parmFile = open(r'D:\eLog_Local\Software\Fail_Record\gridAmp' +
                                str(num) + time_record + '.txt',
                                'w',
                                encoding='utf-8')
                parmFile.write('%s\n' % (wf_8))
                parmFile.close()

                parmFile = open(r'D:\eLog_Local\Software\Fail_Record\cavAmp' +
                                str(num) + time_record + '.txt',
                                'w',
                                encoding='utf-8')
                parmFile.write('%s\n' % (wf_9))
                parmFile.close()

                #延时1s
                time.sleep(1)
                print("Fail Wave Record finished!")

                #写ELOG

                driver = webdriver.Chrome()
                driver.get("http://elog.csns.ihep.ac.cn/Ring+RF/?cmd=Login")

                driver.find_element_by_name("uname").send_keys("longw")
                driver.find_element_by_name("upassword").send_keys("csnsrcsrf")

                driver.find_element_by_class_name("login_submit").click()

                WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located((By.CLASS_NAME, "title2")))
                print(driver.title)

                driver.find_element_by_link_text("New").click()
                WebDriverWait(driver, 10)
                Select(driver.find_element_by_name(
                    "Category")).select_by_value("Fault")
                driver.find_element_by_id("Beam commissioning").click()
                str_text = '自动故障记录:' + time_record
                time.sleep(2)
                driver.find_element_by_name("Subject").send_keys(str_text)
                time.sleep(2)
                driver.find_element_by_name("attfile").send_keys(
                    'D:\eLog_Local\Software\Fail_Record\llrf_warnings' +
                    str(num) + time_record + '.txt')
                time.sleep(2)
                driver.find_element_by_xpath(
                    "//input[@value='Upload']").click()
                time.sleep(1)
                driver.find_element_by_xpath(
                    "//input[@value='Submit']").click()
                time.sleep(1)
                driver.quit()

            except CaChannelException as e:
                print(e)