我是 perl 和 python 的新手。作为我目前工作的一部分,我被要求将 perl 脚本转换为 python。该脚本的目的是自动化 magnum 测试仪和参数分析仪的任务。你们中的任何人都能够理解 get_gpib_status 函数试图做什么吗?具体问题是
- perl 中的 if(/Error/) 是什么意思?
这是什么意思
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; }