SPRING :: NOTE

[Agilent] N9320B Spectrum Analizer Source (Marker Delta Mode and Marker Minimum Search) 본문

Development Tools/Keysight · National Instruments

[Agilent] N9320B Spectrum Analizer Source (Marker Delta Mode and Marker Minimum Search)

RAYZIE 2016. 2. 29. 19:03
반응형

/************************************************************/
/* Using Marker Delta Mode and Marker Minimum Search */
/* */
/* This example is for the N9320B Spectrum Analyzers */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as reference. */
/* */
/* - Opens a USB session */
/* - Clears the Analyzer */
/* - Resets the Analyzer */
/* *RST */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Prompts the user for the start and stop frequencies */
/* - Sets the start and stop frequencies */
/* SENS:FREQ:START freq */
/* SENS:FREQ:STOP freq */
/* - Trigger a sweep and delay for sweep completion */
/* INIT:IMM */
/* - Set the marker to the maximum peak */
/* CALC:MARK:MAX */
/* - Set the analyzer to activate the delta marker */
/* CALC:MARK:MODE DELT */
/* - Trigger a sweep and delay for sweep completion */
/* INIT:IMM */
/* - Set the marker to the minimum amplitude mode */
/* CALC:MARK:MIN */
/* - Query and read the marker amplitude */
/* CALC:MARK:Y? */
/* - Close the session */
/************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include "visa.h"
ViSession defaultRM, viN9320B;
ViStatus errStatus;
ViChar cIdBuff[256] ={0};
char cEnter = 0;
int iResult =0;
/*Set the input port to the 50MHz amplitude reference*/
void Route50MHzSignal()
{
	viQueryf(viN9320B, "*IDN?\n", "%t", &cIdBuff);
	/* prompt the user*/
	/* to connect the amplitude reference output to the
	input*/
	printf ("Connect CAL OUT to the RF IN \n");
	printf ("......Press Return to continue \n");
	scanf( "%c",&cEnter);
	/*Externally route the 50MHz Signal*/
	viPrintf(viN9320B,"CAL:SOUR:STAT ON \n");
}
void main()
{
	/*Program Variable*/
	ViStatus viStatus = 0;
	double dStartFreq =0.0;
	double dStopFreq =0.0;
	double dMarkerAmplitude = 0.0;
	/* Open an USB session*/
	viStatus=viOpenDefaultRM(&defaultRM);
	// USB0::2391::8472::9876543210::0::INSTR --> YOUR VISA ADDRESS
	viStatus=viOpen(defaultRM,"USB0::2391::8472::9876543210::0::INSTR",VI_NULL,VI_NULL,&viN9320B);
	if(viStatus)
	{
		printf("Could not open a session to USB device!\n");
		exit(0);
	}

	/*Clear the instrument*/
	viClear(viN9320B);
	/*Reset the instrument*/
	viPrintf(viN9320B,"*RST\n");
	/*Display the program heading */
	printf("\n\t\t Marker Delta Program \n\n" );
	/*Check for the instrument model number and route the 50MHz
	signal accordingly*/
	Route50MHzSignal();
	/*Set the analyzer to single sweep mode*/
	viPrintf(viN9320B,"INIT:CONT 0\n");
	/*Prompt the user for the start frequency*/
	printf("\t Enter the Start frequency in MHz ");
	/*The user enters the start frequency*/
	scanf("%lf",&dStartFreq);
	/*Prompt the user for the stop frequency*/
	printf("\t Enter the Stop frequency in MHz ");
	/*The user enters the stop frequency*/
	scanf("%lf",&dStopFreq);
	/*Set the analyzer to the values given by the user*/
	//viPrintf(viN9320B,"SENS:FREQ:STAR %lf
	//MHZ;:SENS:FREQ:STOP %lf MHZ\n",dStartFreq,dStopFreq);
	viPrintf(viN9320B,":SENS:FREQ:STAR %lf MHz\n",dStartFreq);
	viPrintf(viN9320B,":SENS:FREQ:STOP %lf MHZ\n",dStopFreq);
	/*Trigger a sweep, delay for completion*/
	viPrintf(viN9320B,"INIT:IMM\n");
	//delay(1);
	/*Set the marker to the maximum peak*/
	viPrintf(viN9320B,"CALC:MARK:MAX\n");
	/*Set the analyzer to activate delta marker mode*/
	viPrintf(viN9320B,"CALC:MARK:MODE DELT\n");
	/*Trigger a sweep, delay for completion*
	viPrintf(viN9320B,"INIT:IMM\n");
	Sleep(1);
	/*Set the marker to minimum amplitude*/
	viPrintf(viN9320B,"CALC:MARK:MIN\n");
	/*Query and read the marker amplitude*/
	viQueryf(viN9320B,"CALC:MARK:Y?\n","%lf",&dMarkerAmplitude);
	/*print the marker amplitude*/
	printf("\n\n\tRESULT: Marker Amplitude Delta =%lf dB\n\
	n",dMarkerAmplitude);
	/*Close the session*/
	viClose(viN9320B);
	viClose(defaultRM);
}


반응형
Comments