gpt4 book ai didi

python - PyVISA-无法使GPIB仪器以编程方式进入REMOTE模式

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:40 32 4
gpt4 key购买 nike

我正在PyCharm Community Edition 2016.1.4上运行带有pyvisa 1.8的Python 3.5.1。

下面列出了“ python -m Visa info”的结果。

尝试使用Keysight 34420A纳伏表进行测量时,我遇到了一个奇怪的问题。

我正在使用National Instruments GPIB-US-HS +电缆与34420A通信。 34420A是GPIB地址22,我已经从前面板进行了验证。

我得到的错误是:
pyvisa.errors.VisaIOError:VI_ERROR_TMO(-1073807339):在操作完成之前超时已过期。

读取34420的内部错误寄存器,我发现:
错误1:550
错误2:-420

这是仅保存的两个错误。

根据34420A手册:

错误550是“本地不允许命令
仪表收到读数?在本地模式下用于RS-232操作的命令。在通过接口发送其他命令之前,应始终执行SYSTem:REMote命令。”

错误-420为“查询未终止
仪表已寻址以进行通话(即通过接口发送数据),但尚未收到将数据发送到输出缓冲区的命令。例如,您可能已经执行了CONFigure命令(该命令不生成数据),然后尝试使用ENTER语句从远程接口读取数据”

编辑:当我尝试发送错误550消息中提到的SYSTem:REMote命令时,我得到:错误514“仅RS-232允许使用的命令:只有RS-232接口允许使用三个命令:SYSTem:LOCal ,SYSTem:REMote和SYSTem:RWLock”如标题中所述,我正在使用GPIB。另外,如本文稍后所述,当我查询接口类型时,它将返回字符串“ HPIB”,这是GPIB的原始名称。我不知道为什么在使用GPIB时会出现RS-232错误,但是如果我不得不猜测,那是从RS-232是唯一的解决方法开始的错误消息。与仪器进行通信,并且在引入HPIB / GPIB之后从未更新错误消息。

错误550和错误-420的根本原因似乎是34420A需要处于“远程”模式才能进行测量。我的问题是我不知道如何以编程方式将34420A置于“远程”模式。

通过阅读PyVISA文档,我认为我需要使用control_ren()方法,但是我不知道如何使它工作。

编辑:我读过堆栈溢出帖子pyVISA: Return instrument to local mode programmatically。那是我最初指向control_ren()的指针。但是,正如我提到的,我不知道如何使它工作。

我当前的变通方法是偶然地或多或少地发现的,它是启动NI-MAX,选择34420A,然后打开VISA测试面板。完成此操作后,34420A上的REMOTE指示灯会亮起,并且可以进行测量。请注意,我不必向34420A发送命令。我只需要打开NI-MAX的VISA测试面板即可。

这是“ python -m签证信息”的结果:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

H:\>python -m visa info
Machine Details:
Platform ID: Windows-7-6.1.7601-SP1
Processor: AMD64 Family 21 Model 48 Stepping 1, AuthenticAMD

