A-16
A2
else
{
for (;;)
{
status = viWrite (devSession, “R? 100,1”, 8, &length);
if (status != VI_SUCCESS)
{
printf (“Unable to send a temp query to %s\n”, argv[1]);
retval = 1;
break;
}
else
{
status = viRead (devSession, result, sizeof(result), &length);
if (status != VI_SUCCESS)
{
printf (“Error reading the temp query response from %s\n”, argv[1]);
retval = 1;
break;
}
else
{
// Null terminate the received string since he viRead does not
// auto-magically Null terminate the data. Note that this will
// not remove the \n if one is included in the result string.
result [length] = ‘\0’;
// If the result string contains a \n character, terminate the
// string at that point - replacing the \n with a Null.
cp = strchr (result, ‘\n’);
if (cp)
*cp = ‘\0’;
// Convert the response to a tempature
sscanf (result, “%d”, &temp);
printf (“Temp: %d.%d\r”, temp / 10, temp % 10);
// Now pause for 10 seconds
Sleep (10 * 1000);
}
}
}
}
// Close the Resource Manager now that we’re done with using VISA.
viClose (rmSession);
return (retval);
}
Figure A-5 Example VISA Program Cont'd