了解 GPIB 接口的 Perl 脚本



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

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

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

    在珀尔?。什么是 python 等价物的 get_gpib_status 函数??.

    非常感谢任何形式的帮助。提前谢谢。脚本如下所示。

    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;
    }
    

AD 1。/Error/是一个正则表达式,匹配任何包含"错误"作为其子字符串的字符串;在此上下文(if(/Error/)中,它被评估为布尔表达式,即。如果在变量中找到匹配$_则为 true;

广告 2.chomp从其参数中删除尾随换行符,或者在缺少参数的情况下,从变量中删除$_;s/+//g;用任何内容替换$_中找到的任何+标志(即删除它们)。你可能已经注意到了,如果没有另行指定,许多 Perl 构造都可以在$_上运行。

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

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

相关内容

  • 没有找到相关文章

最新更新