Python:
Implementation: CPython
Executable: C:\Anaconda3\python.exe
Version: 3.5.1
Compiler: MSC v.1900 64 bit (AMD64)
Bits: 64bit
Build: Feb 16 2016 09:49:46 (#default)
Unicode: UCS4

PyVISA Version: 1.8

Backends:
ni:
Version: 1.8 (bundled with PyVISA)
#1: C:\Windows\system32\visa32.dll:
found by: auto
bitness: 64
Vendor: Agilent Technologies
Impl. Version: 1345598497
Spec. Version: 5243136
#2: C:\Windows\system32\visa32.dll:
found by: auto
bitness: 64
Vendor: Agilent Technologies
Impl. Version: 1345598497
Spec. Version: 5243136


值得一提的是,在打开VISA测试面板后,“ python -m Visa info”的结果似乎没有改变。

这是演示该问题的示例程序,我从Keysight网站上的演示程序改编而成。请注意,我能够与34420A通信。除其他外,我可以读取34420A的ID字符串并确定接口类型(它是HPIB,BTW-HPIB是GPIB的原始名称);我只是无法使仪器进入“远程”模式。

# -*- coding: utf-8 -*-
# Python for Test and Measurement

# Example programs avaialable at 'ftp://ftp.keysight.com/callpub6/callpub6/MISC/Keysight_Python'
#
# Requires VISA installed on Control PC
# 'http://www.agilent.com/find/visa'
# Requires PyVISA to use VISA in Python
# 'http://pyvisa.sourceforge.net/pyvisa/'

# Keysight IO Libraries 17.1.19xxx
# Anaconda Python 2.7.7 32 bit
# pyvisa 1.6.3

##"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
## Copyright © 2015 Agilent Technologies Inc. All rights reserved.
##
## You have a royalty-free right to use, modify, reproduce and distribute this
## example files (and/or any modified version) in any way you find useful, provided
## that you agree that Agilent has no warranty, obligations or liability for any
## Sample Application Files.
##
##"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

# Example Description:
# Basic Example which connects to instrument and queries instrument ID.

# Required Instrument Setup to Execute Example:
# Any instrument connected via GPIB/USB/LAN

# Additional Information:

# import python modules
import visa
import pyvisa
import pyvisa.resources
import pyvisa.constants


try:
# Open Connection

# Try two different ways of opening a resource manager, to see if either works.
# rm = visa.ResourceManager('C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\agvisa\\agbin\\visa32.dll')
rm = pyvisa.ResourceManager()

# Connect to VISA Address
# LAN - VXI-11 Connection: 'TCPIP0::xxx.xxx.xxx.xxx::inst0::INSTR'
# LAN - HiSLIP Connection: 'TCPIP0::xxx.xxx.xxx.xxx::hislip0::INSTR'
# USB Connection: 'USB0::xxxxxx::xxxxxx::xxxxxxxxxx::0::INSTR'
# GPIB Connection: 'GPIP0::xx::INSTR'
# myinst = rm.open_resource("TCPIP0::K-E4990A-00892::inst0::INSTR")
myinst = rm.open_resource("GPIB0::22::INSTR") # Keysight 34420A Nanovoltmeter

# Set Timeout - 5 seconds
myinst.timeout = 5000

# *IDN? - Query Instrumnet ID
myinst.write("*CLS")
myinst.write("*IDN?")
print(myinst.read())

myinst.write("SYStem:INTerface?")
print(myinst.read())

# myinst.write("SYStem:REMote") # This is an RS232-only command

# From: https://pyvisa.readthedocs.io/en/stable/_modules/pyvisa/constants.html
gpib_ren_assert = pyvisa.constants.VI_GPIB_REN_ASSERT
gpib_ren_assert_address = pyvisa.constants.VI_GPIB_REN_ASSERT_ADDRESS
gpib_ren_assert_llo = pyvisa.constants.VI_GPIB_REN_ASSERT_LLO
gpib_ren_assert_address_llo = pyvisa.constants.VI_GPIB_REN_ASSERT_ADDRESS_LLO

# Per https://pyvisa.readthedocs.io/en/stable/api/resources.html#pyvisa.resources.GPIBInstrument.control_ren
# "Controls the state of the GPIB Remote Enable (REN) interface line, and optionally the remote/local state
# of the device."
control_ren_return = myinst.control_ren(gpib_ren_assert_address)
print("The value returned from myinst.control_ren(gpib_ren_assert_address) is: %s" % control_ren_return)

control_ren_return = myinst.control_ren(gpib_ren_assert_address_llo)
print("The value returned from myinst.control_ren(gpib_ren_assert_address_llo) is: %s" % control_ren_return)

control_ren_return = myinst.control_ren(gpib_ren_assert)
print("The value returned from myinst.control_ren(gpib_ren_assert) is: %s" % control_ren_return)

control_ren_return = myinst.control_ren(gpib_ren_assert_llo)
print("The value returned from myinst.control_ren(gpib_ren_assert_llo) is: %s" % control_ren_return)

# https://pyvisa.readthedocs.io/en/latest/api/resources.html#pyvisa.resources.GPIBInstrument says:
# "Do not instantiate directly, use pyvisa.highlevel.ResourceManager.open_resource()."
# gpib_control_ren_return = pyvisa.resources.GPIBInstrument.control_ren(1)
# print("The value returned from pyvisa.resources.GPIBInstrument.control_ren(1) is %s" % gpib_control_ren_return)

# =======================================================================================================
# Uncommenting the next line causes the error:
# pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
# apparently because the instrument is not in REMOTE mode first.
# =======================================================================================================
# myinst.write("MEAS:VOLT:DC?")
# print(myinst.read())

# Close Connection
myinst.close()
print('close instrument connection')

except Exception as err:
print('Exception: ' + str(err.message))

finally:
# perform clean up operations
print('complete')


如前所述,我认为我需要使用“ control_ren()”方法,但我不知道该怎么做。

编辑:如果我的GPIB仪器处于REMOTE模式(通过使用我的NI-MAX / VISA测试面板),那么我可以发送“ control_ren(2)”或“ control_ren(6)”以将仪器置于本地模式。那么,为什么不能使用control_ren()将仪器置于REMOTE模式?


使用“ control_ren(6)”将仪器置于本地模式的基本思想来自 pyVISA: Return instrument to local mode programmatically
值2对应于pyvisa.constants.VI_GPIB_REN_DEASSERT_GTL
值6对应于pyvisa.constants.VI_GPIB_REN_ADDRESS_GTL
GTL =转到本地

最佳答案

回答我自己的问题可能有点不好,但是我想发布我找到的解决方案,以防其他人在尝试解决自己的类似问题时偶然发现该问题。

长话短说,根本原因似乎是NI GPIB-USB-HS +电缆的连接问题。 34420A在GPIB接口的一侧缺少螺丝适配器,因此我们只能在另一侧拧紧GPIB连接器。当我从另一台仪器上拆下了一个螺丝适配器并将其插入34420A时,我们可以将GPIB连接器的两侧拧紧,问题就消失了。

我们认为将GPIB连接器紧紧按在一侧并拧紧就足够了。显然,我们错了。

关于python - PyVISA-无法使GPIB仪器以编程方式进入REMOTE模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56543309/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com