obsidian-notes/仪表通信/FSW通信.md
CSSC-WORK\murmur 3e6078442b init version
2024-04-15 11:19:57 +08:00

2.2 KiB
Raw Blame History

title updated created tags
FSW通信 2022-01-20 07:33:03Z 2022-01-08 13:18:08Z
pathon
visa
代码块

FSW谐波测试代码部分由仪表自动生成

# python script created by FSW: 24:11:2020 04:53:44
import visa
def write_command(instrument, command) :
    instrument.write(command)
    return process_system_error(instrument)
def write_query(instrument, command) :
    buffer = instrument.query(command)
    bSuccess = process_system_error(instrument)
    return bSuccess, buffer
def process_system_error(instrument) :
    bSuccess = True
    EsrErrorMask = 0x3C
    if ((get_esr(instrument) & EsrErrorMask) != 0) :
        print(instrument.query(":SYST:ERR?"))
        instrument.write("*CLS")
        bSuccess = False
    return bSuccess
def get_esr(instrument) :
    esr = instrument.query("*ESR?")
    return int(esr)
VisaResourceManager = visa.ResourceManager()
#set center freQ
fre = '200e6'
descr = '_harm_dis_meas'
#location on FSW
tar_loc = 'd:\\murmur\\'
# connect to analyzer
Analyzer = VisaResourceManager.open_resource("TCPIP::192.168.1.43::inst0::INSTR")
print(Analyzer.query("*IDN?"))
success = write_command( Analyzer, "*CLS" )
success = write_command( Analyzer, ":SYST:DISP:UPD ON" )
success = write_command( Analyzer, ":INIT:CONT OFF" )
#success = write_command( Analyzer, ":DISP:WIND:SUBW:TRAC:Y:SCAL:RLEV 10" )
success = write_command( Analyzer, ":SENS:FREQ:CENT " + fre )
success = write_command( Analyzer, ":CALC:MARK:FUNC:HARM:STAT ON" )
success = write_command( Analyzer, ":INIT:CONT ON" )
success = write_command( Analyzer, ":FORM:DEXP:DSEP POIN" )
success = write_command( Analyzer, ":FORM:DEXP:FORM CSV" )
success = write_command( Analyzer, ":FORM:DEXP:HEAD OFF" )
success = write_command( Analyzer, ":FORM:DEXP:TRAC ALL" )
#success = write_command( Analyzer, ":MMEM:STOR1:TRAC 1,'d:\\" + fre + descr +".CSV'" )
success = write_command( Analyzer, ":MMEM:STOR1:TRAC 1,'" + tar_loc + fre + descr +".CSV'" )
success = write_command( Analyzer, ":SENS:FREQ:MODE SWE" )
# back to local mode
success = write_command(Analyzer, "@LOC")
if success:
 print("Done.\r\nFile's location is {}{}{}.CSV.\r\n".format(tar_loc,fre,descr))
# cleanup
Analyzer.close()
VisaResourceManager.close()

#visa #代码块 #pathon