From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIB-USB-HS and pyvisa

I am trying to use pyvisa 1.0, python 2.5 with GPIB-USB-HS (http://sine.ni.com/nips/cds/view/p/lang/en/nid/201586). 
Python and pyvisa is all native windows application (not cygwin). I am able to get a serial port resource just
fine (which shows that my application installed fine), but I am not able to connect to the GPIB device.
and I can talk to it using the National Instrumant tools (which refer to the device as UD0).
Here is the error message that I get...If you have any other methods or recommendation to
use this device using python, please let me know.


>>> b = Instrument("GPIB0::18")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\Lib\site-packages\pyvisa\visa.py", line 342, in __init__
"lock")))
File "C:\Python25\Lib\site-packages\pyvisa\visa.py", line 124, in __init__
keyw.get("lock", VI_NO_LOCK))
File "C:\Python25\Lib\site-packages\pyvisa\vpp43.py", line 699, in open
byref(vi))
File "C:\Python25\Lib\site-packages\pyvisa\vpp43.py", line 344, in
check_status raise visa_exceptions.VisaIOError, status
pyvisa.visa_exceptions.VisaIOError: VI_ERROR_RSRC_NFOUND: Insufficient location
information or the requested device or resource is not present in the system.
>>>
0 Kudos
Message 1 of 10
(14,428 Views)
Hi shuaib,

I believe the problem is that you are using the resource string "GPIB0::18", which should be "GPIB0::18::INSTR".  Try changing that and see how things work.

-Jason S.
0 Kudos
Message 2 of 10
(14,413 Views)
What device do you mean by 'UD0'? Are you talking about the instrument or the controller? Where exactly do you see this listing? If you are running this on a windows platform, you should have Measurement & Automation Explorer (MAX) and the controller should be listed as GPIB0 (GPIB-USB-HS) and then your instrument should be listed below it. It will list the primary address of the instrument so make sure it actually is 18. In MAX, you also have a software listing. Can you provide the version of VISA that is installed?
0 Kudos
Message 3 of 10
(14,397 Views)

I also am having a nearly identical experience. I am attempting to communicate with HP54542A using pyVISA and ni-488.2 protocal. I use the Meas.Aut.Exp (MAX) to identify my device which has the primary address of 0 but listed as INSTR. 0 at PAD 7. I can use the API commands such as *IDN? and MEAS:TVOL to identify and extract voltage measurements from the scope using the national instruments interactive controller in MAX. I simply want to build a ten line code to do the same thing=> sample the voltage many times and then save that info or display it using python pyVISA code.

 

from visa import instrument
my_instrument = instrument("GPIB0::7::INSTR")
my_instrument.write("*IDN?")
print my_instrument.read()

 

When I run this simple example from pyVISA, it gives the error "syntax error" and highlights the final line ( my_instrument.  -part only-) which seems to tell me that it is the write and read commands from ni-488 protocal that is not being understood properly. I tried changing the GPIB0:: to 0 and 7 and 14::INSTR but it did not change the response. This should work and be exceedingly trivial but I must have made some subtle error?

 

Oh. and the "UDO" refered to in the previous post is from the MAX interactive controller window after using the ibdev command and I did successfully query the identity of the device and extract voltages etc.. I just want it to work in python as well as it did in the MAX interactive controller which is activated by hitting a tab on the upper window bar of the MAX window

0 Kudos
Message 4 of 10
(12,783 Views)

I am using Python 3.3.2 and pyVISA-1.4.win32 and ni-488.2...

0 Kudos
Message 5 of 10
(12,782 Views)

iREMs3,

 

I notice that your write command does not include a '/n' or any other type of termination character. I'm not all that familiar with Python, however I think these termination characters are default in the MAX interactive controller.

Robert B
RF Product Support Engineer
National Instruments
0 Kudos
Message 6 of 10
(12,750 Views)
If you can communicate in MAX and you are getting a pyvisa syntax error, then your problem is with the python code and has nothing to do with NI hardware or software. Have you tried a python forum for help?
0 Kudos
Message 7 of 10
(12,745 Views)

