泰克应用工程师。在
这里的问题是API版本不匹配。您的代码引用的是旧版本的API(RSA300API.dll)错误消息引用的是API(RSA)的更新版本_API.dll). 请确保已安装最新版本的API,并且在代码中引用了正确的dll。在
下面是下载API文档的链接(截至2016年11月1日)。本文件附有Excel电子表格,其中概述了旧函数和新函数之间的区别:
http://www.tek.com/spectrum-analyzer/rsa306-manual-6
为了清晰和一致,在新版本中使用更改了函数名。旧版本的API没有大多数函数的前缀,仅仅从读取函数名就不清楚哪些函数被组合在一起。新版本的API将前缀应用于所有函数,现在只需阅读函数的声明就可以更容易地判断给定函数属于哪个函数组。例如,旧的search和connect函数被简单地称为search()和connect(),而新版本的函数称为DEVICE_search()和DEVICE_connect()。在
注:我使用cdll.LoadLibrary(“RSA_API.dll)来加载dll而不是WinDLL()。在
DEVICE\u Search()的参数与Search()略有不同。由于参数数据类型不同,新的DEVICE_Search()函数在处理ctypes时不如旧的Search()函数好,但我找到了一个可以工作的方法(请参阅下面的代码)。在
下面是我在RSA控制脚本开始时使用的search_connect()函数:from ctypes import *
import os
"""
################################################################
C:\Tektronix\RSA306 API\lib\x64 needs to be added to the
PATH system environment variable
################################################################
"""
os.chdir("C:\\Tektronix\\RSA_API\\lib\\x64")
rsa = cdll.LoadLibrary("RSA_API.dll")
"""#################CLASSES AND FUNCTIONS#################"""
def search_connect():
#search/connect variables
numFound = c_int(0)
intArray = c_int*10
deviceIDs = intArray()
#this is absolutely asinine, but it works
deviceSerial = c_char_p('longer than the longest serial number')
deviceType = c_char_p('longer than the longest device type')
apiVersion = c_char_p('api')
#get API version
rsa.DEVICE_GetAPIVersion(apiVersion)
print('API Version {}'.format(apiVersion.value))
#search
ret = rsa.DEVICE_Search(byref(numFound), deviceIDs,
deviceSerial, deviceType)
if ret != 0:
print('Error in Search: ' + str(ret))
exit()
if numFound.value < 1:
print('No instruments found. Exiting script.')
exit()
elif numFound.value == 1:
print('One device found.')
print('Device type: {}'.format(deviceType.value))
print('Device serial number: {}'.format(deviceSerial.value))
ret = rsa.DEVICE_Connect(deviceIDs[0])
if ret != 0:
print('Error in Connect: ' + str(ret))
exit()
else:
print('Unexpected number of devices found, exiting script.')
exit()