工作中经常手动控制射频切换器切换不同的通路,于是我计划自动化实现这个动作
先是在是可德科技的官网上找到了安捷伦3499的命令集,
3499的每块办卡都是是1路接2路的设计,我需要实现1分4的需求。
只能使用三块卡串联使用,实现1分4的目的。
同时写了个脚本控制它,需要安装NI的labview和CVI以及Pyvisa
代码如下:
#! /usr/bin/env python
#*****************************************************************************
#* File: RfSwitch3499.py
#* Author: Yunpeng Bai
#* Date: 01-Apr-2016
#* This script controls 3499
#*
#*****************************************************************************
#from instruments_v2 import *
import time
#import platform
#import subprocess
#import sys
#import os
import visa
class Rf3499(object):
GPIBaddress = ""
TheEquipment=None
def __init__(self,GPIBaddress = "9"):
print "access to 3499"
rm = visa.ResourceManager()
rm.list_resources()
self.TheEquipment=rm.open_resource('GPIB0::'+GPIBaddress+'::INSTR')
print self.TheEquipment.query("*IDN?")
def ToPipe(self,num):
if num == '1':
self.TheEquipment.write("close (@100,101,102)")
print "switch to Pipe1"
elif num == '2':
self.TheEquipment.write("open (@100);close (@101,102)\n")
print "switch to Pipe2"
elif num == '3':
self.TheEquipment.write("open (@101);close (@102)")
print "switch to Pipe3"
elif num == '4':
self.TheEquipment.write("open (@102)")
print "switch to Pipe4"
else:
print 'nothing done,pipe-num input is not right!!'
def checkStatus(self):
out = ""
stat1 = str(self.TheEquipment.query("ROUT:OPEN? (@100,101,102)"))
print 'stat is :',stat1,
#print type(stat1)
if stat1 == "0,0,0\n":
out = "pipe1"
elif stat1 == "1,0,0\n":
out = "pipe2"
elif stat1 == "1,1,0\n" or stat1 == "0,1,0\n":
out = "pipe3"
elif stat1.split(',')[2] == "1\n":
out = "pipe4"
else:
out = 'Undefined status:'+stat1
return out
改天把环境图附上
如果需要调用这个类来创建对象实现控制3499,调用的例子如下:
#coding:UTF-8
import time
from RfSwitch3499 import *
rfswitch = Rf3499()
time.sleep(2)
rfswitch.ToPipe('4')
time.sleep(2)
a = rfswitch.checkStatus()
print "haha",a
最后一步的功能是查询切换状态,确认切换通道确实是成功了。
确认打开时,对应通道会返回1,若没有打开,返回的对应通道的值是0.