4.1 Examples of Using VISA ...................................................................... 56
4.1.1 Example of VC++ ............................................................................................... 56
4.1.2 Example of VB ................................................................................................... 60
4.1.3 Example of MATLAB .......................................................................................... 63
4.1.4 Example of LabVIEW ......................................................................................... 64
4.2 Examples of Using Socket .................................................................. 66
4.2.1 Example of Python ............................................................................................. 66
4.2.2 Example of Telnet............................................................................................... 68
SSG3000X Programming Guide 3
SIGLENT
1.Programming Overview
SSG3000X support both USB and LAN interfaces. By using these interfaces, in combination
with NI-VISA and programming languages, users can remotely control the signal generator.
Through LAN interface, VXI-11, Sockets and Telnet protocols can be used to communicate
with the signal generator. This chapter introduces how to build communication between the
signal generator and the PC. It also introduces the remote control capabilities.
1.1 Build Communication
1.1.1 Build Communication Using VISA
1、 Install NI-VISA
Before programming, you need to install NI-VISA, which you can download from the NI-VISA
web site. About NI-VISA, there are full version and Run-Time Engine version. The full version
includes the NI device driver and a tool named NI MAX that is a user interface to control the
device. The Run-Time Engine version which is much smaller than the full version only
include NI device driver.
For example, you can get NI-VISA 5.4 full version from: http://www.ni.com/download/ni-visa-
5.4/4230/en/.
You can also download NI-VISA Run-Time Engine 5.4 to your PC and install it as default
selection. Its installation process is similar with the full version.
After you downloaded the file you can follow the steps below to install it:
a. Double click the visa540_full.exe, dialog shown as below:
b. Click Unzip, the installation process will automatically launch after unzipping files. If your
computer needs to install .NET Framework 4, its setup process will auto start.
4 SSG3000X Programming Guide
SIGLENT
c. The NI-VISA installing dialog is shown above. Click Next to start the installation process.
Set the install path, default path is “C:\Program Files\National Instruments\”, you can
change it. Click Next, dialog shown as above.
d. Click Next twice, in the License Agreement dialog, select the “ I accept the above 2 License
Agreement(s).” ,and click Next, dialog shown as below:
SSG3000X Programming Guide 5
SIGLENT
e. Click Next to run installation.
Now the installation is complete, reboot your PC.
2、 Connect the Instrument
Depending on your specific model your signal generator may be able to communicate with a
PC through the USB or LAN interface. This manual takes the USB as an example. (For
instructions to communicate with a PC through the LAN interface see the User Manual.)
a. Connect the USB Device interface at the rear panel of the signal generator and the USB
Host interface of the PC using a USB cable. Assuming your PC is already turned on, turn on
your signal generator and your PC will display the “Device Setup” screen as it automatically
installs the device driver as shown below.
b. Wait for the installation to complete and then proceed to the next step.
6 SSG3000X Programming Guide
SIGLENT
1.1.2 Build Communication Using Sockets
Sockets LAN is a method used to communicate with the signal generator over the LAN
interface using the Transmission Control Protocol/Internet Protocol (TCP/IP). A socket is a
fundamental technology used for computer networking and allows applications to
communicate using standard mechanisms built into network hardware and operating
systems. The method accesses a port on the signal generator from which bidirectional
communication with a network computer can be established.
Before you can use sockets LAN, you must select the signal generator’s sockets port number
to use:
Standard mode. Available on port 5025. Use this port for simple programming.
Telnet mode. The telnet SCPI service is available on port 5024.
1.1.3 Connecting the signal generator via the USB
Host port
Refer to the following steps to finish the connection via USB:
1. Install NI-VISA on your PC for GPIB driver.
2. Connect the signal generator USB Host port to a PC’s GPIB card port, with SIGLENT
USB-GPIB adaptor.
3. Switch on the signal generator
4. Press button on the front panel System→Interface→GPIB to enter the GPIB number.
The signal generator will be detected automatically as a new GPIB point.
1.2 Remote Control Capabilities
1.2.1 User-defined Programming
Users can use SCPI commands to program and control the signal generator. For details,
refer to the introductions in “Programming Examples”.
1.2.2 Send SCPI Commands via NI-MAX
Users can control the signal generator remotely by sending SCPI commands via NI-MAX
software.
1.2.2.1 Using USB
Run NI MAX software.
1, Click “Device and interface” at the upper left corner of the software;
2, Find the “USBTMC” device symbol;
SSG3000X Programming Guide 7
SIGLENT
3, Click “Open VISA Test Panel” option button, then the following interface will appear;
4, Click the “Input/Output” option button and click the “Query” option button in order to view
the operation information.
NOTE: The *IDN? command (known as the Identification Query) returns the instrument
manufacturer, instrument model, serial number, and other identification information.
1.2.2.2 Using LAN
Add Network Device, and select VISA TCP/IP Resource as shown:.
Run NI MAX software.
1, Click “Device and interface” at the upper left corner of the software;
2, Find the “Network Devices” symbol, click “Add Network Devices”;
8 SSG3000X Programming Guide
SIGLENT
3. Select Manual Entry of LAN instrument, select Next, and enter the IP address as shown.
Click Finish to establish the connection:
NOTE: Leave the LAN Device Name BLANK or the connection will fail.
4. After a brief scan, the connection should be shown under Network Devices:
SSG3000X Programming Guide 9
SIGLENT
5. Right-click on the product and select Open NI-VISA Test Panel:
6. Click “Input/Output” option button and click “Query” option button. If everything is OK,
you will see the Read operation information returned as shown below.
10 SSG3000X Programming Guide
SIGLENT
2.SCPI Overview
2.1 Command Format
SCPI commands present a hierarchical tree structure containing multiple subsystems, each
of the subsystems is made up of a root keyword and several sub keywords. The command
string usually starts with “:”, the keywords are separated by “:” and the followed parameter
settings are separated by space. Query commands add “?” at the end of the string.
For example:
:SOURce:FREQuency <freq>
:SOURce:FREQuency?
SOURce is the root key of the command, FREQuency is second. The command begins with
“:”, and separates the keywords at the same time, <freq> separated by space and represents
the parameter available for setting; “?” represents a query.
2.2 Symbol Instruction
The following four symbols are not the content of SCPI commands and can not be sent with
the commands, but are usually used in the commands.
1, Triangle Brackets < >
The parameter in the triangle brackets must be replaced by an effective value. For example:
Send the “CALibration:SPC:TARGet <power>” command in “CALibration:SPC:TARGet 0”.
2, Square Brackets [ ]
The content in the square brackets can be ignored. When the parameter is ignored, the
instrument will set the parameter to its default. For example,
In the “[:SOURce]:POWer?” command, sending any of the four commands below can
generate the same effect:
:SOURce:POWer?
:POWer?
3, Vertical Bar |
The vertical bar is used to separate multiple parameters and when sending the command,
you can choose one of the parameters. For example,
In the “[:SOURce]:AM:STATe OFF|ON|0|1” command, the parameters available are “OFF”,
“ON”, “0” or “1”.
4, Braces { }
The parameters in the braces are optional which can be ignored or set for one or more times.
2.3 Parameter Type
The parameters in the commands introduced in this manual include 6 types: boolean,
enumeration, integer, float and string.
1, Boolean
SSG3000X Programming Guide 11
SIGLENT
The parameters in the commands could be “OFF”, “ON”, “0” or “1”. For example:
[:SOURce]:FM:STATe OFF|ON|0|1
2, Enumeration
The parameter could be any of the values listed. For example:
[:SOURce]:SWEep:STATe OFF|FREQuency|LEVel|LEV_FREQ
The parameter is “OFF”, “FREQuency”, “LEVel” or LEV_FREQ.
3, Integer
Except other notes, the parameter can be any integer within the effective value range. For
example:
[:SOURce]:SWEep:STEP:POINts <value>
The parameter <value> can be set to any integer between 2 and 65535.
4, Float
The parameter could be any value within the effective value range according to the accuracy
requirement (the default accuracy contains up to 9 digits after the decimal points). For
example:
[:SOURce]:POWer:OFFSet <value>
The parameter <value> can be set to any real number between -100 and 100.
5, String
The parameter should be the combinations of ASCII characters. For example:
:SYSTem:COMMunicate:LAN:IPADdress <“xxx.xxx.xxx.xxx”>
The parameter can be set as “192.168.1.12” string.
2.4 Command Abbreviation
All of the commands are not case sensitive, so you can use any of them. But if abbreviation
is used, all the capital letters in the command must be written completely. For example:
:CORRection:FLATness:COUNt?
Can be abbreviated to:
:CORR:FLAT:COUN?
12 SSG3000X Programming Guide
SIGLENT
Command
Format
:OUTPut[:STATe] ON|OFF|1|0
:OUTPut[:STATe]?
Instruction
Activate/Deactivate the RF output.
Get the RF state.
Parameter
Type
Boolean
Parameter
Range
ON|OFF|1|0
Return
Boolean
Default
0
Menu
RF
Example
:OUTPut ON
Command
Format
*IDN?
Instruction
Returns an instrument identification information string. The string will contain the
manufacturer, model number, serial number, software number, FPGA number
and CPLD number.
This command presets the instrument to a factory defined condition that is
appropriate for remote programming operation. *RST is equivalent to performing
3.System Commands
This chapter introduces the Siglent Technologies SSG3000XSCPI commands, include:
IEEE Common Commands 0
System Subsystem 3.2
Preset Subsystem 错误!未找到引用源。
Output Subsystem 3.4
Output Subsystem
3.1.1 RF Output (:OUTPut[:STATe])
Source Subsystem3.5
Sense Subsystem 3.6
3.2 IEEE Common Commands
3.2.1 Identification Query (*IDN)
3.2.2 Reset (*RST)
SSG3000X Programming Guide 13
SIGLENT
the two commands :SOURce:PRESet and *CLS. This command always performs
a factory preset.
Menu
None
Example
*RST
Command
Format
*CLS
Instruction
Clears the status byte register. It does this by emptying the error queue and
clearing all bits in all of the event registers. The status byte register summarizes
the states of the other registers. It is also responsible for generating service
requests.
Menu
None
Example
*CLS
Command
Format
*ESE <number>
*ESE?
Instruction
Set the bits in the standard event status enable register. This register monitors
I/O errors and synchronization conditions such as operation complete, request
control, query error, device dependent error, execution error, command error and
power on. A summary bit is generated on execution of the command.
The query returns the state of the standard event status enable register.
Menu
None
Example
*ESE 16
Command
Format
*ESR?
Instruction
Queries and clears the standard event status event register. (This is a destructive
read.) The value returned reflects the current state (0/1) of all the bits in the
register.
Menu
None
Example
*ESR?
Command
Format
*OPC
*OPC?
Instruction
Set bit 0 in the standard event status register to “1” when all pending operations
have finished.
The query stops any new commands from being processed until the current
processing is complete. Then it returns a “1”, and the program continues. This
query can be used to synchronize events of other instruments on the external
bus.
Returns a “1” if the last processing is complete. Use this query when there’s a
need to monitor the command execution status, such as a sweep execution.
Menu
None
Example
*OPC?
3.2.3 Clear Status (*CLS)
3.2.4 Standard Event Status Enable (*ESE)
3.2.5 Standard Event Status Register Query (*ESR)
3.2.6 Operation Complete Query (*OPC)
14 SSG3000X Programming Guide
3.2.7 Service Request Enable (*SRE)
Command
Format
*SRE <integer>
*SRE?
Instruction
This command enables the desired bits of the service request enable register.
The query returns the value of the register, indicating which bits are currently
enabled.
Menu
None
Example
*SRE 1
Command
Format
*STB
Instruction
This query is used by some instruments for a self test.
Menu
None
Example
*STB
Command
Format
*WAI
Instruction
This command causes the instrument to wait until all pending commands are
completed before executing any additional commands.
There is no query form to the command.
Menu
None
Example
*WAI
Command
Format
*TST?
Instruction
This query is used by some instruments for a self test.
Menu
None
Example
*TST?
Command
Format
:SYSTem:TIME <hhmmss>
:SYSTem:TIME?
Instruction
Set System time.
Get System time.
Parameter
Type
String
Parameter
Range
hour(0 ~ 23), minute(0 ~ 59), second(0 ~ 59)
Return
String
Default
None
Menu
Utility > Setting > Time Setting
Example
Set System time:
3.2.8 Status Byte Query (*STB)
3.2.9 Wait-to-Continue (*WAI)
SIGLENT
3.2.10 Self Test Query (*TST)
3.3 System Subsystem
3.3.1 System Time (:SYSTem:TIME)
SSG3000X Programming Guide 15
SIGLENT
:SYSTem:TIME 182559
Get System time:
:SYSTem:TIME?
Command
Format
:SYSTem:DATE <yyyymmdd>
:SYSTem:DATE?
Instruction
Set system date.
Get system date.
Parameter
Type
String
Parameter
Range
year(four digits), month(1 ~ 12), date(1 ~ 31)
Return
String
Default
None
Menu
Utility > Setting > Time Setting
Example
Set System date:
:SYSTem:DATE 20050101
Get System date:
:SYSTem:DATE?
ON|OFF|AUTO
ON
Internal level control is permanently activated.
OFF
Internal level control is deactivated; Sample & Hold mode is activated.
AUTO
Internal level control is activated/deactivated automatically depending on the
operating state.
Set the mode of the pulse generator.
Get the mode of the pulse generator.
Parameter
Type
Enumeration
Parameter
Range
SINGle|DOUBle|PTRain
SINGle
Enables single pulse generation.
DOUBle
Enables double pulse generation. The two pulses are generated in one pulse
period.
PTRain
A user-defined pulse train is generated The pulse train is defined by value pairs
of on and off times that can be entered in a pulse train list.
Set the delay from the start of the first pulse to the start of the second pulse.
Get the delay from the start of the first pulse to the start of the second pulse.
Set the polarity of the active slope of an applied trigger at the PULSE EXT
connector.
Get the polarity of the active slope of an applied trigger at the PULSE EXT
connector.
Parameter
Type
Enumeration
Parameter
Range
NEGative|POSitive
Return
Enumeration
Default
POSitive
Menu
PULSE > Trig Slope
Example
PULM:TRIG:EXT:SLOP NEG
Command
Format
[:SOURce]:LFOutput ON|OFF|1|0
[:SOURce]:LFOutput?
Instruction
Activate/deactivate the LF output.
Get the LF output state.
Set LF out put frequency.
Get LF out put frequency.
If signal source "Internal" is set, the instrument performs the analog modulations
(AM/FM /PM) with this frequency.
This chapter gives some examples for the programmer. In these examples you can see how
to use the VISA or sockets, in combination with the commands have been described above
to control the signal generator. By following these examples, you can develop many more
applications.
4.1 Examples of Using VISA
4.1.1 Example of VC++
Environment: Win7 32bit system, Visual Studio
The functions of this example: use the NI-VISA, to control the device with USBTMC or
TCP/IP access to do a write and read.
Follow the steps to finish the example:
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 use NI-VISA,
static or automatic:
(1) Static: find files: visa.h, visatype.h, visa32.lib in NI-VISA install path. Copy them to your
project, and add them into project. In the projectname.cpp file, add the follow two lines:
#include "visa.h"
#pragma comment(lib,"visa32.lib")
(2) Automatic:
Set the .h file include directory, the NI-VISA install path, in our computer we set the path is:
C:\Program Files\IVI Foundation \VISA\WinNT\include. Set this path to project---properties--
-c/c++---General---Additional Include Directories: See the picture.
Set lib path set lib file:
Set lib path: the NI-VISA install path, in our computer we set the path is: C:\Program Files\IVI
Foundation\VISA\WinNT\lib\msc. Set this path to project---properties---Linker---General--Additional Library Directories: as seen in the pictures below.
56 SSG3000X Programming Guide
SIGLENT
Set lib file: project---properties---Linker---Command Line---Additional Options: visa32.lib
Include visa.h file: In the projectname.cpp file:
#include <visa.h>
3、Add codes:
(1) USBTMC access code.
Write a function Usbtmc_test:
int Usbtmc_test()
{
/* 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 viPrintf */ /* Try to Read a Response With viScanf */ /* Close the VISA Session */ /***********************************************************/
ViSession defaultRM;
ViSession instr;
ViUInt32 numInstrs;
ViFindList findList;
ViStatus status;
char instrResourceString[VI_FIND_BUFLEN]; unsignedchar buffer[100]; int i; /** 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");
return status;
}
/* Find all the USB TMC VISA resources in our system and store the number of resources in the system in
SSG3000X Programming Guide 57
SIGLENT
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);
return status;
}
/** 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, &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;
}
58 SSG3000X Programming Guide
int _tmain(int argc, _TCHAR* argv[])
{
Usbtmc_test();
return 0;
}
Run result.
SIGLENT
(2) TCP/IP access code.
Write a function TCP_IP_Test:
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)
{
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;
}
Environment: Win7 32bit system, Microsoft Visual Basic 6.0
The function of this example: Use the NI-VISA, to control the device with USBTMC and
TCP/IP access to do a write and read.
Follow the steps to complete the example:
1、 Open Visual Basic, build a standard application program project (Standard EXE)
2、 Set the project environment to use the NI-VISA lib, Click the Existing tab of Project>>Add
Existing Item. Search for the visa32.bas file in the include folder under the NI-VISA
installation path and add the file.
This allows the VISA functions and VISA data types to be used in a program.
3、 Add codes:
(1) USBTMC access code.
Write a function Usbtmc_test:
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
60 SSG3000X Programming Guide
' 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. 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)
SIGLENT
SSG3000X Programming Guide 61
SIGLENT
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
(2) TCP/IP access code.
Write a function TCP_IP_Test:
PrivateFunction TCP_IP_Test(ByVal ip AsString) AsLong
Dim outputBuffer AsString * VI_FIND_BUFLEN 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
(3) Button control code:
PrivateSub exitBtn_Click()
End
EndSub
PrivateSub tcpipBtn_Click()
Dim stat AsLong
stat = TCP_IP_Test(ipTxt.Text)
If (stat < VI_SUCCESS) Then
resultTxt.Text = Hex(stat)
EndIf
62 SSG3000X Programming Guide
EndSub
PrivateSub usbBtn_Click()
Dim stat AsLong
stat = Usbtmc_test
If (stat < VI_SUCCESS) Then
resultTxt.Text = Hex(stat)
EndIf
EndSub
Run result:
SIGLENT
4.1.3 Example of MATLAB
Environment: Win7 32bit system, MATLAB R2013a
The function of this example: Use the NI-VISA, to control the device with USBTMC or
TCP/IP access to do a write and read.
Follow the steps to complete the example:
1、 Open MATLAB, 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、 Add codes:
(1)USBTMC access code
Write a function Usbtmc_test.
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::0xF4EC::0x1501::0123456789::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);
SSG3000X Programming Guide 63
SIGLENT
%Close the VISA object
fclose(vu);
delete(vu);
clear vu;
end
Run result:
(2)TCP/IP access code.
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:
4.1.4 Example of LabVIEW
Environment: Win7 32bit system, LabVIEW 2011
The functions of this example: use the NI-VISA, to control the device with USBTMC and
TCP/IP access to do a write and read.
Follow the steps to complete the example:
1、 Open LabVIEW, 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 and you can
64 SSG3000X Programming Guide
SIGLENT
select and add the following functions from VISA Palette from the pop-up menu: VISA Write,
VISA Read, VISA Open and VISA Close.
4、 Connect them 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 command to the
device, and reads back the response. In this example, the specific command being sent is
the device ID query. Check with your device manufacturer for the device command set. After
all communication is complete, the VI closes the VISA session.
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、 Connect them as shown in the figure below
SSG3000X Programming Guide 65
SIGLENT
8、 Input the IP address and run the program.
4.2 Examples of Using Socket
4.2.1 Example of Python
Python is an interpreted programming language that lets you work quickly and is very
portable.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 test and measurements
tasks.
Environment: Win7 32bit system, Python v2.7.5
The functions of this example: Open a socket, sends a query, and closes the socket. It
does this loop 10 times.
Below isthecode of the script:
#!/usr/bin/env python
#-*- coding:utf-8 –*#----------------------------------------------------------------------------# The short script is a example that open a socket, sends a query,
66 SSG3000X Programming Guide
# 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.32" # should match the instrument’s IP address
port = 5024 # 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))
info = s.recv(4096)
print (info)
except socket.error:
print ('failed to connect to ip ' + remote_ip)
return s
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?')
print (str(count) + ":: " + str(qStr))
count = count + 1
SocketClose(s)
input('Press "Enter" to exit')
if __name__ == '__main__':
proc = main()
Run result:
SIGLENT
SSG3000X Programming Guide 67
SIGLENT
4.2.2 Example of Telnet
Telnet SCPI: Provides the ability to send single SCPI commands from a remote PC to the
signal generator using LAN port number 5024.
How to send single SCPI commands using Telnet:
1. On the remote PC, click Start, then Run
2. Type: telnet <ip address> 5024
3. A Telnet window with a >> prompt should appear on the remote PC screen.
4. From the SCPI prompt:
Type single SCPI commands. Press Enter to send the command.
68 SSG3000X Programming Guide
To exit the telnet window click X in the upper-right corner.
To get a normal telnet prompt, press Ctrl + ] (closing bracket).
SIGLENT
To get SCPI prompt again, type open <ip Address> 5024.
Press Enter:
To close the normal telnet window, type Quit and press Enter.
SSG3000X Programming Guide 69
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.