VI_ERROR_TMO(-1073807339):在操作完成之前超时已过期

时间:2019-06-17 14:45:31

标签: python visa pyvisa

我尝试将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],但我不知道什么是正确的语法。

我检查了设备手册: https://scdn.rohde-schwarz.com/ur/pws/dl_downloads/dl_common_library/dl_manuals/gb_1/h/hmc80115/HMC8015_SCPImanual_en_01.pdf

,但是似乎没有任何效果,对于Python VISA也没有任何明确的解释,我对此没有任何经验。有人知道如何解决该问题吗?

1 个答案:

答案 0 :(得分:1)

在对(新)VISA仪器的连接问题进行故障排除时,我通常会执行以下操作:

  • 确保已正确连接。就像在Windows上一样,显示在设备管理器中。在NI-MAX中-提供了安装的National Instruments的VISA框架。
  • 确保其VISA地址(或其有根据的猜测)显示在VISA资源管理器返回的列表中:rm.list_resources()在您的代码中。
  • 使用给出的显式VISA地址打开资源:类似于代码中的rm.open_resource('ASRL3::INSTR')
  • 默认保留资源配置。
  • 如果API基于SCPI,则发送最基本的命令,例如*IDN?

仅当失败时,我才配置特定的通信设置,例如.write_termination.read_termination.timeout。通常会发生100毫秒的超时。只是为了确定而已。

在代码中,您从一开始就将.values_format.is_binary设置为True。但是随后您.query_ascii_values。看到 not 失败,我会感到非常惊讶。显然,每种乐器都是不同的。尽管快速浏览了一下手册,但我没有看到任何迹象表明您的乐器实际上是。

我的建议:从默认的通信设置开始,尝试获得对*IDN?命令的响应,然后从那里获取它。