Sockets Lan Programming And C - Keysight E4428C ESG RF Programming Manual

Signal generators
Table of Contents

Advertisement

status = viWrite(instr, (ViBuf)"*IDN?\n", 6, &retCount);
status = viRead(instr, (ViBuf)buffer, MAX_COUNT, &retCount);
buffer[retCount]= '\0';
printf("Signal Generator ID = ");
printf(buffer);
printf("\n");
status = viWrite(instr, (ViBuf)"POW:AMPL -5dbm\n", 15, &retCount);
status = viWrite(instr, (ViBuf)"POW?\n",5,&retCount);
status = viRead(instr, (ViBuf)buffer, MAX_COUNT, &retCount);
buffer[retCount]= '\0';
printf("Power level = ");
printf(buffer);
printf("\n");
status = viClose(instr);
status = viClose(defaultRM);
return 0;
}

Sockets LAN Programming and C

The program listing shown in "Queries for Lan Using Sockets" on page 124 consists of two files; lanio.c
and getopt.c. The lanio.c file has two main functions; int main() and an int main1().
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/.
Keysight Signal Generators Programming Guide
// Read the sig gen response
// Indicate the end of the string
// Print header for ID
// Print the ID string
// Print carriage return
// Flush the read buffer
// Set sig gen power to -5dbm
// Query the power level
// Read the power level
// Indicate the end of the string
// Print header to the screen
// Print the queried power level
// Close down the system
Programming Examples
LAN Programming Interface Examples
121

Advertisement

Table of Contents
loading

Table of Contents