原来文章的格式有问题,故进行修改。
在搭建好软件环境后(安装了NI-VISA,pyvisa,pip,python2.7后),用python2.7写命令控制波形发生器。
在官网上找到的参考代码如下:(官网上是射频信号发生器)
#__author__ = 'sn01309'
#coding=utf-8
if __name__ == '__main__' :
import visa;
rm = visa.ResourceManager();
# reslist = rm.list_resources();
inst = rm.open_resource('USB0::0x1AB1::0x099C::DSG8A170200001::INSTR');
inst.write("*IDN?");
print(inst.read());
inst.write(":SOURce:FREQuency 1GHz");#设置频率
inst.write(":SOURce:LEVel -10dBm");#设置幅度
inst.write(":OUTPut:STATe ON");#打开RF开关
rm.close();
发现出现问题:
Traceback (most recent call last):
File "
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1488, in __new_
_
visa_library = open_visa_library(visa_library)
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 1460, in open_v
isa_library
return cls(argument)
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 96, in __new__
raise OSError('Could not open VISA library:\n' + '\n'.join(errs))
OSError: Could not open VISA library:
百度,,只有英文网站,,更绝望了。
参考: http://stackoverflow.com/questions/35544482/oserror-could-not-open-visa-library
没想到就好了!!!!!!神奇。
只要把visa32.dll的路径加上,
rm = visa.ResourceManager("C:/Windows/System32/visa32.dll");
改完的代码如下:
成功!!波形发生器自动显示1234hz!!!太神奇了,,后面继续调,看能不能扫个频,或者能把示波器的结果显示。。。。
import visa;
rm = visa.ResourceManager("C:/Windows/System32/visa32.dll");
inst = rm.open_resource('USB0::0x1AB1::0x0641::DG4E172301638::INSTR');
inst.write("*IDN?");
print(inst.read());
inst.write(":SOURce:FREQuency 1234Hz");#设置频率
rm.close()