📄 opt.py
字号:
import visa
from time import sleep
from time import strftime, localtime
import time
import datetime
import copy
import math
import string
import shutil
import win32com.client as w32c
import epProcs
e = epProcs.EpProcs()
sa = visa.instrument("gpib::18::instr")
sw = visa.instrument("gpib::7::instr")
ps = visa.instrument("gpib::5::instr")
def SetSwitch(chan):
switches_closed = (sw.ask("route:close?")).split(',')
if len(switches_closed) == 4 and chan >= 1000:
return
if len(switches_closed) == 1 and chan < 1000:
return
sw.write("*rst")
sw.write("*cls")
if chan < 1000:
sw.write("route:open:all")
sw.write("route:clos (@4)")
else:
sw.write("route:open:all")
sw.write("route:clos (@5,30,31,32)")
def writeToCell(sh,row_adr,col_adr,val):
count = 1
while count<2:
try:
sh.Cells(row_adr,col_adr).Value = val
break
except w32c.pythoncom.com_error, why:
if why[0] == -2147418111:
print "the workbook is being used, so wait and re-try later."
sleep(1)
else:
print "unknown com error:\n"
print why
sleep(1)
def readFromCell(sh,row_adr,col_adr):
'''
it's up to the caller to determine the type
'''
count = 1
while count<2:
try:
val = sh.Cells(row_adr,col_adr).Value
return val
except w32c.pythoncom.com_error, why:
if why[0] == -2147418111:
print "the workbook is being used, so wait and re-try later."
sleep(1)
else:
print "unknown com error:\n"
print why
sleep(1)
def ConfigFileOpen(config_fname): #open donfiguration file
w32c.pythoncom.CoInitialize()
print w32c.pythoncom._GetInterfaceCount()
app = w32c.Dispatch("Excel.Application")
app.Visible = True
app.Interactive = True
wb_config = app.Workbooks.Open(config_fname)
return wb_config
def FileClose(wb_config): #close both data and configuration files
app = w32c.Dispatch("Excel.Application")
app.Visible=True
app.Interactive = True
wb_config = None
app = None
w32c.pythoncom.CoUninitialize()
print w32c.pythoncom._GetInterfaceCount()
def SA_Setting(mode, sa):
print "%s SA_Setting" %mode
sa.write("inst edgegsm")
sa.write("rad:dev ms")
sa.write("rad:carr burs")
sa.write("init:cont on")
sa.write("conf:%s" %mode)
sa.write("%s:trig:sour ext" %mode)
if mode == "orfs" or mode == "eorf":
if mode == "eorf":
sa.write("rad:carr burs")
sa.write("%s:list:sel shor" %mode)
sa.write("%s:aver:fast off" %mode)
sa.write("%s:aver on" %mode)
sa.write("%s:aver:coun 100" %mode)
sa.write("SENSe:%s:LIST:MOD:FREQ 0.0, 4.0e5" %mode)
sa.write("eorf:list:sel cust")
elif mode == "eevm":
sa.write("rad:carr burs")
sa.write("eevm:bsyn:sour tseq")
sa.write("eevm:ferr:tran wide")
sa.write("eevm:aver on")
sa.write("eevm:aver:coun 100")
sa.write("eevm:aver:type mean")
elif mode == "pfer":
sa.write("pfer:bsyn:sour tseq")
sa.write("pfer:aver on")
sa.write("pfer:aver:coun 100")
sa.write("pfer:aver:type mean")
else:
sa.write("%s:aver on" %mode)
sa.write("%s:aver:coun 100" %mode)
sa.timeout = 40
sa.write("SYNC:BURS:STHR -40")
return
def Tx8PskEVM (ch,sh, i):
SA_Setting("eevm", sa)
sa.write("RAD:CARR BURS")
sa.write("SYNC:BURS:STHR -40")
sa.timeout = 40
sa.write("freq:cent %f MHz" %float(ch))
#sa.write("init:cont off")
sleep(5)
data2 = sa.ask("read:eevm1?")
sleep(1)
data2 = data2.split(',')
sleep(1)
writeToCell(sh,i,4,round (float(data2[0]),2))
writeToCell(sh,i,5,round (float(data2[1]),2))
writeToCell(sh,i,6,round (float(data2[2]),2))
writeToCell(sh,i,7,round (float(data2[3]),2))
writeToCell(sh,i,8,round (float(data2[4]),2))
def TxGmskPhaseError (ch,sh, i):
SA_Setting("pfer", sa)
sa.write("RAD:CARR BURS")
sa.timeout = 40
sa.write("freq:cent %f MHz" %float(ch))
sa.write("pfer:aver:type max")
#sa.write("init:cont off")
sleep(5)
data2 = sa.ask("read:pfer1?")
sleep(1)
data2 = data2.split(',')
sleep(1)
writeToCell(sh,i,4,round (float(data2[0]),2))
writeToCell(sh,i,5,round (float(data2[1]),2))
def Tx8PskModMask(ch,sh, i) :
SA_Setting("eorf", sa)
sa.write("RAD:CARR BURS")
sa.write("SYNC:BURS:STHR -40")
sa.timeout = 40
sa.write("freq:cent %f MHz" %float(ch))
#sa.write("init:cont off")
sleep(5)
data2 = sa.ask("read:eorf1?")
sleep(1)
data2 = data2.split(',')
sleep(1)
# writeToCell(sh,i,2,round (float(data2[12]),2))
# writeToCell(sh,i,3,round (float(data2[14]),2))
writeToCell(sh,i,2,round (float(data2[4]),2))
writeToCell(sh,i,3,round (float(data2[6]),2))
def TxGmskModMask(ch,sh, i) :
SA_Setting("orfs", sa)
sa.write("RAD:CARR BURS")
sa.timeout = 40
sa.write("freq:cent %f MHz" %float(ch))
#sa.write("init:cont off")
sleep(5)
data2 = sa.ask("read:orfs1?")
sleep(1)
data2 = data2.split(',')
sleep(1)
# writeToCell(sh,i,2,round (float(data2[12]),2))
# writeToCell(sh,i,3,round (float(data2[14]),2))
writeToCell(sh,i,2,round (float(data2[4]),2))
writeToCell(sh,i,3,round (float(data2[6]),2))
def Tx8PskSpec(ch):
SA_Setting("spec",sa)
sa.write("RAD:CARR BURS")
sa.write("SYNC:BURS:STHR -40")
sa.timeout = 40
sa.write("freq:cent %f MHz" %float(ch))
sleep(5)
data2 = (sa.ask("read:spec7?")).split(',')
sleep(1)
return float(data2[137])
def RCCALTEST (ch):
SetSwitch(ch)
e.burstPsk(ch, 0x68)
fname = "Y:\\AlanWang\\AutoTests\\AutoTest_Tx\\2G\\Zeus\\AutoTest\\opt.xls"
wb = ConfigFileOpen(fname)
sh = wb.Sheets("RCCAL")
for i in range(2,20):
sa.write("*rst")
value_to_poke = float(readFromCell(sh,i,1)) + 32
while (e.peek(0x8)%64) != value_to_poke:
e.rfstDown()
sleep (0.5)
e.poke(0x8, value_to_poke)
e.rfstUp()
sleep (0.5)
Tx8PskModMask(ch, sh, i)
Tx8PskEVM(ch,sh, i)
sh = None
FileClose(wb)
def LOTEST (ch, padr=0x68):
SetSwitch(ch)
e.burstPsk(ch, padr)
fname = "Y:\\AlanWang\\AutoTests\\AutoTest_Tx\\2G\\Zeus\\AutoTest\\opt.xls"
wb = ConfigFileOpen(fname)
print "test"
sh = wb.Sheets("LO")
for i in range(2,20):
sa.write("*rst")
value_to_poke = float(readFromCell(sh,i,1))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -