VISA Message-Based Application Example (VB)

NI-VISA

VISA Message-Based Application 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 As ViStatus

Dim dfltRM
Dim sesn
Dim retCount
Dim idnResult
Dim resultBuffer
As ViSession
As ViSession
As Long
As String * 72
As String * 256
Rem Open Default Resource Manager
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then

Rem Error initializing VISA...exiting
Exit Sub

End If

Rem Open communication with GPIB Device at Primary Addr 1
Rem NOTE: For simplicity, we will not show error checking
stat = viOpen(dfltRM, "GPIB::1::INSTR", VI_NULL, VI_NULL, sesn)

Rem Initialize the timeout attribute to 10 s
stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 10000)

Rem Set termination character to carriage return (\r=0x0D)
stat = viSetAttribute(sesn, VI_ATTR_TERMCHAR, &H0D)
stat = viSetAttribute(sesn, VI_ATTR_TERMCHAR_EN, VI_TRUE)

Rem Don't assert END on the last byte
stat = viSetAttribute(sesn, VI_ATTR_SEND_END_EN, VI_FALSE)

Rem Clear the device
stat = viClear(sesn)

Rem Request the IEEE 488.2 identification information
stat = viWrite(sesn, "*IDN?", 5, retCount)
stat = viRead(sesn, idnResult, 72, retCount)

Rem Your code should use idnResult and retCount to parse device info

Rem Trigger the device for an instrument reading
stat = viAssertTrigger(sesn, VI_TRIG_PROT_DEFAULT)

Rem Receive results
stat = viRead(sesn, resultBuffer, 256, retCount)

Rem Close sessions
stat = viClose (sesn)
stat = viClose (dfltRM)

End Sub