NI Home > Community > NI Discussion Forums

Instrument Control (GPIB, Serial, VISA, IVI)

Reply
Member
neox
Posts: 4
0 Kudos

PyVISA - Keythley 2000 M

Hi!
A few days ago, I installed PyVISA  (Ubuntu Linux) and the required libvisa.so.7 along with the linux-gpib packages.
I'm 100% sure that the NI GPIB-USB-HS is detected by the system and responsive.
However, as I wrote my first program in python

*listing*

1 from visa import instrument
2 my_instrument = instrument ("GPIB:00:INSTR")

*listing ends*

I got the errors listed below:

Traceback (most recent call last):
  File "testvisa.py", line 3, in ?
    my_instrument = instrument("GPIB0::00::INSTR")
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 279, in instrument
    return Instrument(resource_name, **keyw)
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 351, in __init__
    raise ValueError, "given resource was not an INSTR but %s" \
ValueError: given resource was not an INSTR but

Thanx,
Razvan

P.S. I realize that this is not a forum for python programmers. It's just that I couldn't find any useful information on other forums.
Active Participant
Chris_R.
Posts: 408
0 Kudos

Re: PyVISA - Keythley 2000 M

Hi Razvan,

I am not familiar with PyVISA or that distribution of Linux, but I did notice a couple things that we can try.  First, "GPIB:00:INSTR" is not a valid resource descriptor for NI-VISA, and other VISA's as well.  Typically, the format is GPIB0::2::INSTR, where "2" is the address of the instrument and "GPIB0" is the GPIB card 1.  Unless PyVISA is converting this format, then this may be the problem.

Also, in blue, you have "GPIB0::00::INSTR".  This is more like what format VISA requires, but an instrument with a primary address of 0 typically does not exist since most of the time, the controller has an address of 0.  You may want to check your instrument to see what the address is and change it if the controller has the same address.

I hope this helps, but let me know if you have any other questions!

Chris R.
Applications Engineer
National Instruments
Member
neox
Posts: 4
0 Kudos

Re: PyVISA - Keythley 2000 M

So I set the instrument address to 10 and made the appropriate modifications in the source file.
Unfortunately, the result was no different than the one before.

Source code:

from visa import instrument
keithley = instrument("GPIB0::10")
keithley.write("*rst; status:smileytongue:reset; *cls")

Result:

razvan@Area52:~$ python2.4 keithley.py
Traceback (most recent call last):
  File "keithley.py", line 2, in ?
    keithley = instrument("GPIB0::10")
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 279, in instrument
    return Instrument(resource_name, **keyw)
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 351, in __init__
    raise ValueError, "given resource was not an INSTR but %s" \
ValueError: given resource was not an INSTR but

Active Participant
Chris_R.
Posts: 408
0 Kudos

Re: PyVISA - Keythley 2000 M

Hi Razvan,

Is the GPIB-USB-HS recognized by the computer?  Also, are you sure this instrument is in working order?  Has this setup worked before on this computer?

Chris R.
Applications Engineer
National Instruments
Member
neox
Posts: 4
0 Kudos

Re: PyVISA - Keythley 2000 M

