Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How SRQ is handled in IVI drivers?

Hi,
 
We are started migrating our old GPIB driver to IVI drivers. In GPIB we use 'ibnotify()' to handle Instrument generated SRQ. Is this taken care in the IVI drivers? or should we open a VISA\GPIB session and enable callback function?
In IVI driver if the status is non-zero we are reading the error buffer, whether this will take care SRQ also?
 
Thanks for going through this, let me know your valuable inputs.
 
Prashantha
0 Kudos
Message 1 of 5
(4,302 Views)
It's my understanding that the handling of low level functions such as SRQ would be done by the instrument specific driver. At the class level, you have the status check functions and if an instrument sets SRQ, the instrument driver would read this and return the information during a status check. While all 488.2 instruments are supposed to have a status register and the instrument specific driver should be checking this, some older GPIB instruments may not have a status register, the author of the instrument specific driver may not use it, and not all IVI class instruments are GPIB. If you want your program to be truly IVI, then you need to avoid doing any instrument specific operations at the top level of your program. If you have concerns about how a specific instrument driver is handling something like SRQ, you need to get the source code. With NI IVI-C drivers, you always have source code available.
0 Kudos
Message 2 of 5
(4,289 Views)
Hi Prashantha,
 
Checking for SRQ needs to be implemented in a callback. You can take a look at WaitForOPCCallback in scope specific drivers - here is an example:
 
/*****************************************************************************
 * Function: tkds30xx_WaitForOPCCallback                                              
 * Purpose:  This function waits until the instrument has finished processing
 *           all pending operations.  This function is called by the
 *           tkds30xx_WaitForOPC utility function.  The IVI engine invokes
 *           this function in the following two cases:
 *           - Before invoking the read callback for attributes for which the
 *             IVI_VAL_WAIT_FOR_OPC_BEFORE_READS flag is set.
 *           - After invoking the write callback for attributes for which the
 *             IVI_VAL_WAIT_FOR_OPC_AFTER_WRITES flag is set.
 *****************************************************************************/
static ViStatus _VI_FUNC tkds30xx_WaitForOPCCallback (ViSession vi, ViSession io)
{
    ViStatus    error = VI_SUCCESS;
    ViInt32     opcTimeout;
    ViUInt16    statusByte;
    ViUInt16    interface = VI_INTF_GPIB;
   
    viCheckErr( viGetAttribute (io, VI_ATTR_INTF_TYPE, &interface));
   
    checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL, TKDS30XX_ATTR_OPC_TIMEOUT, 0,
                                       &opcTimeout));
    if (interface == VI_INTF_GPIB)
        {
        checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL, TKDS30XX_ATTR_OPC_TIMEOUT, 0,
                                            &opcTimeout));
        viCheckErr( viEnableEvent (io, VI_EVENT_SERVICE_REQ, VI_QUEUE, VI_NULL));
        viCheckErr( viPrintf (io, "*OPC"));
            /* wait for SRQ */
        viCheckErr( viWaitOnEvent (io, VI_EVENT_SERVICE_REQ, opcTimeout, VI_NULL, VI_NULL));
        viCheckErr( viDisableEvent (io, VI_EVENT_SERVICE_REQ, VI_QUEUE));
            /* clean up after SRQ */
        viCheckErr( viBufWrite (io, "*CLS", 4, VI_NULL));
        viCheckErr( viReadSTB (io, &statusByte));
        }
    else {
        ViBoolean opcDone = VI_FALSE;
        viCheckErr( viQueryf (io, "*OPC?", "%hd", &opcDone));
    }
Error:
    if (interface == VI_INTF_GPIB)
        {
        viDiscardEvents (io, VI_EVENT_SERVICE_REQ, VI_QUEUE);
        if (error == VI_ERROR_TMO)
            Ivi_SetErrorInfo(vi, VI_TRUE, TKDS30XX_ERROR_MAX_TIME_EXCEEDED, 0, VI_NULL);
        }
    return error;
 
 
0 Kudos
Message 3 of 5
(4,275 Views)

Hi Thanks for the replay.

Let me more specific on the question with the exact work we are doing.

We have old GPIB driver for SONY/TEKRONIX RTD710 digitizer which uses ibnotify() and GPIB callback function to handle SRQ, with this we are able to get all the instrument generated SRQ's depending upon our requirement.

Now we change the digitizer to Tektronix TDS5032B DPO and downloaded NI-IVI 'C', driver, with this we developed the driver with checking the status after each function call.

Now the question has arised on the SRQ part , I underrstood wait for OPC when fetchinng the waveform, but will other SRQ's like COMMAND ERROR, EXECUTION ERRORS are handle in status check? Pls let me know. Do we need to open a seperate VISA\GPIB session? I'm not very clear on this.

Thanks

Prashantha

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

Hi Prashantha,

I believe the answer to your question is yes, the CheckStatusCallback does check for EXECUTION_ERROR_BIT and COMMAND_ERROR_BIT. Again, you can use tkds30xx driver as an example:

    /*- 488.2 Event Status Register (ESR) Bits ------------------------------*/
#define IEEE_488_2_QUERY_ERROR_BIT              0x04
#define IEEE_488_2_DEVICE_DEPENDENT_ERROR_BIT   0x08
#define IEEE_488_2_EXECUTION_ERROR_BIT          0x10
#define IEEE_488_2_COMMAND_ERROR_BIT            0x20

#define IEEE_488_2_ERROR_BITS     (IEEE_488_2_QUERY_ERROR_BIT | \
                                   IEEE_488_2_DEVICE_DEPENDENT_ERROR_BIT | \
                                   IEEE_488_2_EXECUTION_ERROR_BIT | \
                                   IEEE_488_2_COMMAND_ERROR_BIT)

static ViStatus _VI_FUNC tkds30xx_CheckStatusCallback (ViSession vi, ViSession io)
{
    ViStatus    error = VI_SUCCESS;
    ViInt16     esr = 0;
    ViUInt16  interface = VI_INTF_GPIB;
   
    viCheckErr( viGetAttribute (io, VI_ATTR_INTF_TYPE, &interface));
    if (interface != VI_INTF_ASRL)
        {
            /* Query instrument status */
        viCheckErr( viQueryf (io, "*ESR?", "%hd", &esr));
   
            /* Convert status information into a message */
        if (esr & IEEE_488_2_ERROR_BITS)
            {    
            viCheckErr( IVI_ERROR_INSTR_SPECIFIC);
            }
        }  
Error:
    return error;
}

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