0

我是 perl 和 python 的新手。作为我目前工作的一部分,我被要求将 perl 脚本转换为 python。该脚本的目的是自动化 magnum 测试仪和参数分析仪的任务。你们中的任何人都能够理解 get_gpib_status 函数试图做什么吗?具体问题是

  1. perl 中的 if(/Error/) 是什么意思?
  2. 这是什么意思

            chomp;
            s/\+//g;
            $value = $_;
            $foundError = 0;
    

    在 perl 中?get_gpib_status 函数的 python 等效项是什么?

    任何形式的帮助都将受到高度赞赏。提前致谢。脚本如下图所示。

    BEGIN {unshift(@INC, "." , ".." , 
    "\\Micron\\Nextest\\perl_modules");}
    
    
    use runcli;                                                                     
    # Enable input from perl script as nextest cli command, Runcli is the 
    command 
    that you’ll use to communicate with the tester
    use getHost;                                                                    
    # To latch in module/ "library into current script, here the 
    getHost.pm 
    is 
    loaded, used once on nextest system
    
    
    
    #open FILE,">","iv.txt" or die $!;                                              
    # Make file ready for reading from FILE
    
    
    $k=148;                                                                         
    # Time period T = 38ns corresponds to data value of 140
    #$i=0;
    while($k<156)
    {
    $i=3;
    while($i<4)
    {
    #$logfile = "vpasscp8stg_SS_vppmode"."stg"."$i"."freq"."$k".".txt";             
    # Give the name to the logfile
    #open(LOG,">$logfile") or die $!;                                               
    # Makes the file ready for reading from LOG
    
    
    #******************* SUBS ****************************
    
    if($i==3)
    {
    
    runcli("gpibinit;");
    runcli("gpibsend(0x1,\":PAGE:CHAN:MODE SWEEP\")");                              
    # PAGE, CHANnel, MODE, Set the mode to sweep
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU1:VNAME 'Vout'\")");                       
    # Source Monitor Unit, voltage name Vout
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU1:INAME 'Iout'\")");                       
    # current name Iout
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU1:MODE V\")");                             
    # voltage output node
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU1:FUNCTION VAR1\")");                      
    # function Variable
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU2:VNAME 'Vcc'\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU2:INAME 'Icc'\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU2:MODE V\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU2:FUNCTION CONSTANT\")");                  
    # function constant
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU3:VNAME 'Vpp'\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU3:INAME 'Ipp'\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU3:MODE V\")");
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU3:FUNCTION CONSTANT\")");
    
    #runcli("gpibsend(0x1,\":PAGE:CHAN:SMU3:DIS\")");
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:SMU4:DIS\")");
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:VSU1:DIS\")");                                
    # Voltage Source Unit DISabled
    
    runcli("gpibsend(0x1,\":PAGE:CHAN:VSU2:DIS\")");
    
    runcli("gpibsend(0x1,\":PAGE:DISP:LIST:SELECT 'Vout'\")");                      
    # DISPlay LIST
    runcli("gpibsend(0x1,\":PAGE:DISP:LIST:SELECT 'Iout'\")");
    runcli("gpibsend(0x1,\":PAGE:DISP:LIST:SELECT 'Vcc'\")");
    runcli("gpibsend(0x1,\":PAGE:DISP:LIST:SELECT 'Icc'\")");
    
    
    
    
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:MODE SINGLE\")");                  
    # Single Stair Sweep
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:SPACING LINEAR\")");               
    # The sweep is incremented (decremented) by the
    # stepsize until the stop value is reached.
    
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:START 2.8\")");                    
    # Setting the sweep range of Vout
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:STOP 18\")");
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:STEP 0.1\")");
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:COMPLIANCE 0.05\")");              
    # Compliance: meaning the stable state of voltage, on the parametric 
    analyzer
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:VAR1:PCOMPLIANCE:STATE 
    0\")");         
    # PCOMPLIANCE: Might be the state before the stable state
    
    runcli("gpibsend(0x1,\":PAGE:MEAS:DEL 2\")");                                   
    # Delay
    runcli("gpibsend(0x1,\":PAGE:MEAS:HTIM 50\")");                                 
    # Hold Time
    
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:CONS:SMU2:SOURCE 3.3\")");              
    # Setting the values for VCC
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:CONS:SMU2:COMP 0.1\")");
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:CONS:SMU3:SOURCE 12\")");               
    # Setting the values for VPP
    runcli("gpibsend(0x1,\":PAGE:MEAS:SWEEP:CONS:SMU3:COMP 0.1\")");
    
    
    runcli("gpibsend(0x1,\":PAGE:SCON:SING\")");
    
    sleep(2);
    runcli("ctst");
    runcli("stst");
    sleep(2);
    runcli("pu;rs");
    runcli("B16R_vpasscp_vpp.txt()");
    runcli("regaccess(static_load,0x9,0x9,$k)");                                    
    # Using the Cregs 0x9 to modulate the frequency
    runcli("adputr(0xcf,0x03)");
    runcli("rs");
    poll_4156c();
    }
    
    
    
    
    sub poll_4156c{
    runcli("gpibsend(0x1,\":STAT:OPER:COND?\");");                                  
    # This command returns the present status of the Operation
    # Status "CONDITION" register. Reading this register does not clear 
    it.
    runcli("gpibreceive(0x1);");
    while((get_gpib_status() > 0)&&($foundError < 1) ){
    sleep(3);
    runcli("gpibsend(0x1,\":STAT:OPER:COND?\")");
    runcli("gpibreceive(0x1);");
    }
    
    }#end poll_4156c subroutine
    
    
    
    
    
    sub get_gpib_status{
    # get file info
    $host_meas = getHost();                                                         
    # Retrieve the nextest station detail, will return something like 
    mav2pt 
    - 0014
    $file_meas = $host_meas."_temp.cli";                                            
    # Define the file_meas as the nextest cli temporary file, Contains 
    all 
    the text as displayed on Nextest CLI
    open(STATUS, "$file_meas" ) || die("Can't open logfile: $!");
    print "\nSTATUS received from GPIB:";
    while(<STATUS>)
    {
    if(/Error/){
    runcli("gpibinit;");
    $foundError = 1;
    }
    else
    {
    chomp;
    s/\+//g;
    $value = $_;
    $foundError = 0;
    }
    } # End of while(<INMEAS>) loop.
    close(STATUS);
    #print "value = $value";
    return($value);
    }#End of get_gpib_status subroutine.
    
    
    $i=$i+1;
    }
    $k=$k+8;
    }
    
4

1 回答 1

0

广告 1./Error/是一个正则表达式,匹配任何包含“Error”作为其子字符串的字符串;在这种情况下 ( if(/Error/) 它被评估为布尔表达式,即。如果在$_变量中找到匹配项,则为真;

广告。2.chomp从变量中删除其参数中的尾随换行符,或者在缺少参数的情况下$_s/\+//g;将发现的任何+标志都替换$_为空(即删除它们)。您可能已经注意到,$_如果没有另外指定,许多 Perl 构造都会运行。

get_gpib_status在您的脚本中定义 -sub get_gpib_status是定义的开始(在 Perl 中,函数是使用sub关键字定义的,代表“子例程”)。

最后,我表示诚挚的哀悼。将程序从一种语言改写成另一种语言的任务交给没有任何一种语言经验的人可能不是我听说过的最愚蠢的管理决定,但在列表中排名靠前。

于 2017-07-04T19:56:14.067 回答