You were correct. I am using python 3.3. For a reason unknown to me, pyvisa did not import with this version. I uninstalled the software and reinstalled 2.6.7 version. I found this out by typing the commands into the dos prompt line by line and using traceback errors. The python code was flawlessly implemented using this older version. I performed all the functions MAX was capable of implementing. It was clear as you pointed out that if MAX recieved the command prompts that the python implementator of the module must have been at fault (actually I was for not reading the 100 page update report on python 3.3). Thank you for the hospitality of the board. I am certain that other users of ni-hardware and software will appreciate this notification since I would have appreciated it. My laboratory colleague is also preparing LabVIEW software for the same device. Great service and company....

0 Kudos
Message 8 of 10
(12,698 Views)
hallow...
 
i have a problem on python and c script.
i try to automatic test Agilent DC power supply on python or c script,
but python and c script do not recognize "GPIB0::2::INSTR"
 
my computer plug to the power supply via NI GPIB cable
i have connection in the Agilent app ('GPIB0::2::INSTR') but not on my scripts
 
my os is win 7 64_bit
i have visa drivers
i have NI drivres, connection expert app and NI IO trace app
python 2.7 (IDLE for win 7)
pyvisa lib
 
---------------python_script--------------------------------------------------------------
ython 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import visa
>>> rm = visa.ResourceManager()
>>> rm.list_resources()
(u'ASRL1::INSTR', u'ASRL2::INSTR', u'ASRL3::INSTR', u'ASRL10::INSTR')
>>> osci = rm.open_resource('GPIB0::2::INSTR')
 
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
osci = rm.open_resource('GPIB0::2::INSTR')
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 300, in open_resource
return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
File "C:\Python27\lib\site-packages\pyvisa\ctwrapper\functions.py", line 1059, in open
library.viOpen(session, resource_name, access_mode, open_timeout, byref(out_session))
File "C:\Python27\lib\site-packages\pyvisa\highlevel.py", line 171, in _return_handler
raise errors.VisaIOError(ret_value)
VisaIOError: VI_ERROR_LIBRARY_NFOUND (-1073807202): A code library required by VISA could not be located or loaded.
>>>
-----------------------------------------------------------------------------------------------------------------------
 
 
-------------------------------------------C_script--------------------------------------------------------------------
/*idn.c
This example program queries a GPIB device for an identification string
and prints the results. Note that you must change the address. */
//#include "sicl.h"
#include <visa.h>
#include <stdio.h>
 
void main () {
 
ViSession defaultRM, vi;
char buf [256] = {0};
 
 
/* Open session to GPIB device at address 22 */
viOpenDefaultRM (&defaultRM);
printf("calling viOpen...\r\n");
viOpen (defaultRM, "GPIB::2::INSTR", VI_NULL,VI_NULL, &vi);
 
/* Initialize device */
viPrintf (vi, "*RST\n");
 
/* Send an *IDN? string to the device */
viPrintf (vi, "*IDN?");
 
/* Read results */
viScanf (vi, "%t", &buf);
 
/* Print results */
printf ("Instrument identification string: [%s]\n", &buf);
 
/* Close session */
viClose (vi);
viClose (defaultRM);
}
---------------------------------------------------------------------------------------------------------------------------
 
 
 
after compile and exequte the c file, the output :
 
Instrument identification string: []
0 Kudos
Message 9 of 10
(11,945 Views)

Hi guys,

I am trying to connect GPIB-USB-HS and pay visa. I believe the correct visa resources are not shown in my code. The reason behind my statement is that when I disconnect GPIB-USB-HS from my PC, I am still getting the same visa resources. Is there anyone who helps me with this issue?

 

 

import pyvisa as visa
inst = visa.ResourceManager()
inst.list_resources()

 

 

Thank you, 

 

 

 

0 Kudos
Message 10 of 10
(4,963 Views)