Keysight CXG, EXG, and MXG X-Series Signal Generators Programming Guide 121
Programming Examples
LAN Programming Interface Examples
The
int main
() function allows communication with the signal generator
interactively from the command line. The program reads the signal generator's
hostname from the command line, followed by the SCPI command. It then
opens a socket to the signal generator, using port 5025, and sends the
command. If the command appears to be a query, the program queries the
signal generator for a response, and prints the response.
The
int main1()
, after renaming to
int main()
, will output a sequence of
commands to the signal generator. You can use the format as a template and
then add your own code.
This program is available on the signal generator Documentation CD-ROM as
lanio.c
.
Sockets on UNIX
In UNIX, LAN communication through sockets is very similar to reading or
writing a file. The only difference is the
openSocket()
routine, which uses a
few network library routines to create the TCP/IP network connection. Once
this connection is created, the
standard fread()
and
fwrite()
routines are
used for network communication. The following steps outline the process:
1.
Copy the lanio.c and getopt.c files to your home UNIX directory. For
example,
/users/mydir/.
2.
At the UNIX prompt in your home directory type:
cc -Aa -O -o lanio
lanio.c
3.
At the UNIX prompt in your home directory type:
./lanio xxxxx
“*IDN?”
where
xxxxx
is the hostname for the signal generator. Use this
same format to output SCPI commands to the signal generator.
The
int main1()
function will output a sequence of commands in a program
format. If you want to run a program using a sequence of commands then
perform the following:
1.
Rename the lanio.c
int main1()
to
int main()
and the original
int
main()
to
int main1().
2.
In the
main()
,
openSocket()
function, change the “your hostname here”
string to the hostname of the signal generator you want to control.
3.
Re-save the lanio.c program.
4.
At the UNIX prompt type:
cc -Aa -O -o lanio lanio.c
5.
At the UNIX prompt type:
./lanio
The program will run and output a sequence of SCPI commands to the signal
generator. The UNIX display will show a display similar to the following:
unix machine: /users/mydir
$ ./lanio
ID: Keysight Technologies, E4438C, US70000001, C.02.00
Содержание X-Series
Страница 4: ...4 ...
Страница 10: ...10 Contents ...