Finding Resources
As shown in the previous section, you can create a session to a resource using the viOpen() call. However, before you use this call you need to know the exact location (address) of the resource you want to open. To find out what resources are currently available at a given point in time, you can use the search services provided by the viFindRsrc() operation, as shown in the following example.
Example
Note This example shows C source code. There is also an example in Visual Basic syntax. |
#include "visa.h"
/* Find the first matching device and return a session to it */
/* Error initializing VISA ... exiting */ } /* Error finding resources ... exiting */ } status = viOpen(defaultRM, desc, VI_NULL, VI_NULL, &instr); viFindNext(fList, desc); } viClose(instr); } viClose(instr); } } } |
As this example shows, you can use viFindRsrc() to get a list of matching resource names, which you can then further examine one at a time using viFindNext(). Remember to free the space allocated by the system by invoking viClose() on the list reference fList.
Notice that while this sample function returns a session, it does not return the reference to the resource manager session that was also opened within the same function. In other words, there is only one output parameter, the session to the instrument itself, instrSesn. When your program is done using this session, it also needs to close that corresponding resource manager session. Therefore, if you use this style of initialization routine, you should later get the reference to the resource manager session by querying the attribute VI_ATTR_RM_SESSION just before closing the INSTR session. You can then close the resource manager session with viClose().