Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I work with dynamic range tables in Labwindows/CVI instrument drivers

Is there a good example somewhere on how to work with dynamic range tables in LabWindows/CVI IVI Instrument drivers? The documentation is a little fuzzy about exactly what needs to be called when. I am trying to create a range table, and was under the impression that "Ivi_RangeTableNew" would allocate the range table to memory and return a pointer to it through the rangeTable Ptr parameter - but it doesn't, it wants a pointer to an existing range table. Huh? 
0 Kudos
Message 1 of 5
(4,074 Views)

Hey Pblase,

I think is that the key is in the IVI Manual found here. and on page 96 you can find this

 

"static ViStatus _VI_FUNC exampleAttrRange_WriteCallback

(ViSession vi, ViSession io,

ViConstString channelName,

ViAttr attributeId, ViReal64 value)

{

ViStatus error = VI_SUCCESS;

ViString cmd;

IviRangeTablePtr rangeTablePtr;

checkErr( Ivi_GetAttrRangeTable (vi, "", EXAMPLE_ATTR_RANGE,

&rangeTablePtr));

checkErr( Ivi_GetViInt32EntryFromValue (value, rangeTablePtr,

VI_NULL, VI_NULL, VI_NULL, VI_NULL, &cmd,

VI_NULL));

viCheckErr (viPrintf (io, ":RANG: %s;", cmd));

Error:

return error;

}"

 

And the trick is just to point to the right pointer "rangeTablePtr".

 

Good luck!

Regards,

Nick D.

 

 

 

 

0 Kudos
Message 2 of 5
(4,064 Views)
Thanks. It turned out that the problem was that (after I fixed the obvious pointer problem) I was calling "RangeTableNew " with "io" and not "vi". This results in a "General Protection Fault" problem (see attached).
 
Which leads me to the next question: when does one use io (generated by  io = Ivi_IOSession(vi);) and when use vi (the ViSession passed in and originally generated in the Init function by Ivi_SpecificDriverNew()?
 
Thanks
Paul
 
/*****************************************************************************
 * Function: NPESP300_DefaultInstrSetup                                              
 * Purpose:  This function sends a default setup to the instrument.  The   
 *           NPESP300_reset function calls this function.  The
 *           NPESP300_IviInit function calls this function when the
 *           user passes VI_FALSE for the reset parameter.  This function is
 *           useful for configuring settings that other instrument driver
 *           functions require.   
 *
 *           Note:  Call this function only when the session is locked.
 *****************************************************************************/
static ViStatus NPESP300_DefaultInstrSetup (ViSession vi)
{
    ViStatus    error = VI_SUCCESS;
 IviRangeTablePtr rangeTablePtr;   
    /* Invalidate all attributes */
    checkErr( Ivi_InvalidateAllAttributes (vi));
   
    if (!Ivi_Simulating(vi))
        {
        ViSession   io = Ivi_IOSession(vi); /* call only when locked */
        checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));
  
  /*=CHANGE:===============================================================*
     Change the following command string so that it executes the default
     setup for your instrument.  The example does the following:
    
     *CLS     clears the event/status registers                                     
     *ESE 1   sets the standard event status enable register to recognize 
              operation complete.                                         
     *SRE 32  sets the service request register to enable a service       
              request on operation complete                               
  
     These settings are required for the default implementation of the     
     WaitForOPCCallback to work correctly.                                
  
  viCheckErr( viPrintf (io, "*CLS;*ESE 1;*SRE 32"));
   *============================================================END=CHANGE=*/
  
  //Create range tables
  rangeTablePtr = VI_NULL;
  checkErr( Ivi_RangeTableNew (vi, 5, 1, VI_TRUE, VI_TRUE, &rangeTablePtr));
  //Max/Min for (0) Position; (1) Velocity; (2) Acceleration; (3) Jog
  checkErr( Ivi_SetAttrRangeTableCallback (vi,
            NPESP300_ATTR_CurrentPosition,
            NPESP300AttrCurrentposition_RangeTableCallback));
  
  
        }
Error:
    return error;
}
0 Kudos
Message 3 of 5
(4,057 Views)
pblase,
 
The 'vi' is an IVI driver session handle maintained by the IVI Engine. The 'io' is the handle to whatever I/O library is being used to communicate with the instrument, for example VISA, GPIB etc. So wherever the driver makes called to the low-level I/O library, e.g. viWrite, viRead etc., it must use the 'io' session handle. Note that usage of 'io' sessions is always conditions by if (!Ivi_Simulating(vi)) blocks because the io session doesnt exist if the driver is simulating.
 
You create the io session handle in the driver's initialize function.
 
Hope this makes it clear.
 
z_haider
Message 4 of 5
(4,044 Views)

Yes, thank you very much. So: If I'm only concerned with the internals of the driver, range tables, Attributes, etc, then I use "vi". If I actually have to talk to the instrument, then I use "io".

Paul

0 Kudos
Message 5 of 5
(4,041 Views)