Programming Manual MSO/UPO2000 Series
147 / 156
Instruments.uni-trend.com
a)
USBTMC
Example
PrivateFunction usbtmc_test() AsLong
' This code demonstrates sending synchronous read & write commands
' to an USB Test & Measurement Class (USBTMC) instrument using NI-VISA
' The example writes the "*IDN?\n" string to all the USBTMC
' devices connected to the system and attempts to read back
' results using the write and read functions.
' The general flow of the code is
' Open Resource Manager
' Open VISA Session to an Instrument
' Write the Identification Query Using viWrite
' Try to Read a Response With viRead
' Close the VISA Session
Const MAX_CNT = 200
Dim defaultRM AsLong
Dim instrsesn AsLong
Dim numlnstrs AsLong
Dim findList AsLong
Dim retCount AsLong
Dim status AsLong
Dim instrResourceString AsString *VI_FIND_BUFLEN
Dim Buffer AsString * MAX_CNT
Dim i AsInteger
' First we must call viOpenDefaultRM to get the manager
' handle. We will store this handle in defaultRM.
status = viOpenDefaultRM(defaultRM)
If(status < VI_SUCCESS) Then
resultTxt.Text = "Could not open a session to the VISA Resource Manager!"
usbtmc_test = status
ExitFunction
EndIf
' Find all the USB TMC VISA resources in our system and store the
' number of resources in the system in numInstrs.
status = viFindRsrc(defaultRM, "USB?*INSTR", findList, numlnstrs, instrResourceString)
If (status < VI_SUCCESS) Then
resultTxt.Text = "An error occurred while finding resources."
viClose(defaultRM)
usbtmc_test = status
ExitFunction
EndIf