Agilent Technologies 8714ET Switch User Manual


 
LAN Interface Supplement 6-15
Controlling the Analyzer via the LAN
Controlling the Analyzer with a C Program
{
fprintf(stderr, "Unable to create FILE * structure : %s\n",
strerror(errno));
exit(2);
}
return fgets(result, maxLength, instFile);
#endif
}
/***************************************************************************
*
> $Function: queryInstrument$
*
* $Description: send a SCPI command to the instrument, return a response.$
*
* $Parameters: $
* (FILE *) . . . . . . . . . file pointer associated with TCP/IP socket.
* (const char *command) . . SCPI command string.
* (char *result) . . . . . . where to put the result.
* (size_t) maxLength . . . . maximum size of result array in bytes.
*
* $Return: (long) . . . . . . . The number of bytes in result buffer.
*
* $Errors: returns 0 if anything goes wrong. $
*
***************************************************************************/
long queryInstrument(SOCKET sock,
const char *command, char *result, size_t maxLength)
{
long ch;
char tmp_buf[8];
long resultBytes = 0;
int command_err;
int count;
/*********************************************************
* Send command to analyzer
*********************************************************/
command_err = commandInstrument(sock, command);
if (command_err) return COMMAND_ERROR;
/*********************************************************
* Read response from analyzer
********************************************************/
count = recv(sock, tmp_buf, 1, 0); /* read 1 char */
ch = tmp_buf[0];
if ((count < 1) || (ch == EOF) || (ch == '\n'))
{
*result = '\0'; /* null terminate result for ascii */
return 0;
}
/* use a do-while so we can break out */
do
{
if (ch == '#')