AnsweredAssumed Answered

Demo code to measure ACLR using VISA

Question asked by msamithu on Jul 12, 2007
Latest reply on May 18, 2010 by mukta2008
Hi,
I am trying to measure ACLR using an analyzer over LAN.
Can anyone please provide me any sample code to read ACLR using VISA? The manual has one sample code with "*IDN" command which returns the identification text. But it does not work properly if I want to write some other command (for example, READ:ACLR?). It can write the command but does not return any result. Can anyone please help me?

My code is like this:

#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "visa.h"
#include "conio.h"

#define BUFFER_SIZE 255
int main(int argc, char* argv[])
{
ViStatus status; /* For checking errors */
ViSession defaultRM, instr; /* Communication channels */
ViUInt32 retCount; /* Return count from string I/O */
ViChar buffer[BUFFER_SIZE]; /* Buffer for string I/O */
char tempDisplay[BUFFER_SIZE]; /* Display buffer for example */
char *pAddress;
/* Make sure we got our address. */
if ( argc < 2 )
{
printf("Usage: IdnExample \"TCPIP::xxx.xxx.xxx.xxx::inst0::INSTR\"\n");
printf("\t where xxx.xxx.xxx.xxx is the IP address of your instrument.\n");

char c;
c= getch();

return -1;
}
/* Store the address. */
pAddress = argv[1];
/* Begin by initializing the system*/
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS)
{
/* Error Initializing VISA...exiting*/
printf("Can't initialize VISA\n");
return -1;
}
/* Open communication with TCP/IP device at xxx.xxx.xxx.xxx*/
/* NOTE: For simplicity, we will not show error checking*/
/* TODO: Add error handling. */
status = viOpen(defaultRM, pAddress, VI_NULL, VI_NULL, &instr);
/* Set the timeout for message-based communication*/
/* TODO: Add error handling. */
status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 5000);
/* Ask the device for identification */
sprintf(buffer, "READ:ACLR?\n");
status = viWrite(instr, (unsigned char *)&buffer[0], 6,
&retCount);
status = viRead(instr, (unsigned char *)buffer, BUFFER_SIZE,
&retCount);
/* TODO: Add code to process data. */
strncpy(tempDisplay, buffer, retCount);
tempDisplay[retCount] = 0; /* Null-terminate display string. */
printf("READ:ACLR? Returned %d bytes: %s\n", retCount, tempDisplay);
/* Close down the system */
/* TODO: Add error handling. */
status = viClose(instr);
status = viClose(defaultRM);


char c;
c= getch();

return 0;


}  

Outcomes