This function can be called in a Visual Basic program. It sends the *IDN? query to the instrument and returns the byte count and ASCII response string.
Rem This example is based on Example 2‑1 from the NI‑VISA User Manual.
Public Sub IdnMain(ByVal address As String, ByRef byteCount As String, ByRef returnBytes As String)
Const BUFFER_SIZE = 200
Dim stat As ViStatus
Dim dfltRM As ViSession
Dim sesn As ViSession
Dim retCount As Long
Dim buffer As String * BUFFER_SIZE
Rem ***Include visa32.dll as a reference in your project.***
Rem Begin by initializing the system
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then
Rem Error initializing VISA...exiting
MsgBox “Can't initialize VISA”
Exit Sub
End If
Rem Open communication with Device
Rem NOTE: For simplicity, we will not show error checking
Rem TODO: Add error handling.
stat = viOpen(dfltRM, address, VI_NULL, VI_NULL, sesn)
Rem Set the timeout for message‑based communication
Rem TODO: Add error handling.
stat = viSetAttribute(sesn, VI_ATTR_TMO_VALUE, 120000)
Rem Ask the device for identification
Rem TODO: Add error handling.
stat = viWrite(sesn, “*IDN?”, 5, retCount)
stat = viRead(sesn, buffer, BUFFER_SIZE, retCount)