Agilent Technologies ES Switch User Manual


 
LAN Interface Supplement 6-9
Controlling the Analyzer via the LAN
Controlling the Analyzer with a C Program
Controlling the Analyzer with a C
Program
The following example program demonstrates simple socket
programming. It is written in C, and compiles in the HP-UX UNIX
environment, or the WIN32 environment. It is portable to other UNIX
environments with only minor changes.
In UNIX, LAN communication via 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.
In Windows, the routines send() and recv() must be used, since fread()
and fwrite() may not work on sockets.
The program reads the analyzer's hostname from the command line,
followed by the SCPI command. It then opens a socket to the analyzer
using port 5025, and sends the command. If the command appears to be
a query, the program queries the analyzer for a response, and prints the
response.
NOTE Port 5025 is the default port for SCPI socket programming. To use a
different port, refer to “Using Socket Programming to Control Your
Analyzer” on page 6-3.
This example program can also be used as a utility to talk to your
analyzer from the command prompt on your UNIX workstation or
Windows 95 PC, or from within a script.
NOTE This program is included on the Example Programs Disk shipped with
your analyzer as lanio.c.