Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Question on getting a Device Handle

Hi All
I am trying the following function to get a device handle from an instrument on the bus.

When I try to get the device handle for the same instrument in a loop.
I get the device handles for some time and thereafter I get a
negative number as the device handle.

Some times I get a negative number in the first loop.

Can anyone help why?
I am using windows XP/ MI-488.2 version 2.52 Controller & Analyzer Software

Code
-------
Public Function getDeviceHandle(ByRef iGPIBAddr As Integer, _
                                ByRef iDHandle As Integer) As Boolean
    Dim iListen     As Integer  'boolean integer if device was found on the bus

    'check if device is on the bus
    Call VBIB32.ibln(0, 13, NO_SAD, iListen)
    
    If (iListen = 0) Then GoTo FUNCEND
    
    'check if aborted or if device was found
    If (iListen <> 0) Then
        'get a handle to the device
        Call VBIB32.ibdev(0, 13, NO_SAD, T10s, 1, 0, iDHandle)
        
        If (iDHandle < 0) Then GoTo FUNCEND
    End If
    getDeviceHandle = True
    
    Exit Function
FUNCEND:
    getDeviceHandle = False
End Function

0 Kudos
Message 1 of 4
(3,955 Views)
 

Hi,

The function you are using, ibdev, opens and initializes any unused devices on the GPIB bus.  If there aren't any devices on the bus, or the devices on the bus are in use, ibdev will return -1.  Is this what ibdev is returning in your case?  If so, make sure the devices on the bus are not being used.  Also, using ibdev in a loop will return the device desciptor after the first iteration, but each iteration afterward will return -1 (if there is just one device on the bus) as the device on the bus is already initialized and in use.  Why do you need to run this code multiple times in a loop?  

I have attached a link to the both the NI-488.2M Software Reference Manual, https://www.ni.com/docs/en-US/bundle/370950a/resource/370950a.pdf, and the NI-488.2 User Manual, https://www.ni.com/docs/en-US/bundle/ni-488.2-user-manual/resource/370428w.pdf, both of which detail the ibdev function.  I hope this helps.

Ted

Ted H
Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(3,932 Views)
Hi Ted
I am running a program in Visual basic 6.0 where I have around 10 devices (signal generators) on the bus.
- I select one device at a time and make a frequency sweep.
- Then check the status byte via serial polling using the ibrsp() function.
- In order to send the device ID to ibrsp() I am using the ibdev() function.
- I also tried to save the device ID into a variable for every device logged into
  the application and use it later when I do a sweep and read the status byte.
- But the ibrsp() returns zero (0) as the status byte.
- The iberr generated is (23) EHDL "Invalid handle passed".
- I am passing an integer variable which is already initialized with the device ID
  on logon.
- I checked the GPIB Analyzer to see whether the serial poll is been done and figured that it is not.
- I am now trying to use the AllSpoll to see if it works. 

I would appriciate if you could help on this.
0 Kudos
Message 3 of 4
(3,927 Views)
 

Hi,

How are you sending your device hand to the ibsrp() function?  If you are getting an invalid handle error, you will need to make sure you are passing the correct device desciptor in the correct format to the ibsrp() function.  The device desriptor should be in the form "UDX" where X is an integer returned by the ibdev() function.

A very useful tool when debugging GPIB issues is NI Spy.  NI Spy is a utility that shows all commands sent over the GPIB bus, and will let you see the ibdev, ibsrp and all other GPIB commands sent to your device.  NI Spy can be found from Measurement and Automation Explorer under Tools>>NI-488.2>>NI Spy or from Start>>All Programs>>National Instruments>>NI Spy.  I have attached a link to an online KnowledgeBase detailing how to use NI Spy:  https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YHdrCAG&l=en-US.  I hope this information helps.

Ted

Ted H
Applications Engineering
National Instruments
0 Kudos
Message 4 of 4
(3,907 Views)