Chapter 3 Programming Examples
RIGOL
DS4000E Programming Guide
3-5
Dim ret As Long
'Turn on the device, and the device resource descriptor is in CELLS(1,2) of SHEET1'
viErr = visa.viOpenDefaultRM(viDefRm)
viErr = visa.viOpen(viDefRm, Sheet1.Cells(1, 2), 0, 5000, viDevice)
‘Send request, read the data, and the return value is in CELLS(2,2) of SHEET1’
cmdStr = "*IDN?"
viErr = visa.viWrite(viDevice, cmdStr, Len(cmdStr), ret)
viErr = visa.viRead(viDevice, idnStr, 128, ret)
Sheet1.Cells(2, 2) = idnStr
‘Turn off the device’
visa.viClose (viDevice)
visa.viClose (viDefRm)
End Sub
Note: If the Excel file created in Step 1 does not enable the Macros, a prompt message “The following
features cannot be saved in macro-free workbooks” will be displayed. In this case, please save the file
as a macro-enabled file type (filename with a suffix of ".xlsm").
Besides, when you need to view or modify the codes, you can select View Code in the Developer tab
in the Excel window to open the code window.
6.
Click Insert in the Developer tab in the Excel window, and then select the desired button in Form
Controls and put it into the cell of the Excel. At this time, the Assign Macro interface is displayed,
select Sheet1.QueryIdn and click OK.
7.
The default button name is "Button 1". Right-click the button and select Edit Text in the pop-up menu
to change the button name to "*IDN?" as shown in the figure below. Click the *IDN? button to read
the device information. The result is displayed in SHEET1.CELLS(2,2) (namely the B2 cell in Sheet1).