Everything reads fine. After the ni_usb_gpib module is sucessfully loaded in the kernel, I can use a terminal-like program (ibtest) to bring the instrument in remote mode. Actually, when I plug the interface into the usb I get this message (which proves that everything's OK):

[17181165.456000] ni_usb_gpib: probe succeeded for path: usb-0000:00:1d.7-1
[17181166.880000] gpib: (debug) request module returned 256
[17181166.880000] ni_usb_gpib: attach
[17181166.880000]       attached to bus interface 0, address 0xdfe34600
[17181166.888000]       product id=0x709b
[17181166.888000] ni_usb_hs_wait_for_ready: board serial number is 0x121b456
[17181166.888000] /opt/linux-gpib-3.2.08/drivers/gpib/ni_usb/ni_usb_gpib.c: ni_usb_hs_wait_for_ready: unexpected data: buffer[7]=0x4, expected 0x3
[17181166.888000] /opt/linux-gpib-3.2.08/drivers/gpib/ni_usb/ni_usb_gpib.c: ni_usb_hs_wait_for_ready: unexpected data: buffer[10]=0x3, expected 0x96
[17181166.888000] ni_usb_dump_raw_block:
[17181166.888000]  40  1  0  1 30  1  2  4
[17181166.888000]   0  0  3


Active Participant
Chris_R.
Posts: 408
0 Kudos

Re: PyVISA - Keythley 2000 M

Have you tried using "GPIB0::10::INSTR" as your resource descriptor?  It seems you didn't use the "INSTR" in the code you posted.  Try this and see if that helps.
Chris R.
Applications Engineer
National Instruments
Member
neox
Posts: 4
0 Kudos

Re: PyVISA - Keythley 2000 M

That did not help, either.

Here's the outcome:
razvan@Area52:~$ sudo python2.4 keithley.py
Traceback (most recent call last):
  File "keithley.py", line 2, in ?
    keithley = instrument("GPIB0::10::INSTR")
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 279, in instrument
    return Instrument(resource_name, **keyw)
  File "/usr/lib/python2.4/site-packages/pyvisa/visa.py", line 351, in __init__
    raise ValueError, "given resource was not an INSTR but %s" \
ValueError: given resource was not an INSTR but

Active Participant
Chris_R.
Posts: 408
0 Kudos

Re: PyVISA - Keythley 2000 M

Hi Razvan,

Have you installed NI-VISA successfully?  Since the PyVISA package doesn't have the low-level VISA commands, you will need to install a full version of VISA if you haven't already.  Since you have purchased a GPIB-USB-HS, you do not have to purchase it separately.  You can download it here if you need it.  Ubuntu is not a supported distribution for NI drivers, so it may not install properly on your system. 

I hope this helps!  I am sorry for my limited resources for you, but will send you what I can even though National Instruments does not support PyVISA or Ubuntu.

Have a great day!

Chris R.
Applications Engineer
National Instruments
Member TPK
Member
TPK
Posts: 2
0 Kudos

Re: PyVISA - Keythley 2000 M

I am using Windows XP and have installed NI-VISA. Iam using pyvisa.I have 2 GPIB equipments. CMU200 and SMU200. The SMU 200 doesnt have a secondary address. But the CMU200 has around 8to 10 secondary address.when using

equip=visa.instrument(GPIB::28) ----works normally. (28 is the primary address of the SMU200)

but when using  

equip=visa.instrument(GPIB::13)  ---- doesn't work. throws the following  exception. 

 

>>> equip1=visa.instrument("GPIB0::13")

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "c:\python26\lib\site-packages\pyvisa\visa.py", line 290, in instrument  

    return GpibInstrument(resource_name, **keyw)

  File "c:\python26\lib\site-packages\pyvisa\visa.py", line 594, in __init__ 

    Instrument.__init__(self, resource_name, **keyw)

  File "c:\python26\lib\site-packages\pyvisa\visa.py", line 358, in __init__

    "lock")))

  File "c:\python26\lib\site-packages\pyvisa\visa.py", line 152, in __init__

    vpp43.clear(self.vi)

  File "c:\python26\lib\site-packages\pyvisa\vpp43.py", line 557, in clear

    visa_library().viClear(vi)

  File "c:\python26\lib\site-packages\pyvisa\vpp43.py", line 398, in check_status

    raise visa_exceptions.VisaIOError, status

pyvisa.visa_exceptions.VisaIOError: VI_ERROR_NLISTENERS: No listeners condition

is detected (both NRFD and NDAC are deasserted). 

 

I believe I need to specify the secondary address  also.. But i don know how to do that in pyvisa. Or if its something else kindly guide me through this .

 

Regards

Prasanna

 

Member TPK
Member
TPK
Posts: 2
0 Kudos

Re: PyVISA - Keythley 2000 M

Hello,

I actually figured it out. The format for specifying the secondary address is the same as i had mentioned.

equip=visa.instrument("GPIB::13::98") with primary add-13 and sec add-98 provided the secondary address is specified on the instrument connected.  If the secondary address is not specified, then the default sec add is 0 so we need to specify it like

equip=visa.instrument("GPIB::13::0")

 

Cheers

Prasanna