Command synchronization
// *****************************************************************************
// Use *WAI to synchronize the measurement: instrument holds commands 3, 4
// until commands 1, 2 are finished. Due to no instrument feedback on waiting,
// we recommend other methods.
// *****************************************************************************
command1;command2;*WAI;command3;command4
// *****************************************************************************
// Use *OPC? for synchronization: instrument executes commands 1, 2.
// When finished continues with processing of commands 3, 4.
// *****************************************************************************
command1
command2
*OPC?
command3
command4
// *****************************************************************************
// Use *OPC + serial poll for synchronization: instrument processes command 1.
// Enable the OPC bit of the ESE register and read the ESR register
// to clear pending events. The query also ensures that all previous
// commands are processed before the next step.
// Send command 2 with OPC*.
// Poll the status byte register using VISA built-in command viReadSTB().
// When the command 2 is finished, the OPC bit in ESR register also sets the
// event status bit (ESB = bit 5) in the STB register.
// Then the instrument continues with processing of commands 3, 4.
// *****************************************************************************
command1
*ESE 1;*ESR?
command2;*OPC
viReadSTB() until ESB bit is 1
command3
command4
/// *****************************************************************************************
// Use service request for synchronization
// instrument processes command 1.
// Enable ESB (bit 5 in STB register) Enable OPC bit (bit 0 in ESR)
// Clear the ESR register by reading it (the value is not relevant).
// *****************************************************************************************
command1
*SRE 32
*ESE 1
*ESR?
// *****************************************************************************************
// To enable event notification use the following VISA function:
// *****************************************************************************************
viEnableEvent(vi, VI_EVENT_SERVICE_REQ, VI_QUEUE, 0)
// *****************************************************************************************
// If required discard stale events before generating a new SRQ:
// *****************************************************************************************
viDiscardEvents(vi, VI_EVENT_SERVICE_REQ, VI_QUEUE)
viReadSTB() until SRQ (bit 7) is unset
// *****************************************************************************************
// Insert *OPC in the command sequence to generate service request (SRQ)
// *****************************************************************************************
command2;*OPC
// *****************************************************************************************
// Wait for the generated SRQ and read the corresponding status byte -> SRQ (bit 7) is set.
// *****************************************************************************************
viWaitOnEvent(vi, VI_EVENT_SERVICE_REQ, timeout, NULL, NULL)
viReadSTB(vi, &stb)