4.1EXAMPLES OF USING VISA ........................................................................................................... 58
4.1.1 VC++ Example ...................................................................................................................... 58
4.1.2 VB Example .......................................................................................................................... 65
4.1.3 MATLAB Example ................................................................................................................. 70
4.1.4 LabVIEW Example ................................................................................................................ 72
4.1.5 Python Example ................................................................................................................... 74
4.2EXAMPLES OF USING SOCKETS ....................................................................................................... 77
4.2.1 Python Example ................................................................................................................... 77
5 INDEX ..................................................................................................................................... 80
2
Page 4
Programming Guide
1 Programming Overview
By using USB and LAN interfaces, in combination with NI-VISA and programming
languages, users can remotely control the waveform generator. Through LAN interface,
VXI-11, Sockets and Telnet protocols can be used to communicate with the instruments.
This chapter introduces how to build communication between the instrument and the PC.
It also introduces how to configure a system for remote instrument control.
1.1 Build communication via VISA
1.1.1 Install NI-VISA
Before programming, please make sure that you have properly installed the latest version
of National Instruments NI-VISA Software.
NI-VISA is a communication library that enables computer communications to
instrumentation. There are two available VISA packages: A full version and the Run-Time
Engine. The full version includes NI device drivers and a tool named NI MAX; a user
interface to control the device. While the drivers and NI MAX can be useful, they are not
required for remote control. The Run-Time Engine is a much smaller file and is
recommended for remote control.
For convenience, you can obtain the latest version of the NI-VISA run-time engine or full
version from the National Instruments website. The installation process is similar for both
versions.
Follow these steps to install NI-VISA (The full version of NI-VISA 5.4 is used in this
example):
a. Download the appropriate version of NI-VISA (the Run-time engine is recommended)
b. Double click the visa540_full.exe, dialog shown as below:
3
Page 5
Programming Guide
c. Click Unzip, the install process will launch after unzipping files. If your computer
needs to install the .NET Framework 4, it may auto start.
d. The NI-VISA install dialog is shown above. Click Next to start the installation process.
4
Page 6
Programming Guide
e. Set the install path, default path is “C:\Program Files\National Instruments\”, you can
change it, if you prefer. Click Next, dialog as shown above.
f. Click Next twice, in the License Agreement dialog, select the “I accept the above 2
License Agreement(s).”,and click Next, dialog as shown below:
5
Page 7
g. Click Next to begin installation.
Programming Guide
h. Now the installation is complete. Reboot your PC.
6
Page 8
Programming Guide
1.1.2 Connect the instrument
Depending on the specific model, the arbitrary waveform generator may be able to
communicate with a PC through the USB or LAN interface.
Connect the arbitrary waveform generator and the USB Host interface of the PC using a
USB cable. Assuming your PC is already turned on, turn on the SDG, and then the PC will
display the “Device Setup” screen as it automatically installs the device driver as shown
below.
Wait for the installation to complete and then proceed to the next step.
7
Page 9
Programming Guide
1.2 Remote Control
1.2.1 User-defined Programming
Users can send SCPI commands via a computer to program and control the arbitrary
waveform generator. For details, refer to the introductions in " Programming Examples".
1.2.2 Using SCPI via NI-MAX
NI-MAX is a program created and maintained by National Instruments. It provides a basic
remote control interface for VXI, LAN, USB, GPIB, and Serial communications. The SDG
can be controlled remotely by sending SCPI commands via NI-MAX.
1.2.3 Using SCPI over Telnet
Telnet provides a means of communicating with the SDG over the LAN. The Telnet protocol
sends SCPI commands to the SDG from a PC and is similar to communicating with the
SDG over USB. It sends and receives information interactively: one command at a time.
The Windows operating systems use a command prompt style interface for the Telnet client.
The steps are as follows:
1. On your PC, click Start > All Programs > Accessories > Command Prompt.
2. At the command prompt, type in telnet.
3. Press the Enter key. The Telnet display screen will be displayed.
8
Page 10
Programming Guide
4. At the Telnet command line, type:
open XXX.XXX.XXX.XXX 5024
Where XXX.XXX.XXX.XXX is the instrument’s IP address and 5024 is the port. You should
see a response similar to the following:
5. At the SCPI> prompt, input the SCPI commands such as *IDN? to return the company
name, model number, serial number, and firmware version number.
9
Page 11
Programming Guide
6. To exit the SCPI> session, press the Ctrl+] keys simultaneously.
7. Type quit at the prompt or close the Telnet window to close the connection to the
instrument and exit Telnet.
1.2.4 Using SCPI over Socket
Socket API can be used to control the SDG series by LAN without installing any other
libraries. This can reduce the complexity of programming.
SOCKET ADDRESS IP address + port number
IP ADDRESS SDG IP address
PORT NUMBER 5025
Please see section 4.2 "Examples of Using Sockets" for the details.
10
Page 12
Programming Guide
2 Introduction to the SCPI Language
2.1 About Commands & Queries
This section lists and describes the remote control commands and queries recognized by
the instrument. All commands and queries can be executed in either local or remote state.
Each command or query, with syntax and other information, has some examples listed.
The commands are given in both long and short format at “COMMAND SYNTAX”and “QUERY SYNTAX”, and the subject is indicated as a command or query or both. Queries
perform actions such as obtaining information, and are recognized by the question mark
(?) following the header.
2.2 Description
In the description, a brief explanation of the function performed is given. This is followed
by a presentation of the formal syntax, with the header given in Upper-and-Lower-Case
characters and the short form derived from it in ALL UPPER-CASE characters. Where
applicable, the syntax of the query is given with the format of its response.
2.3 Usage
The commands and queries listed here can be used for SDGxxxx Series Arbitrary
Waveform Generators.
2.4 Command Notation
The following notations are used in the commands:
< > Angular brackets enclose words that are used as placeholders, of which there are
two types: the header path and the data parameter of a command.
:= A colon followed by an equals sign separates a placeholder, from the description of
the type and range of values that may be used in a command instead of the
placeholder.
{ } Braces enclose a list of choices, one of which must be made.
[ ] Square brackets enclose optional items.
… An ellipsis indicates that the items both to its left and right may be repeated for a
11
Page 13
number of times.
Short
Long Form
Subsystem
What Command/Query does
*IDN
*IDN
SYSTEM
Gets identification from device.
*OPC
*OPC
SYSTEM
Gets or sets the OPC bit (0) in the Event
Status Register (ESR).
*RST
*RST
SYSTEM
Initiates a device reset.
CHDR
COMM_HEADER
SIGNAL
Sets or gets the command returned format
OUTP
OUTPUT
SIGNAL
Sets or gets the output state.
BSWV
BASIC_WAVE
SIGNAL
Sets or gets the basic wave parameters.
MDWV
MODULATEWAVE
SIGNAL
Sets or gets the modulation parameters.
SWWV
SWEEPWAVE
SIGNAL
Sets or gets the sweep parameters.
BTWV
BURSTWAVE
SIGNAL
Sets or gets the burst parameters.
PACP
PARACOPY
SIGNAL
Copies parameters from one channel to the
other.
ARWV
ARBWAVE
DATA
Changes arbitrary wave type.
SYNC
SYNC
SIGNAL
Sets or gets the synchronization signal.
NBFM
NUMBER_FORM
AT
SYSTEM
Sets or gets the data format.
LAGG
LANGUAGE
SYSTEM
Sets or gets the language.
SCFG
SYS_CFG
SYSTEM
Sets or gets the power-on system setting
way.
BUZZ
BUZZER
SYSTEM
Sets or gets the buzzer state.
SCSV
SCREEN_SAVE
SYSTEM
Sets or gets the screen save state.
ROSC
ROSCILLATOR
SIGNAL
Sets or gets the state of clock source.
FCNT
FREQCOUNTER
SIGNAL
Sets or gets the frequency counter
parameters.
INVT
INVERT
SIGNAL
Sets or gets the polarity of current channel.
COUP
COUPLING
SIGNAL
Sets or gets the coupling parameters.
VOLTPRT
VOLTPRT
SYSTEM
Sets or gets the state of over-voltage
protection.
STL
STORELIST
SIGNAL
Lists all stored waveforms.
WVDT
WVDT
SIGNAL
Sets and gets the arbitrary wave data.
VKEY
VIRTUALKEY
SYSTEM
Sets the virtual keys.
SYST:CO
MM:LAN:I
PAD
SYSTEM:COMMU
NICATE:LAN:IPAD
DRESS
SYSTEM
The Command can set and get system IP
address.
SYST:CO
SYSTEM:COMMU
SYSTEM
The Command can set and get system
2.5 Table of Command & Queries
Programming Guide
12
Page 14
Programming Guide
Short
Long Form
Subsystem
What Command/Query does
MM:LAN:S
MAS
NICATE:LAN:SMA
SK
subnet mask.
SYST:CO
MM:LAN:G
AT
SYSTEM:COMMU
NICATE:LAN:GAT
EWAY
SYSTEM
The Command can set and get system
Gateway.
SRATE
SAMPLERATE
SIGNAL
Sets or gets the arbitrary wave mode,
sampling rate and interpolation method.
HARM
HARMonic
SIGNAL
Sets or gets the harmonic information.
CMBN
CoMBiNe
SIGNAL
Sets or gets the wave combine information.
MODE
MODE
SIGNAL
Sets or gets the waveform phase mode
CASCADE
CASCADE
SYSTEM
Set up multi-device synchronization
IQ:CENT
IQ:CENTerfreq
SIGNAL
Sets the I/Q modulator center frequency.
IQ:SAMP
IQ:SAMPlerate
SIGNAL
Sets the I/Q sample rate.
IQ:SYMB
IQ:SYMBolrate
SIGNAL
Sets the I/Q symbol rate.
IQ:AMPL
IQ:AMPLitude
SIGNAL
Sets the I/Q amplitude.
IQ:IQAD:G
AIN
IQ:IQADjustment:
GAIN
SIGNAL
Adjusts the ratio of I to Q while preserving
the composite.
IQ:IQAD:I
OFF
IQ:IQADjustment:I
OFFset
SIGNAL
Adjusts the I channel offset value.
IQ:IQAD:Q
OFF
IQ:IQADjustment:
QOFFset
SIGNAL
Adjusts the I channel offset value.
IQ:IQAD:Q
SK
IQ:IQADjustment:
QSKew
SIGNAL
Adjusts the phase angle between the I
and Q vectors by increasing or decreasing
the Q phase angle.
IQ:TRIG:S
OUR
IQ:TRIGger:SOUR
ce
SIGNAL
Sets the I/Q trigger source.
IQ:WAVE:
BUIL
IQ:WAVEload:BUI
Ltin
SIGNAL
Selects the I/Q wave from built in wave list.
IQ:WAVE:
USER
IQ:WAVEload:USE
Rstored
SIGNAL
Select the I/Q wave from user stored
waveforms.
:IQ:
Frequency
Sampling
:IQ:
FrequencySamplin
g
SIGNAL
Sets the I/Q Frequency sampling rate.
13
Page 15
Programming Guide
DESCRIPTION
The *IDN? query causes the instrument to identify itself. The
response is comprised of the manufacturer, model, serial number
and firmware version.
QUERY SYNTAX
*IDN?
RESPONSE FORMAT
Format 1: *IDN, <device id>,<model>,<serial number>,<firmware
version>, <hardware version>
Format 2: <manufacturer>,<model>,<serial number>,<firmware
version>
<device id>:= “SDG”.
<manufacturer>:= “Siglent Technologies”.
<model>:= A model identifier less than 14 characters, should not
contain the word “MODEL”.
<serial number>:= The serial number.
<firmware version>:= The firmware version number.
<hardware version>:= The hardware level field, containing
information about all separately revisable subsystems.
EXAMPLE
Reads version information:
*IDN?
Return:
Siglent Technologies,SDG6052X, SDG6XBAX1R0034,
6.01.01.28 (It may differ from each version)
3 Commands and Queries
3.1 IEEE 488.2 Common Command Introduction
The IEEE standard defines the common commands used for
querying the basic information of the instrument or executing
basic operations. These commands usually start with "*" and
the length of the keywords of the command is usually 3
characters.
3.1.1 *IDN
Notes:
1. The table below shows the available response format of the command in each SDG
14
Page 16
Programming Guide
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
Response Format
Format1
Format1
Format2
Format1
Format2
Format2
DESCRIPTION
The *OPC (Operation Complete) command sets the OPC bit (bit
0) in the standard Event Status Register (ESR). This command
has no other effect on the operation of the device because the
instrument starts parsing a command or query only after it has
completely processed the previous command or query. The
*OPC? query always responds with the ASCII character 1
because the device only responds to the query when the previous
command has been entirely executed.
COMMAND SYNTAX
*OPC
QUERY SYNTAX
*OPC?
RESPONSE FORMAT
Format 1: *OPC 1
Format 2: 1
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
Response Format
Format1
Format1
Format2
Format1
Format2
Format2
series.
2. Format of <hardware version>: value1-value2-value3-value4-value5.
value1: PCB version.
value2: Hardware version.
Note: The table below shows the available response format of the command in each SDG
series.
15
Page 17
3.1.3 *RST
DESCRIPTION
The *RST command initiates a device reset and recalls the
default setup.
COMMAND SYNTAX
*RST
EXAMPLE
This example resets the signal generator to the default setup:
*RST
DESCRIPTION
This command is used to change the query command returned
format. “SHORT” parameter returns short format. “LONG”
parameter returns long format. “OFF” returns nothing.
Note: The table below shows the availability of the command in each SDG series.
16
Page 18
Programming Guide
DESCRIPTION
This command enables or disables the output port(s) at the front panel. The query returns
“ON” or “OFF” and “LOAD”, “PLRT”, “RATIO” parameters.
COMMAND
SYNTAX
<channel>:OUTPut ON|OFF,LOAD,<load>,PLRT, <polarity>
<channel>:= {C1, C2}.
<load>:= {see the note below}. The unit is ohm.
<polarity>:= {NOR, INVT}, in which NOR refers to normal, and INVT refers to invert.
NoiseSum: to add noise to the channel with specified signal-to-noise ratio.
<channel>:NOISE_ADD STATE,ON|OFF,RATIO,<S/N>.
or
<channel>:NOISE_ADD STATE,ON|OFF,RATIO_DB,<S/N(dB)>.
<S/N>:= {2.1-100000000}.
<S/N (dB)>:= {3.24886-80}.
Max Amplitude Output: to limit the maximum amplitude output.
<channel>:BSWV MAX_OUTPUT_AMP, <Amplitude>
<Amplitude>:={1-20}, Maximum output amplitude peak-to-peak voltages.
turn on NoiseSum and set the signal-to-noise ratio
C1:NOISE_ADD STATE,ON,RATIO,120
Set the maximum output amplitude
C1:BSWV MAX_OUTPUT_AMP,5
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
<channel>
no
yes
yes
yes
yes
yes
LOAD
50, HZ
50~10000,
HZ
50~100000
, HZ
50, HZ
50~100000
, HZ
50~100000
, HZ
DESCRIPTION
This command sets or gets the basic wave parameters.
COMMAND SYNTAX
<channel>:BaSic_WaVe <parameter>,<value>
<channel>:={C1, C2}.
<parameter>:= {a parameter from the table below}.
<value>:={value of the corresponding parameter}.
Parameters
Value
Description
WVTP
<type>
:= {SINE, SQUARE, RAMP, PULSE, NOISE, ARB, DC,
PRBS, IQ}. If the command doesn’t set basic waveform
type, WVPT will be set to the current waveform.
FRQ
<frequency>
:= frequency. The unit is Hertz “Hz”. Refer to the data
sheet for the range of valid values. Not valid when WVTP
is NOISE or DC.
PERI
<period>
:= period. The unit is seconds "s". Refer to the data sheet
for the range of valid values. Not valid when WVTP is
NOISE or DC.
AMP
<amplitude>
:= amplitude. The unit is volts, peak-to-peak "Vpp". Refer
to the data sheet for the range of valid values. Not valid
when WVTP is NOISE or DC.
Note: The table below shows the availability of the command in each SDG series.
* "HZ" refers to High Z.
3.4 Basic Wave Command
18
Page 20
Programming Guide
OFST
<offset>
:= offset. The unit is volts "V". Refer to the data sheet for
the range of valid values. Not valid when WVTP is
NOISE.
SYM
<symmetry>
:={0 to 100}. Symmetry of RAMP. The unit is "%". Only
settable when WVTP is RAMP.
DUTY
<duty>
:= {0 to 100}. Duty cycle. The unit is "%". Value depends
on frequency. Only settable when WVTP is SQUARE or
PULSE.
PHSE
<phase>
:= {0 to 360}. The unit is "degree". Not valid when WVTP
is NOISE, PULSE or DC.
STDEV
<stdev>
:= standard deviation of NOISE. The unit is volts "V".
Refer to the data sheet for the range of valid values. Only
settable when WVTP is NOISE.
MEAN
<mean>
:= mean of NOISE. The unit is volts "V". Refer to the data
sheet for the range of valid values. Only settable when
WVTP is NOISE.
WIDTH
<width>
:= positive pulse width. The unit is seconds "s". Refer to
the data sheet for the range of valid values. Only settable
when WVTP is PULSE.
RISE
<rise>
:= rise time (10%~90%). The unit is seconds "s". Refer
to the data sheet for the range of valid values. Only
settable when WVTP is PULSE.
FALL
<fall>
:= fall time (90%~10%). The unit is seconds "s". Refer to
the data sheet for the range of valid values. Only settable
when WVTP is PULSE.
DLY
<delay>
:= pulse delay. The unit is seconds "s". Refer to the data
sheet for the range of valid values. Only settable when
WVTP is PULSE.
HLEV
<high level>
:= high level. The unit is volts "V". Not valid when WVTP
is NOISE or DC.
LLEV
<low level>
:= low level. The unit is volts "V". Not valid when WVTP
is NOISE or DC.
BANDSTATE
<bandwidth
switch >
:= {ON,OFF}. Only settable when WVTP is NOISE.
BANDWIDT
H
<bandwidth
value>
:= noise bandwidth. The unit is Hertz "Hz". Refer to the
data sheet for the range of valid values. Only settable
when WVTP is NOISE.
LENGTH
<prbs
length>
:={3~32}. Actual PRBS length = 2
LENGTH
-1. Only settable
when WVTP is PRBS.
EDGE
<prbs
rise/fall>
:= rise/fall time of PRBS. The unit is seconds "s". Refer
to the data sheet for the range of valid values. Only
settable when WVTP is PRBS.
DIFFSTATE
<prbs
:={ON, OFF}. State of PRBS differential mode. Only
19
Page 21
Programming Guide
differential
switch>
settable when WVTP is PRBS.
BITRATE
<prbs bit
rate>
:= PRBS bit rate. The unit is bits-per-second "bps". Refer
to the data sheet for the range of valid values. Only
settable when WVTP is PRBS.
LOGICLEVE
L
<prbs
logiclevel
rate>
:={ TTL_CMOS, LVTTL_LVCMOS, ECL, LVPECL,
LVDS }. Only settable when WVTP is PRBS.
AMPVRMS
<amplitude>
:= amplitude. The unit is Vrm.
AMPDBM
<amplitude>
:= amplitude. The unit is dBm.
QUERY SYNTAX
<channel>: BaSic_WaVe?
<channel>:= {C1, C2}.
RESPONSE FORMAT
<channel>:BSWV <parameter>
<parameter>:= {All the parameters of the current basic
waveform}.
<type>:= {AM,DSBAM,FM,PM,PWM,ASK,FSK,PSK}.
<parameter>:= {a parameter from the table below}.
<value>:= {value of the corresponding parameter}.
1. The table below shows the availability of some command parameters in each SDG
series.
2. In SDG1000X if Wave Combine is enabled, WVTP cannot be set to SQUARE.
3.5 Modulate Wave Command
21
Page 23
Programming Guide
Parameters
Value
Description
STATE
<state>
:={ON, OFF}. Enable or disable modulation.
STATE must be set to ON before you set or
read other parameters of the modulation.
AM, SRC
<src>
:= {INT, EXT}. AM signal source.
AM, MDSP
<mod wave shape>
:= {SINE, SQUARE, TRIANGLE, UPRAMP,
DNRAMP, NOISE, ARB}.
AM modulation wave. Only settable when
SRC is INT.
AM, FRQ
<AM frequency>
:= AM frequency. The unit is Hertz "Hz". Refer
to the data sheet for the range of valid values.
Only settable when SRC is INT.
AM, DEPTH
<depth>
:= {0 to 120}. AM depth. The unit is "%". Only
settable when SRC is INT.
DSBAM, SRC
<src>
:= {INT, EXT}. DSBAM signal source.
DSBAM,
MDSP
<mod wave shape>
:= {SINE, SQUARE, TRIANGLE, UPRAMP,
DNRAMP, NOISE, ARB}.
DSB AM modulation wave. Only settable
when SRC is INT.
DSBAM, FRQ
<DSB-AM
frequency>
:= DSB AM frequency. The unit is Hertz "Hz".
Refer to the data sheet for the range of valid
values. Only settable when SRC is INT.
FM, SRC
<src>
:= {INT, EXT}. FM signal source.
FM, MDSP
<mod wave shape>
:= {SINE, SQUARE, TRIANGLE, UPRAMP,
DNRAMP, NOISE, ARB}.
FM modulation wave. Only settable when
SRC is INT.
FM, FRQ
<FM frequency>
:= FM frequency. The unit is Hertz "Hz". Refer
to the data sheet for the range of valid values.
Only settable when SRC is INT.
FM, DEVI
<FM frequency
deviation >
:= {0 to carrier frequency}.
FM frequency deviation. The value depends
on the difference between the carrier
frequency and the bandwidth frequency. Only
settable when signal source is INT.
PM, SRC,
<src>
:= {INT, EXT}. PM signal source.
PM, MDSP
<mod wave shape>
:= {SINE, SQUARE, TRIANGLE, UPRAMP,
DNRAMP, NOISE, ARB}.
PM modulation wave. Only settable when
SRC is INT.
PM, FRQ
<PM frequency>
:= PM frequency. The unit is Hertz "Hz". Refer
to the data sheet for the range of valid values.
Only settable when SRC is INT.
22
Page 24
Programming Guide
PM, DEVI
<PM phase offset>
:= {0 to 360}. PM phase deviation. The unit is
"degree". Only settable when SRC is INT.
PWM, SRC
<src>
:= {INT, EXT}. PWM signal source.
PWM, FRQ
<PWM frequency>
:= PWM frequency. The unit is Hertz "Hz".
Refer to the data sheet for the range of valid
values. Only settable when SRC is INT.
PWM, DEVI
<PWM dev>
:= Duty cycle deviation. The unit is "%". Value
depends on the carrier duty cycle.
PWM, MDSP
<mod wave shape>
:= {SINE, SQUARE, TRIANGLE, UPRAMP,
DNRAMP, NOISE, ARB}.
PWM modulation wave. Only settable when
SRC is INT.
ASK, SRC
<src>
:= {INT, EXT}. ASK signal source.
ASK, KFRQ
< key frequency>
:= ASK key frequency. The unit is Hertz "Hz".
Refer to the data sheet for the range of valid
values. Only settable when SRC is INT.
FSK, SRC
<src>
:= {INT, EXT}. FSK signal source.
FSK, KFRQ
< key frequency>
:= FSK key frequency. The unit is Hertz "Hz".
Refer to the data sheet for the range of valid
values. Only settable when SRC is INT.
FSK, HFRQ
<FSK_hop_freq>
:= FSK hop frequency. The same with basic
wave frequency. The unit is Hertz "Hz". Refer
to the data sheet for the range of valid values.
PSK, SRC
<src>
:= {INT, EXT}. PSK signal source.
PSK, KFRQ
< key frequency>
:= PSK key frequency. The unit is Hertz "Hz".
Refer to the data sheet for the range of valid
values. Only settable when SRC is INT.
Read CH1 modulate wave parameters when STATE is OFF:
C1:MDWV?
Return:
C1:MDWV STATE,OFF
24
Page 26
Programming Guide
Set CH1 FM frequency to 1000 Hz:
C1:MDWV FM,FRQ,1000
Set CH1 carrier to SINE:
C1:MDWV CARR,WVTP,SINE
Set CH1 carrier frequency to 1000 Hz:
C1:MDWV CARR,FRQ,1000
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
<channel>
no
yes
yes
yes
yes
yes
<type>, SRC
no
yes
yes
yes
yes
yes
CARR, DLY
no
yes
yes
yes
yes
yes
CARR, RISE
yes
no
yes
yes
yes
yes
CARR, FALL
yes
no
yes
yes
yes
yes
DESCRIPTION
This command sets or gets the sweep parameters.
COMMAND SYNTAX
<channel>:SweepWaVe <parameter>,<value>
<channel>:={C1, C2}
<parameter>:= {a parameter from the table below}
<value>:={value of the corresponding parameter}
Parameters
Value
Description
STATE
<state>
:={ON, OFF}. Enable or disable sweep.
STATE must be set to ON before you set or read
other parameters of the sweep.
TIME
<time>
:= sweep time. The unit is seconds "s". Refer to
the data sheet for the range of valid values.
START
<start_freq>
:= start frequency. The same with basic wave
frequency. The unit is Hertz "Hz".
STOP
<stop_freq>
:= stop frequency. The same with basic wave
frequency. The unit is Hertz "Hz".
SWMD
<sweep_mode>
:= {LINE, LOG}, in which LINE refers to Linear and
Note: The table below shows the availability of some command parameters in each SDG
series.
<type>:= {AM, FM, PM, FSK, ASK, PSK, DSBAM, PWM}.
3.6 Sweep Wave Command
25
Page 27
Programming Guide
LOG refers to Logarithmic.
DIR
<direction>
:= {UP, DOWN}. Sweep direction.
TRSR
<trig_src>
:= {EXT, INT, MAN}. Trigger source. EXT refers to
External, INT refers to Internal and MAN refers to
Manual.
MTRIG
:= send a manual trigger. Only valid when TRSR
is MAN.
TRMD
<trig_mode>
:= {ON, OFF}. State of trigger output. If TRSR is
EXT, the parameter is invalid.
EDGE
<edge>
:={RISE, FALL}. Available trigger edge. Only valid
when TRSR is EXT or MAN.
CARR, WVTP
<wave type>
:= {SINE, SQUARE, RAMP, ARB}. Carrier
waveform type. Modulation is not available if the
carrier is PULSE, NOISE or DC.
CARR, FRQ
<frequency>
:= carrier frequency. The unit is Hertz "Hz". Refer
to the data sheet for the range of valid values.
CARR, PHSE
<phase>
:= {0 to 360}. Carrier phase. The unit is "degree".
CARR, AMP
<amplitude>
:= carrier amplitude. The unit is volts, peak-topeak "Vpp". Refer to the data sheet for the range
of valid values.
CARR, OFST
<offset>
:= carrier offset. The unit is volts "V". Refer to the
data sheet for the range of valid values.
CARR, SYM
<symmetry>
:= {0 to 100}. Carrier symmetry when the carrier is
RAMP. The unit is "%".
CARR, DUTY
<duty>
:= {0 to 100}. Carrier duty cycle when the carrier is
SQUARE. The unit is "%".
MARK_STATE
<state>
:= {ON, OFF}.
MARK_FREQ
<frequency>
:= mark frequency. The unit is Hertz "Hz". The
range is from the start frequency to the stop
frequency.
QUERY SYNTAX
<channel>:SWeepWaVe?
<channel>:= {C1, C2}.
RESPONSE FORMAT
<channel>:SWWV <parameter>
<parameter>:= {All parameters of the current sweep wave}
This commend sets or gets the burst wave parameters.
COMMAND SYNTAX
<channel>:BursTWaVe <parameter>,<value>
<channel>:= {C1, C2}.
<parameter>:= {a parameter from the table below}.
<value>:= {value of the corresponding parameter}.
Parameters
Value
Description
STATE
<state>
:= {ON, OFF}. Enable or disable burst.
STATE must be set to ON before you set or read other
Note: The table below shows the availability of some command parameters in each SDG
series.
3.7 Burst Wave Command
27
Page 29
Programming Guide
parameters of the burst.
PRD
<period>
:= burst period. Refer to the data sheet for the range
of valid values. The unit is seconds “s”. Not valid
when:
Carrier is NOISE
GATE_NCYC is GATE (except "X" series)
TRSR is EXT
STPS
<start_phase>
:= {0 to 360}. Start phase of the carrier. The unit is
"degree". Not valid when the carrier is NOISE or
PULSE.
GATE_NCYC
<burst_mode>
:= {GATE, NCYC}. Burst mode. Not valid when the
carrier is NOISE.
TRSR
<trig_src>
:= {EXT, INT, MAN}. Trigger source. EXT refers to
External, INT refers to Internal and MAN refers to
Manual.
MTRIG
:= send a manual trigger. Only when TRSR is MAN,
the parameter is valid.
DLAY
<delay>
:= trigger delay. The unit is seconds "s". Refer to the
data sheet for the range of valid values. Available
when GATE_NCYC is NCYC. Not valid when the
carrier is NOISE.
PLRT
<polarity>
:= {NEG, POS}. Gate polarity. Negative or Positive.
TRMD
<trig_mode>
:= {RISE, FALL, OFF}. Trigger out mode. Available
when GATE_NCYC is NCYC and TRSR is INT or
MAN. Not valid when the carrier is NOISE.
EDGE
<edge>
:={RISE, FALL}. Available trigger edge. Only valid
when TRSR is EXT or MAN.
EDGE
<edge>
:= { RISE, FALL}. Available trigger edge. Available
when GATE_NCYC is NCYC and TRSR is EXT. Not
valid when the carrier is NOISE.
TIME
<circle_ time>
:={INF, 1, 2,..., M}, where M is the maximum
supported Ncycle number which depends on the
model; INF sets the burst to Infinite mode.
Available when GATE_NCYC is NCYC. Not valid
when the carrier is NOISE.
This command copies parameters from one channel to another.
COMMAND SYNTAX
ParaCoPy <destination_channel>,<src_channel>
< destination_channel>:= {C1, C2}.
<src_channel>:= {C1, C2}.
Note: the parameters C1 and C2 must be set to the device
together.
EXAMPLE
Copy parameters from CH1 to CH2.
PACP C2,C1
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
PACP
no
yes
yes
yes
yes
yes
DESCRIPTION
This command sets and gets the arbitrary waveform type.
Note: The index number in the command syntax and the response
Note: The table below shows the availability of some command parameters in each SDG
series.
3.8 Parameter Copy Command
Note: The table below shows the availability of the command in each SDG series.
3.9 Arbitrary Wave Command
30
Page 32
Programming Guide
format of query omit the character ‘M’, and directly uses the value
to represent the index number.
COMMAND SYNTAX
<channel>:ArbWaVe INDEX,<index>
<channel>:ArbWaVe NAME,<name>
<channel>:= {C1, C2}.
<index>: the index of the arbitrary waveform from the table below.
<name>: the name of the arbitrary waveform from the table below.
.QUERY SYNTAX
<channel>:ARbWaVe?
<channel>:= {C1, C2}.
RESPONSE FORMAT
<channel>:ARWV INDEX,<index>,NAME,<name>
EXAMPLE
Set CH1 current waveform by index 2:
C1:ARWV INDEX,2
Read CH1 current waveform:
C1:ARWV?
Return:
C1:ARWV INDEX,2,NAME,StairUp
Set CH1 current waveform to wave_1 by name.
C1:ARWV NAME,wave_1
RELATED COMMANDS
STL
Index
Name
Index
Name
Index
Name
Index
Name
0
Sine
12
Logfall
24
Gmonopuls
36
Triang
1
Noise
13
Logrise
25
Tripuls
37
Harris
2
StairUp
14
Sqrt
26
Cardiac
38
Bartlett
3
StairDn
15
Root3
27
Quake
39
Tan
4
Stairud
16
X^2
28
Chirp
40
Cot
5
Ppulse
17
X^3
29
Twotone
41
Sec
6
Npulse
18
Sinc
30
Snr
42
Csc
7
Trapezia
19
Gaussian
31
Hamming
43
Asin
8
Upramp
20
Dlorentz
32
Hanning
44
Acos
9
Dnramp
21
Haversine
33
Kaiser
45
Atan
10
Exp_fall
22
Lorentz
34
Blackman
46
Acot
11
Exp_rise
23
Gauspuls
35
Gausswin
47
Square
Note: This table is just an example, the index depends on the specific model. The “STL?”
command can be used to get the accurate mapping relationship between the index and
name.
This command sets and gets the arbitrary waveform data.
COMMAND SYNTAX
<channel>:WVDT <index>,<parameter>,<value>
<channel>:= {C1, C2}.
<index>:= {Mn}. The waveform index. See note 2 below for the
details.
<parameter>:= {a parameter from the table below}.
<value>:= {value of the corresponding parameter}.
Parameters
Value
Description
WVNM
<wave_name>
:= waveform name.
TYPE
<type>
:= {0 to 5}
0 - common
1 - math
2 - engineering
3 - window
4 - triangle function
5 - user defined
This parameter is not valid for the “X” series.
Note: The table below shows the availability of some command parameters in each SDG
series.
3.22 Arb Data Command
42
Page 44
Programming Guide
LENGTH
<length>
:= the number of waveform bytes, the valid range
depends on the model. See note 1 below for the
details.
This parameter is not necessary in the “X” series
FREQ
<frequency>
:= frequency. The unit is Hertz “Hz”.
AMPL
<amplifier>
:= amplitude. The unit is volts, peak-to-peak “Vpp”.
OFST
<offset>
:= offset. The unit is volts “V”.
PHASE
<phase>
:= phase. The unit is "degree".
WAVEDATA
<wave data>
:= waveform data.
The wave data needs to be read from a waveform file
QUERY SYNTAX
Format 1: WVDT? Mn
Format 2: WVDT? USER,<wave_name>
<wave name>:={The name of user defined waveform}.
0<=n<=196.
M0~M196: build-in (32KB).
Not necessary when sending waveform data.
SDG6000X/X-E
0<=n<=196.
M0~M196: build-in (32KB).
Not necessary when sending waveform data.
DESCRIPTION
This command is used to simulate pressing a key on the front panel.
COMMAND SYNTAX
VirtualKEY VALUE,<value>,STATE,<state>
<value>:= {a Name or Index of the virtual keys from the table below}.
<state>:= {0,1}, where “1” is effective to virtual value, and “0” is
useless.
Name
Index
Name
Index
KB_FUNC1
28
KB_NUMBER_4
52
KB_FUNC2
23
KB_NUMBER_5
53
KB_FUNC3
18
KB_NUMBER_6
54
KB_FUNC4
13
KB_NUMBER_7
55
KB_FUNC5
8
KB_NUMBER_8
56
KB_FUNC6
3
KB_NUMBER_9
57
KB_SINE
34
KB_POINT
46
KB_SQUARE
29
KB_NEGATIVE
43
KB_ RAMP
24
KB_LEFT
44
KB_PULSE
19
KB_RIGHT
40
KB_NOISE
14
KB_UP
45
KB_ARB
9
KB_DOWN
39
KB_MOD
15
KB_OUTPUT1
153
KB_SWEEP
16
KB_OUTPUT2
152
KB_BURST
17
KB_KNOB_RIGHT
175
KB_WAVES
4
KB_KNOB_LEFT
177
KB_UTILITY
11
KB_KNOB_DOWN
176
KB_PARAMETER
5
KB_HELP
12
KB_STORE_RECALL
70
KB_CHANNEL
72
3.23 Virtual Key Command
Programming Guide
44
Page 46
Programming Guide
KB_NUMBER_0
48
KB_NUMBER_1
49
KB_NUMBER_2
50
KB_NUMBER_3
51
Keys and Indices on the SDG1000X/SDG2000X/SDG6000X/SDG6000X-E
Keys and Indices on the SDG5000
45
Page 47
Programming Guide
Keys and Indices on the SDG1000/SDG800
EXAMPLE
VKEY VALUE,15,STATE,1
VKEY VALUE,KB_SWEEP,STATE,1
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
KB_FUNC6
no
no
yes
yes
yes
yes
KB_STORE_RECAL
L
yes
yes
yes
no
yes
yes
KB_HELP
yes
yes
no
no
no
no
KB_CHANNEL
no
yes
yes
no
yes
yes
KB_SINE
yes
yes
no
no
no
no
KB_SQUARE
yes
yes
no
no
no
no
KB_ RAMP
yes
yes
no
no
no
no
KB_PULSE
yes
yes
no
no
no
no
KB_NOISE
yes
yes
no
no
no
no
KB_ARB
yes
yes
no
no
no
no
KB_UP
yes
yes
no
no
no
no
KB_DOWN
yes
yes
no
no
no
no
DESCRIPTION
This command sets and gets the system IP address.
Note: The table below shows the availability of some command parameters in each SDG
series.
<parameter1>:={an integer value between 1 and 223}.
<parameter2>:={an integer value between 0 and 255}.
<parameter3>:={an integer value between 0 and 255}.
<parameter4>:={an integer value between 0 and 255}.
QUERY SYNTAX
SYSTem:COMMunicate:LAN:IPADdress?
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
SYST:COMM:LAN:I
PAD
no
no
yes
no
yes
yes
DESCRIPTION
This command sets and gets the system subnet mask.
<parameter1>:={an integer value between 0 and 255}.
<parameter2>:={an integer value between 0 and 255}.
<parameter3>:={an integer value between 0 and 255}.
<parameter4>:={an integer value between 0 and 255}.
QUERY SYNTAX
SYSTem:COMMunicate:LAN:SMASk?
EXAMPLES Set IP address to 10.11.13.203:
SYST:COMM:LAN:IPAD “10.11.13.203”
Get the IP address:
SYST:COMM:LAN:IPAD?
Return:
“10.11.13.203”
Note: The table below shows the availability of the command in each SDG series.:
<parameter1>:={an integer value between 0 and 223}.
<parameter2>:={an integer value between 0 and 255}.
<parameter3>:={an integer value between 0 and 255}.
<parameter4>:={an integer value between 0 and 255}.
QUERY SYNTAX
SYSTem:COMMunicate:LAN:GATeway?
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
SYST:COMM:LAN:G
AT
no
no
yes
no
yes
yes
DESCRIPTION
This command sets or gets the Arb mode, sampling rate and
SYST:COMM:LAN:SMAS?
Return:
“255.0.0.0”
Note: The table below shows the availability of the command in each SDG series.
3.26 Gateway Command
EXAMPLES Set Gateway to 10.11.13.5:
SYSTem:COMMunicate:LAN:GATeway “10.11.13.5”
Get gateway:
SYSTem:COMMunicate:LAN:GATeway?
Return:
“10.11.13.5”
Note: The table below shows the availability of the command in each SDG series.
3.27 Sampling Rate Command
48
Page 50
Programming Guide
interpolation method. Sampling rate and interpolation method can only
be set when MODE is TARB.
<channel>:= <C1, C2>.
<mode>:= {DDS, TARB}, where TARB is TrueArb.
<sample rate>:= sample rate. The unit is Sa/s.
<interpolation>:= {LINE, HOLD, SINC, SINC27, SINC13}, where LINE
is linear, and HOLD is zero-order hold. SINC, SINC27 and SINC13
are only for SDG6000X/X-E.
QUERY SYNTAX
<channel>:SRATE?
EXAMPLES
Get the sampling rate of CH1:
C1:SRATE?
Return:
C1:SRATE MODE,DDS
Set CH1 to TureArb mode:
C1:SRATE MODE,TARB
Set sampling rate of CH1 to 1000000Sa/s:
C1:SRATE VALUE,1000000
Set CH1 to TureArb mode and set interpolation to SINC13
C1:SRATE MODE,TARB,INTER,SINC13
Parameter
/command
SDG800
SDG1000
SDG2000X
SDG5000
SDG1000X
SDG6000X
/X-E
SRATE
no
no
yes
no
no
yes
INTER
no
no
no
no
no
yes
DESCRIPTION
This command sets or gets the harmonic parameters. Only available
when the basic wave is SINE.
COMMAND SYNTAX
<channel>:HARMonic HARMSTATE,<state>,HARMTYPE,
Note: The table below shows the availability of the command and some parameters in each
SDG series.
<state>:= <ON, OFF>.
<type>:= <EVEN, ODD, ALL>.
<order>:= {1,2,...,M}, where M is the supported maximum order.
<unit>:= < HARMAMP, HARMDBC>.
<value>:= amplitude of specified harmonic. The range of valid values
depends on the model. When <unit>= HARMAMP, the unit is volts,
peak-to-peak “Vpp”, and when <unit>= HARMDBC, the unit is "dBc".
<phase>:= {0~360}, the unit is "degree"
This command set up synchronization between two or more
instruments and achieve in-phase output
COMMAND SYNTAX
CASCADE STATE,ON|OFF,MODE,<MODE>,DELAY,<DELAY>
Note: The table below shows the availability of the command in each SDG series.
3.30 Mode Select Command
Note: The table below shows the availability of the command in each SDG series.
3.31 Multi-Device Sync
51
Page 53
<MODE>:={MASTER,SLAVE}
<DELAY>:={0-0.000025},UNIT=s,This parameter can only be set
in slave mode
QUERY SYNTAX
CASCADE?
RESPONSE FORMAT
Return from SLAVE MODE :
CASCADE STATE,ON,MODE,SLAVE,DELAY, <DELAY>
Return from MASTER mode :
CASCADE STATE,ON,MODE,MASTER
EXAMPLE
Set the device as slave and the delay to 0.0000001s:
CASCADE STATE,ON,MODE,SLAVE,DELAY,0.0000001
Parameter
/command
SDG800
SDG1000
SDG2000
X
SDG5000
SDG1000
X
SDG6000
X
SDG6000
X-E
IQ
no
no
no
no
no
yes
no
DESCRIPTION
This command sets center frequency of the I/Q modulator.
COMMAND SYNTAX
[:SOURce]:IQ:CENTerfreq <center_freq><unit>
<center_freq>:= the center frequency. Refer to the data sheet for
the range of valid values.
<unit>:= {Hz, kHz, MHz, GHz}. The default unit is Hertz “Hz”.
QUERY SYNTAX
[:SOURce]:IQ:CENTerfreq?
RESPONSE FORMAT
<center_freq> (expressed in Hz.)
EXAMPLE
Set the center frequency to 1 kHz:
:SOURce:IQ:CENTerfreq 1000Hz
3.32 IQ Commands
Programming Guide
The table below shows the availability of IQ commands in each SDG series.
3.32.1 :IQ:CENTerfreq
52
Page 54
Programming Guide
DESCRIPTION
This command sets the I/Q sampling rate.
COMMAND SYNTAX
[:SOURce]:IQ:SAMPlerate <sample_rate><unit>
<sample_rate>:= sample rate. Refer to the data sheet for the
range of valid values.
<unit>:= {Hz, kHz, MHz, GHz}. The default unit is Hertz “Hz”.
QUERY SYNTAX
[:SOURce]:IQ:SAMPlerate?
RESPONSE FORMAT
<sample_rate> (expressed in Hz.)
EXAMPLE
Set the sample rate to 100 kHz:
:IQ:SAMPlerate 1000000
or:
:IQ:SAMP 100kHz
DESCRIPTION
This command sets the I/Q symbol rate.
COMMAND SYNTAX
[:SOURce]:IQ:SYMBolrate <symb_rate><unit>
<symb_rate>:= symbol rate. Refer to the data sheet for the range
of valid values.
<unit>:= {S/s, kS/s, MS/s}. The default unit is symbols-per-second
“S/s”.
QUERY SYNTAX
[:SOURce]:IQ:SYMBolrate?
RESPONSE FORMAT
<symb_rate> (expressed in S/s.)
EXAMPLE
Set the symbol rate to 1 MS/s:
:IQ:SYMB 1MS/s
DESCRIPTION
This command sets the I/Q amplitude.
COMMAND SYNTAX
[:SOURce]:IQ:AMPLitude <amplitude><unit>
<amplitude>:= amplitude. Refer to the data sheet for the range of
valid values.
3.32.2 :IQ:SAMPlerate
3.32.3 :IQ:SYMBolrate
3.32.4 :IQ:AMPLitude
53
Page 55
<unit>:= {Vrms, mVrms, dBm}. The default unit is volts, rootmean-square “Vrms”.
QUERY SYNTAX
[:SOURce]:IQ:AMPLitude?
RESPONSE FORMAT
<amplitude> (expressed Vrms.)
EXAMPLE
Set the I/Q amplitude (sqrt(I2+Q2)) to 0.2 Vrms:
:IQ:AMPL 0.2
DESCRIPTION
This command adjusts the ratio of I to Q while preserving the
composite.
COMMAND SYNTAX
[:SOURce]:IQ:IQADjustment:GAIN <gain_ratio>
<gain_ratio>:= Gain ratio of I to Q. The default unit is dB.
QUERY SYNTAX
[:SOURce]:IQ:IQADjustment:GAIN?
RESPONSE FORMAT
<gain_ratio> (expressed in unit of dB.)
EXAMPLE
Set the gain ratio of I/Q to 0.1dB:
:IQ:IQADjustment:GAIN 0.1
DESCRIPTION
This command adjusts the I channel offset value.
COMMAND SYNTAX
[:SOURce]:IQ:IQADjustment:IOFFset <offset><unit>
<offset>:= I offset.
<unit>:= {V, mV, uV}. The default unit is volts “V”.
QUERY SYNTAX
[:SOURce]:IQ:IQADjustment:IOFFset?
RESPONSE FORMAT
<offset> (expressed V.)
EXAMPLE
Set the I offset to 1 mV:
:IQ:IQADjustment:IOFFset 1mV
3.32.5 :IQ:IQADjustment:GAIN
Programming Guide
3.32.6 :IQ:IQADjustment:IOFFset
54
Page 56
Programming Guide
DESCRIPTION
This command adjusts the Q channel offset value.
COMMAND SYNTAX
[:SOURce]:IQ:IQADjustment:QOFFset <offset><unit>
<offset>:= Q offset.
<unit>:= {V, mV, uV}. The default unit is volts “V”.
QUERY SYNTAX
[:SOURce]:IQ:IQADjustment:QOFFset?
RESPONSE FORMAT
<offset> (expressed in V.)
EXAMPLE
Set the Q offset to -1 mV:
:IQ:IQAD:QOFF -0.001V
DESCRIPTION
This command adjusts the phase angle (quadrature skew)
between the I and Q vectors by increasing or decreasing the
Q phase angle.
COMMAND SYNTAX
[:SOURce]:IQ:IQADjustment:QSKew <angle>
<angle>:= angle. The unit is degree.
This chapter gives some examples for the programmer. In these examples you can see
how to use VISA or sockets, in combination with the commands described above to control
the generator. By following these examples, you can develop many more applications.
4.1 Examples of Using VISA
4.1.1 VC++ Example
Environment: Windows 7 32-bit, Visual Studio.
Description: Query the instrument information using "*IDN?" command over NI-VISA,
with the access through USBTMC and TCP/IP separately.
Steps:
1. Open Visual Studio, create a new VC++ win32 console project.
2. Set the project environment to use the NI-VISA lib, there are two ways to specify
NI-VISA, static or automatic:
a) Static:
Find the files visa.h, visatype.h and visa32.lib in NI-VISA installation path, copy
them to the root path of the VC++ project, and add them into the project. In the
projectname.cpp file, add the following two lines:
In "project---properties---c/c++---General---Additional Include Directories" set
the value to the NI-VISA installation path (e.g. C:\Program Files\IVI
Foundation\VISA\WinNT\include), as shown in the figure below:
58
Page 60
Programming Guide
In " project---properties---Linker---General---Additional Library Directories " set
the value to the NI-VISA installation path (e.g. C:\Program Files\IVI
Foundation\VISA\WinNT\include), as shown in the figure below:
In "project---properties---Linker---Command Line---Additional" set the value to
visa32.lib, as shown in the figure below:
/** First we must call viOpenDefaultRM to get the manager
* handle. We will store this handle in defaultRM.*/
status=viOpenDefaultRM (&defaultRM);
if (status<VI_SUCCESS)
{
printf ("Could not open a session to the VISA Resource Manager!\n");
returnstatus;
}
/* 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, &numInstrs,
instrResourceString);
if (status<VI_SUCCESS)
{
printf ("An error occurred while finding resources.\nPress 'Enter' to
continue.");
fflush(stdin);
getchar();
viClose (defaultRM);
returnstatus;
}
/** Now we will open VISA sessions to all USB TMC instruments.
* We must use the handle from viOpenDefaultRM and we must
* also use a string that indicates which instrument to open. This
* is called the instrument descriptor. The format for this string
* can be found in the function panel by right clicking on the
* descriptor parameter. After opening a session to the
* device, we will get a handle to the instrument which we
* will use in later VISA functions. The AccessMode and Timeout
* parameters in this function are reserved for future
* functionality. These two parameters are given the value VI_NULL.*/
for (i=0; i<int(numInstrs); i++)
{
if (i> 0)
{
viFindNext (findList, instrResourceString);
}
status = viOpen (defaultRM, instrResourceString, VI_NULL, VI_NULL,
61
Page 63
Programming Guide
&instr);
if (status<VI_SUCCESS)
{
printf ("Cannot open a session to the device %d.\n", i+1);
continue;
}
/* * At this point we now have a session open to the USB TMC instrument.
* We will now use the viPrintf function to send the device the string
"*IDN?\n",
* asking for the device's identification. */
char * cmmand ="*IDN?\n";
status = viPrintf (instr, cmmand);
if (status<VI_SUCCESS)
{
printf ("Error writing to the device %d.\n", i+1);
status = viClose (instr);
continue;
}
/** Now we will attempt to read back a response from the device to
* the identification query that was sent. We will use the viScanf
* function to acquire the data.
* After the data has been read the response is displayed.*/
status = viScanf(instr, "%t", buffer);
if (status<VI_SUCCESS)
{
printf ("Error reading a response from the device %d.\n", i+1);
}
else
{
printf ("\nDevice %d: %s\n", i+1 , buffer);
}
status = viClose (instr);
}
/** Now we will close the session to the instrument using
* viClose. This operation frees all system resources. */
status = viClose (defaultRM);
printf("Press 'Enter' to exit.");
fflush(stdin);
getchar();
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
62
Page 64
Programming Guide
{
Usbtmc_test();
return 0;
}
Run result:
b) TCP/IP:
int TCP_IP_Test(char *pIP)
{
char outputBuffer[VI_FIND_BUFLEN];
ViSession defaultRM, instr;
ViStatus status;
/* First we will need to open the default resource manager. */
status = viOpenDefaultRM (&defaultRM);
if (status<VI_SUCCESS)
{
printf("Could not open a session to the VISA Resource Manager!\n");
}
/* Now we will open a session via TCP/IP device */
char head[256] ="TCPIP0::";
char tail[] ="::INSTR";
strcat(head,pIP);
strcat(head,tail);
status = viOpen (defaultRM, head, VI_LOAD_CONFIG, VI_NULL, &instr);
if (status<VI_SUCCESS)
{
printf ("An error occurred opening the session\n");
viClose(defaultRM);
}
status = viPrintf(instr, "*idn?\n");
status = viScanf(instr, "%t", outputBuffer);
if (status<VI_SUCCESS)
63
Page 65
Programming Guide
{
printf("viRead failed with error code: %x \n",status);
viClose(defaultRM);
}
else
{
printf ("\nMesseage read from device: %*s\n", 0,outputBuffer);
}
status = viClose (instr);
status = viClose (defaultRM);
printf("Press 'Enter' to exit.");
fflush(stdin);
getchar();
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
printf("Please input IP address:");
char ip[256];
fflush(stdin);
gets(ip);
TCP_IP_Test(ip);
return 0;
}
Run result:
64
Page 66
Programming Guide
4.1.2 VB Example
Environment: Windows 7 32-bit, Microsoft Visual Basic 6.0
Description: Query the instrument information using "IDN?" command over NI-VISA,
with the access through USBTMC and TCP/IP separately.
Steps:
1. Open Visual Basic, and build a standard application program project.
2. Set the project environment to use the NI-VISA lib: Click the Existing tab of
Project>>Add Existing Item, search the visa32.bas file in the "include" folder under
the NI-VISA installation path and add the file, as shown in the figure below:
3. Coding:
a) USBTMC:
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
65
Page 67
Programming Guide
' 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
' Now we will open VISA sessions to all USB TMC instruments. ' We must use the handle from viOpenDefaultRM and we must ' also use a string that indicates which instrument to open. This ' is called the instrument descriptor. The format for this string ' can be found in the function panel by right clicking on the ' descriptor parameter. After opening a session to the ' device, we will get a handle to the instrument which we ' will use in later VISA functions. The AccessMode and Timeout ' parameters in this function are reserved for future ' functionality. These two parameters are given the value VI_NULL.
66
Page 68
Programming Guide
For i = 0 To numInstrs
If (i > 0) Then
status = viFindNext(findList, instrResourceString)
EndIf
status = viOpen(defaultRM, instrResourceString, VI_NULL, VI_NULL, instrsesn)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Cannot open a session to the device " + CStr(i + 1)
GoTo NextFind
EndIf
' At this point we now have a session open to the USB TMC instrument. ' We will now use the viWrite function to send the device the string "*IDN?", ' asking for the device's identification.
status = viWrite(instrsesn, "*IDN?", 5, retCount)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Error writing to the device."
status = viClose(instrsesn)
GoTo NextFind
EndIf
' Now we will attempt to read back a response from the device to ' the identification query that was sent. We will use the viRead ' function to acquire the data. ' After the data has been read the response is displayed.
status = viRead(instrsesn, Buffer, MAX_CNT, retCount)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Error reading a response from the device." + CStr(i + 1)
Else
resultTxt.Text = "Read from device: " + CStr(i + 1) + " " + Buffer
EndIf
status = viClose(instrsesn)
Next i
' Now we will close the session to the instrument using ' viClose. This operation frees all system resources.
status = viClose(defaultRM)
Usbtmc_test = 0
EndFunction
b) TCP/IP:
PrivateFunction TCP_IP_Test(ByVal ip AsString) AsLong
Dim outputBuffer AsString * VI_FIND_BUFLEN
67
Page 69
Programming Guide
Dim defaultRM AsLong Dim instrsesn AsLong Dim status AsLong Dim count AsLong
' First we will need to open the default resource manager.
status = viOpenDefaultRM(defaultRM)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Could not open a session to the VISA Resource Manager!"
TCP_IP_Test = status
ExitFunction EndIf
' Now we will open a session via TCP/IP device
status = viOpen(defaultRM, "TCPIP0::" + ip + "::INSTR", VI_LOAD_CONFIG, VI_NULL,
instrsesn)
If (status < VI_SUCCESS) Then
resultTxt.Text = "An error occurred opening the session"
viClose(defaultRM)
TCP_IP_Test = status
ExitFunction EndIf
status = viWrite(instrsesn, "*IDN?", 5, count)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Error writing to the device."
EndIf
status = viRead(instrsesn, outputBuffer, VI_FIND_BUFLEN, count)
If (status < VI_SUCCESS) Then
resultTxt.Text = "Error reading a response from the device." + CStr(i + 1)
Else
resultTxt.Text = "read from device:" + outputBuffer
EndIf
status = viClose(instrsesn)
status = viClose(defaultRM)
TCP_IP_Test = 0
EndFunction
c) Button control code:
PrivateSub exitBtn_Click()
End
68
Page 70
Programming Guide
EndSub
PrivateSub tcpipBtn_Click()
Dim stat AsLong
stat = TCP_IP_Test(ipTxt.Text)
If (stat < VI_SUCCESS) Then
resultTxt.Text = Hex(stat)
EndIf
EndSub
PrivateSub usbBtn_Click()
Dim stat AsLong
stat = Usbtmc_test
If (stat < VI_SUCCESS) Then
resultTxt.Text = Hex(stat)
EndIf
EndSub
Run result:
69
Page 71
Programming Guide
4.1.3 MATLAB Example
Environment: Windows 7 32-bit, MATLAB R2013a
Description: Query the instrument information using "IDN?" command over NI-VISA,
with the access through USBTMC and TCP/IP separately.
Steps:
1. Open MATLAB, and modify the current directory. In this demo, the current directory
is modified to "D:\USBTMC_TCPIP_Demo".
2. Click File>>New>>Script in the Matlab interface to create an empty M file.
3. Coding:
a) USBTMC:
function USBTMC_test()
% This code demonstrates sending synchronous read & write commands
% to an USB Test & Measurement Class (USBTMC) instrument using
% NI-VISA
%Create a VISA-USB object connected to a USB instrument
vu = visa('ni','USB0::0xF4ED::0xEE3A::sdg2000x::INSTR');
%Open the VISA object created
fopen(vu);
%Send the string "*IDN?",asking for the device's identification.
fprintf(vu,'*IDN?');
%Request the data
outputbuffer = fscanf(vu);
disp(outputbuffer);
%Close the VISA object
fclose(vu);
delete(vu);
clear vu;
end
70
Run result:
Page 72
Programming Guide
b) TCP/IP:
Write a function TCP_IP_Test:
function TCP_IP_test()
% This code demonstrates sending synchronous read & write commands
% to an TCP/IP instrument using NI-VISA
%Create a VISA-TCPIP object connected to an instrument
%configured with IP address.
%Send the string "*IDN?",asking for the device's identification.
fprintf(vt,'*IDN?');
%Request the data
outputbuffer = fscanf(vt);
disp(outputbuffer);
%Close the VISA object
fclose(vt);
delete(vt);
clear vt;
end
Run result:
71
Page 73
Programming Guide
4.1.4 LabVIEW Example
Environment: Windows 7 32-bit, LabVIEW 2011
Description: Query the instrument information using "IDN?" command over NI-VISA,
with the access through USBTMC and TCP/IP separately.
Steps:
1. Open LabVIEW, and create a VI file.
2. Add controls. Right-click in the Front Panel interface, select and add VISA
resource name, error in, error out and some indicators from the Controls column.
3. Open the Block Diagram interface. Right-click on the VISA resource name,
select and add the following functions from VISA Palette from the pop-up menu:
VISA Write, VISA Read, VISA Open and VISA Close.
4. The connection is as shown in the figure below:
5. Select the device resource from the VISA Resource Name list box and run the
program.
In this example, the VI opens a VISA session to a USBTMC device, writes a "IDN?"
command to the device, and reads back the response. After all communication is
complete, the VI closes the VISA session.
72
Page 74
Programming Guide
6. Communicating with the device via TCP/IP is similar to USBTMC. But you need to
change VISA Write and VISA Read Function to Synchronous I/O. The LabVIEW
default is asynchronous I/O. Right-click the node and select Synchronous I/O
Mod>>Synchronous from the shortcut menu to write or read data synchronously.
7. The connection is as shown in the figure below:
8. Input the IP address and run the program.
73
Page 75
Programming Guide
4.1.5 Python Example
Environment: Python2.7, PyVISA 1.4
(Please install PyVISA after installing Python2.7. Please refer to
https://pyvisa.readthedocs.io/en/stable/getting.html for PyVISA installation guide.
Description: Use Python script to build an 8-point 16-bit arbitrary waveform (0x1000,
0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x7fff) and save the waveform
data in "wave1.bin", then download it to the instrument, finally read it back from the
instrument and save it as "wave2.bin".
Below is the code of the script:
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import visa
import time
import binascii
#USB resource of Device
device_resource = "USB0::0xF4EC::0x1101::#15::INSTR"
def create_wave_file():
"""create a file"""
f = open("wave1.bin", "wb")
for a in wave_points:
b = hex(a)
b = b[2:]
len_b = len(b)
if (0 == len_b):
b = '0000'
elif (1 == len_b):
b = '000' + b
elif (2 == len_b):
b = '00' + b
elif (3 == len_b):
74
Page 76
Programming Guide
b = '0' + b
c = binascii.a2b_hex(b) #Hexadecimal integer to ASCii encoded string
f.write(c)
f.close()
def send_wawe_data(dev):
"""send wave1.bin to the device"""
f = open("wave1.bin", "rb") #wave1.bin is the waveform to be sent
data = f.read()
print 'write bytes:',len(data)
dev.write("C1:WVDT
WVNM,wave1,FREQ,2000.0,AMPL,4.0,OFST,0.0,PHASE,0.0,WAVEDATA,%s" % (data))
#"X" series (SDG1000X/SDG2000X/SDG6000X/X-E)
dev.write("C1:ARWV NAME,wave1")
f.close()
def get_wave_data(dev):
"""get wave from the devide"""
f = open("wave2.bin", "wb") #save the waveform as wave2.bin
dev.write("WVDT? user,wave1") #"X" series (SDG1000X/SDG2000X/SDG6000X/X-E)
time.sleep(1)
data = dev.read()
data_pos = data.find("WAVEDATA,") + len("WAVEDATA,")
print data[0:data_pos]
wave_data = data[data_pos:]
print 'read bytes:',len(wave_data)
f.write(wave_data)
f.close()
Python has a low-level networking module that provides access to the socket interface.
Python scripts can be written for sockets to do a variety of tests and measurement tasks.
Environment: Windows 7 32-bit, Python v2.7.5
Description: Open a socket, send a query, and repeat this loop for 10 times, finally close
the socket. Note that SCPI command strings must be terminated with a “\n” (new line)
character in programming.
Below is the code of the script:
#!/usr/bin/env python
#-*- coding:utf-8 –*#----------------------------------------------------------------------------# The short script is a example that open a socket, sends a query,
# print the return message and closes the socket.
#-----------------------------------------------------------------------------
import socket # for sockets
import sys # for exit
import time # for sleep
remote_ip = "10.11.13.40" # should match the instrument’s IP address
port = 5025 # the port number of the instrument service
count = 0
def SocketConnect():
try:
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print ('Failed to create socket.')
sys.exit();
try:
#Connect to remote server
s.connect((remote_ip , port))
except socket.error:
print ('failed to connect to ip ' + remote_ip)
def SocketClose(Sock):
#close the socket
Sock.close()
time.sleep(.300)
def main():
global remote_ip
global port
global count
# Body: send the SCPI commands *IDN? 10 times and print the return message
s = SocketConnect()
for i in range(10):
qStr = SocketQuery(s, b'*IDN?\n')
print (str(count) + ":: " + str(qStr))
count = count + 1
SocketClose(s)
input('Press "Enter" to exit')