我尝试将Power Analyzer Rohde&Schwarz HMC8015('ASRL3 :: INSTR')连接到计算机,并读取设备可以通过python VISA显示的任何数据。我的代码行有很多问题,可以读取我的设备数据。
我的代码是:
import visa
rm = visa.ResourceManager()
name = rm.list_resources()
#using with allows to close explicitly the resource at the end of the script
with rm.open_resource('ASRL3::INSTR') as Power_Analyser:
Power_Analyser.values_format.is_binary = True
Power_Analyser.values_format.datatype = 'B'
Power_Analyser.values_format.is_big_endian = False
Power_Analyser.values_format.container = bytearray
Power_Analyser.timeout = 25000 #2,5 seconds
Power_Analyser.write_termination = '\n'
Data = Power_Analyser.query_ascii_values('P?',datatype='s')[0]
print(Data)
#write the Data to a file on my PC
PCfilePath = 'C:\\Users\\ApCha\\Documents\\Python Scripts\\a.txt'
newFile = open(PCfilePath, "wb")
newFile.write(Data)
newFile.close()
它向我显示:VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
无论超时设置多大。我猜测问题出在
Power_Analyser.query_ascii_values('P?',datatype='s')[0]
,但我不知道什么是正确的语法。
,但是似乎没有任何效果,对于Python VISA也没有任何明确的解释,我对此没有任何经验。有人知道如何解决该问题吗?
答案 0 :(得分:1)
在对(新)VISA仪器的连接问题进行故障排除时,我通常会执行以下操作:
rm.list_resources()
在您的代码中。rm.open_resource('ASRL3::INSTR')
。*IDN?
。仅当失败时,我才配置特定的通信设置,例如.write_termination
,.read_termination
和.timeout
。通常会发生100毫秒的超时。只是为了确定而已。
在代码中,您从一开始就将.values_format.is_binary
设置为True
。但是随后您.query_ascii_values
。看到 not 失败,我会感到非常惊讶。显然,每种乐器都是不同的。尽管快速浏览了一下手册,但我没有看到任何迹象表明您的乐器实际上是。
我的建议:从默认的通信设置开始,尝试获得对*IDN?
命令的响应,然后从那里获取它。