Reputation: 467
I'm running Python 3.5.1 with pyvisa 1.8 on PyCharm Community Edition 2016.1.4.
The result of "python -m visa info" is listed below.
I'm having an odd problem when I try to take measurement with a Keysight 34420A Nanovoltmeter.
I'm communicating with the 34420A using a National Instruments GPIB-US-HS+ cable. The 34420A is a GPIB address 22, which I've verified from the front panel.
The error I'm getting is: pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
Reading the 34420's internal error register, I find: ERR 1: 550 ERR 2: -420
These are the only two errors that are saved.
According to the 34420A manual:
Error 550 is "Command not allowed in local The meter received a READ? command while in the local mode for RS-232 operation. You should always execute the SYSTem:REMote command before sending other commands over the interface."
Error -420 is "Query UNTERMINATED The meter was addressed to talk (i.e., to send data over the interface) but a command has not been received which sends data to the output buffer. For example, you may have executed a CONFigure command (which does not generate data) and then attempted an ENTER statement to read data from the remote interface"
EDIT: When I try sending the SYSTem:REMote command mentioned in the ERROR 550 message, I get: ERROR 514 "Command allowed only with RS-232: There are three commands which are only allowed with the RS-232 interface: SYSTem:LOCal, SYSTem:REMote, and SYSTem:RWLock" As mentioned in the title, I'm using GPIB. Also, as mentioned later in this post, when I query the interface type, it return the string "HPIB", which is the original name for GPIB. I don't know why I'm getting what appears to be an RS-232 error when I'm using GPIB but if I had to guess, it would be that the error message dates from when RS-232 was the only means of communicating with instruments and the error message was never updated after HPIB/GPIB was introduced.
The root cause of the ERROR 550 and ERROR -420 appears to be that the 34420A needs to be in REMOTE mode to take a measurement. My problem is I can't figure out how to put the 34420A into REMOTE mode programmatically.
From my reading of the PyVISA documentation, I think I need to use the control_ren() method but I can't figure out how to make that work.
EDIT: I've read the Stack Overflow post pyVISA: Return instrument to local mode programmatically. That was my original pointer to control_ren(). However, as I mentioned, I can't figure out how to get it to work.
My current work-around, which I discovered more-or-less by chance, is to start NI-MAX, select the 34420A, and open the VISA test panel. When I do this, the REMOTE indicator on the 34420A turns on and I'm able to take measurements. Note that I don't have to send a command to the 34420A. I just have to have NI-MAX's VISA test panel open.
Here is the result of "python -m visa info":
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
For what it's worth, the result of "python -m visa info" doesn't appear to change after I open the VISA test panel.
Here's a sample program demonstrating the problem, which I've adapted from a demo program on the Keysight website. Note that I'm able to communicate with the 34420A. Among other things, I can read the 34420A's ID string and determine the interface type (it's HPIB, BTW - HPIB was the original name for GPIB); I just can't get the instrument into REMOTE mode.
# -*- 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')
As I mentioned, I think I need to use the "control_ren()" method but I can't figure out how.
EDIT: If my GPIB instrument is in REMOTE mode (by using my NI-MAX / VISA Test Panel kludge), then I can send "control_ren(2)" or "control_ren(6)" to put the instrument into local mode. So why can't I use control_ren() to put the instrument into REMOTE mode?
Upvotes: 1
Views: 2110
Reputation: 467
It may be somewhat bad form to answer my own question but I wanted to post the solution I found in case anyone else stumbles across this question while trying to solve their own similar problem.
Long story short, the root cause appears be a connection problem with the National Instruments GPIB-USB-HS+ cable. The 34420A was missing an screw adapter on one side of the GPIB interface, so we could only screw the GPIB connector tight on the other side. When I cannibalized a screw adapter from another instrument and inserted it into the 34420A, so we COULD screw the GPIB connector down tight on both sides, the problem went away.
We thought having the GPIB connector pressed on tightly and screwed down on one side was good enough. Obviously, we were wrong.
Upvotes: 1