LAN Interface Supplement 6-13
Controlling the Analyzer via the LAN
Controlling the Analyzer with a C Program
memset(&peeraddr_in, 0, sizeof(struct sockaddr_in));
/***********************************************/
/* map the desired host name to internal form. */
/***********************************************/
hostPtr = gethostbyname(hostname);
if (hostPtr == NULL)
{
fprintf(stderr,"unable to resolve hostname '%s'\n", hostname);
return INVALID_SOCKET;
}
/*******************/
/* create a socket */
/*******************/
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET)
{
fprintf(stderr,"unable to create socket to '%s': %s\n",
hostname, strerror(errno));
return INVALID_SOCKET;
}
memcpy(&peeraddr_in.sin_addr.s_addr, hostPtr->h_addr, hostPtr->h_length);
peeraddr_in.sin_family = AF_INET;
peeraddr_in.sin_port = htons((unsigned short)portNumber);
if (connect(s, (const struct sockaddr*)&peeraddr_in,
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
fprintf(stderr,"unable to create socket to '%s': %s\n",
hostname, strerror(errno));
return INVALID_SOCKET;
}
return s;
}
/***************************************************************************
*
> $Function: commandInstrument$
*
* $Description: send a SCPI command to the instrument.$
*
* $Parameters: $
* (FILE *) . . . . . . . . . file pointer associated with TCP/IP socket.
* (const char *command) . . SCPI command string.
* $Return: (char *) . . . . . . a pointer to the result string.
*
* $Errors: returns 0 if send fails $
*
***************************************************************************/
int commandInstrument(SOCKET sock,
const char *command)
{
int count;