Message-Based Communication Example (VB)

NI-VISA

Message-Based Communication 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()

Const MAX_CNT = 200

Dim stat
Dim dfltRM
Dim sesn
Dim retCount
Dim buffer
As ViStatus
As ViSession
As ViSession
As Long
As String * MAX_CNT
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 GPIB Device at Primary Addr 1
Rem NOTE: For simplicity, we will not show error checking
stat = viOpen(dfltRM, "GPIB0::1::INSTR", VI_NULL, VI_NULL, sesn)

Rem Set the timeout for message-based communication
stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 5000)

Rem Ask the device for identification
stat = viWrite(sesn, "*IDN?", 5, retCount)
stat = viRead(sesn, buffer, MAX_CNT, retCount)

Rem Your code should process the data

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

End Sub