Handling Events Example (VB)

NI-VISA

Handling Events Example (Visual Basic)

Note  The Visual Basic examples in the NI-VISA Help use the VISA data types where applicable. This feature is available only on Windows. To use this feature, select the VISA library (visa32.dll) as a reference from Visual Basic. This makes use of the type library embedded into the DLL.

Private Sub vbMain()

Dim stat
Dim dfltRM
Dim sesn
Dim eType
Dim eData
Dim statID
As ViStatus
As ViSession
As ViSession
As ViEventType
As ViEvent
As Integer
Rem Begin by initializing the system
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then

Rem Error initializing VISA...exiting
Exit Sub

End If

Rem Open communication with VXI Device at Logical Address 16
Rem NOTE: For simplicity, we will not show error checking
stat = viOpen(dfltRM, "VXI0::16::INSTR", VI_NULL, VI_NULL, sesn)

Rem Enable the driver to detect the interrupts
stat = viEnableEvent(sesn, VI_EVENT_VXI_SIGP, VI_QUEUE, VI_NULL)

Rem Send the commands to the oscilloscope to capture the
Rem waveform and interrupt when done

stat = viWaitOnEvent(sesn, VI_EVENT_VXI_SIGP, 5000, eType, eData)
If (stat < VI_SUCCESS) Then

Rem No interrupts received after 5000 ms timeout
stat = viClose (dfltRM)
Exit Sub

End If

Rem Obtain the information about the event and then destroy the
Rem event. In this case, we want the status ID from the interrupt.
stat = viGetAttribute(eData, VI_ATTR_SIGP_STATUS_ID, statID)
stat = viClose(eData)

Rem Your code should read data from the instrument and process it.

Rem Stop listening to events
stat = viDisableEvent(sesn, VI_EVENT_VXI_SIGP, VI_QUEUE)

Rem Close down the system
stat = viClose(sesn)
stat = viClose(dfltRM)

End Sub