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 158
Image 158
Manual background

Programming Examples

Using C Programming Over Socket LAN

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 == ’#’)

{

/* binary data encountered - figure out what it is */ long numDigits;

long numBytes = 0;

/* char length[10]; */

count = recv(sock, tmp_buf, 1, 0); /* read 1 char */ ch = tmp_buf[0];

if ((count < 1) (ch == EOF)) break; /* End of file */

if (ch < ’0’ ch > ’9’) break; /* unexpected char */ numDigits = ch - ’0’;

if (numDigits)

{

/* read numDigits bytes into result string. */ count = recv(sock, result, (int)numDigits, 0); result[count] = 0; /* null terminate */ numBytes = atol(result);

}

if (numBytes)

{

158

Chapter 3

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