我在PyCharm Community 2016.1.4上使用PyVisa1.8运行Python3.5.1。
下面列出了"python -m visa信息“的结果。
我遇到了一个奇怪的问题,当我尝试用Keysight 34420 A纳米伏特计进行测量时。
我正在使用国家仪器GPIB-US-HS+电缆与34420 A通信。34420A是一个GPIB地址22,这是我已经从前面板验证。
我得到的错误是: pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339):超时在操作完成前过期。
阅读34420的内部错误寄存器,我发现:错误1: 550错误2:-420。
这是唯一保存的两个错误。
根据34420 A手册:
错误550是“命令在本地不允许,仪表在本地模式下接收读取命令,用于RS-232操作。在通过接口发送其他命令之前,应始终执行系统:远程命令”。
Error -420是“查询UNTERMINATED该表被寻址用于交谈(即通过接口发送数据),但是没有接收到将数据发送到输出缓冲区的命令。例如,您可能执行了一个CONFigure命令(该命令不生成数据),然后尝试使用ENTER语句从远程接口读取数据”。
编辑:当我尝试发送错误550消息中提到的SYSTem:REMote命令时,我得到: ERROR 514“命令只允许使用RS-232:有三个命令只能在RS-232接口上允许: SYSTem:LOCal,SYSTem:REMote,和SYSTem:RWLock”,正如标题中提到的,我正在使用GPIB。另外,正如本文后面提到的,当我查询接口类型时,它返回字符串"HPIB",这是GPIB的原始名称。我不知道为什么当我使用GPIB的时候,我得到的是一个RS-232错误,但是如果我不得不猜测的话,错误消息是从RS-232是唯一的与仪器通信的方式开始的,在HPIB/GPIB被引入之后,错误消息从未被更新过。
错误550和错误420的根本原因似乎是,344 20a需要处于远程模式才能进行测量。我的问题是,我不知道如何以编程方式将34420A放到远程模式中。
从我对PyVISA文档的阅读中,我认为我需要使用control_ren()方法,但是我不知道如何使它工作。
编辑:我读过堆栈溢出帖子pyVISA: Return instrument to local mode programmatically。这是我指向control_ren()的原始指针。然而,正如我所提到的,我不知道如何让它开始工作。
我目前的工作,或多或少是偶然发现的,就是启动NI-MAX,选择344 20A,打开签证测试面板。当我这样做的时候,34420 A上的遥控器打开了,我可以测量。请注意,我不必向34420 A发送命令。我只需要让NI-MAX的签证测试小组打开。
以下是"python -m visa信息“的结果:
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不管它的价值是什么,"python -m签证信息“的结果在我打开签证测试面板后似乎不会改变。
这里有一个演示问题的示例程序,我从Keysight网站上的一个演示程序中进行了调整。请注意,我能够与34420 A通信。除其他外,我可以读取34420A的ID字符串并确定接口类型(它是HPIB,BTW是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仪器处于远程模式(通过使用我的NI-MAX / VISA测试面板),那么我可以发送"control_ren(2)“或"control_ren(6)”将仪器放到本地模式。那么,为什么我不能使用control_ren()将仪器放到远程模式中呢?
发布于 2019-07-03 13:59:51
回答我自己的问题可能有点糟糕,但我想贴出我找到的解决方案,以防其他人在试图解决自己的类似问题时遇到这个问题。
长话短说,根本原因似乎是与国家仪器GPIB-USB-HS+电缆的连接问题。34420A缺少一个螺丝钉适配器在GPIB接口的一边,所以我们只能螺丝紧固在另一边的GPIB连接器。当我从另一个仪器中取出一个螺丝钉适配器并将它插入到344 20A中时,我们就可以将GPIB连接器紧紧地固定在两边,问题就解决了。
我们认为把GPIB连接器紧紧地压在一边,这样就足够了。很明显我们错了。
https://stackoverflow.com/questions/56543309
复制相似问题