Agilent Technologies E4406A VSA manual Programming Examples, Using C Programming Over Socket LAN

Models: E4406A VSA

1 406
Download 406 pages 63.49 Kb
Page 155
Image 155
Manual background

Programming Examples

Using C Programming Over Socket LAN

/* fprintf(stderr, "Sending \"%s\".\n", command); */ if (strchr(command, ’\n’) == NULL) {

fprintf(stderr, "Warning: missing newline on command %s.\n", command);

}

count = send(sock, command, strlen(command), 0); if (count == SOCKET_ERROR) {

return COMMAND_ERROR;

}

return NO_CMD_ERROR;

}

/**************************************************************************

*recv_line(): similar to fgets(), but uses recv()

**************************************************************************/

char * recv_line(SOCKET sock, char * result, int maxLength)

{

#ifdef WINSOCK

int cur_length = 0; int count;

char * ptr = result; int err = 1;

while (cur_length < maxLength) { /* Get a byte into ptr */ count = recv(sock, ptr, 1, 0);

/* If no chars to read, stop. */ if (count < 1) {

break;

}

cur_length += count;

Chapter 3

155

Page 155
Image 155
Agilent Technologies E4406A VSA manual Programming Examples, Using C Programming Over Socket LAN, Chapter