⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aumg369xb.c

📁 介绍了GPIB在开发mg369*仪器的自动控制方面的技巧和注意事项
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************************** 
 * (c) 2007, National Instruments, Corporation. All Rights Reserved.	     	       * 
 ***************************************************************************************/
 
/***************************************************************************************
 *  Anritsu Ltd, MG369XB Synthesized Signal Generator   
 *  VXIPNP, LabWindows/CVI 8.0 Instrument Driver
 *
 *  Original Release: 10/20/2007                                  
 *  By: Xiangchao Xie, National Instruments, Shanghai China                              
 *      PH: (86.21)50509810	Fax: (86.21)65556244	
 *		Email: xiangchao.xie@ni.com                            
 *                                                                           
 *  Modification History:                                                    
 *                                                                           
 *      07/16/2007  - Instrument Driver Created.
 *		10/20/2007  - Instrument Driver Released. 
 ***************************************************************************************/

#include <visa.h>
#include <ansi_c.h>
#include "aumg369xb.h"


/*= DEFINES ===========================================================================*/
#define AUMG369XB_REVISION			"Rev 1.0, 10/2007, CVI 8.1" /*  Instrument driver revision */
#define AUMG369XB_BUILD_REVISION	"00001"						/*  Driver build revision      */
#define AUMG369XB_BUFFER_SIZE		512L         				/*  File I/O buffer size 	   */

/*= Macros ============================================================================*/ 
#ifndef CHECKERR
#define CHECKERR(fCall) \
	if (status = (fCall), (status = (status < 0) ? status : VI_SUCCESS)) \
		{ \
		goto Error; \
		} \
		else
#endif

#ifndef CHECKPARAM
#define CHECKPARAM(fCall, errorCode) \
	if (fCall) \
		{ \
		status = (errorCode); \
		goto Error; \
		} \
		else
#endif


/*= Static Parameter ==================================================================*/
static ViInt32 gModelNumber						=	AUMG369XB_MODEL_MG3691B;
static ViInt32 gPowerLevelUnit					=	0;


/***************************************************************************************/
/*= INSTRUMENT-DEPENDENT COMMAND ARRAYS ===============================================*/
/***************************************************************************************/
static ViString triggerSourceTable[]			=	{"AUT", "TEX", "EXT", "MAN"};

static ViString alternateSweepRangeTable[]		=	{"AFU", "AF1", "AF3", "AD1", "AD5", "AD6"};

static ViString stepSweepModeTable[]			=	{"LGS", "LIS"};

static ViString sweepRangeTable[]				=	{"FUL", "SF1", "SF3", "DF0", "DF1", "DF5", "DF6"};

static ViString scancwFrequencyTable[]			=	{"SQD", "SQU", "SQF"};

static ViString	 frequencyMarkerModeTable[]		=	{"IM1", "VM1", "MK0"};

static ViString levelingModeTable[]				=	{"IL1", "DL1", "PL1", "LV0", "LV1"};

static ViString internalFMModeTable[]			=	{"FMN", "FM9", "FM7", "FM8"};

static ViString externalFMModeTable[]			=	{"FM2", "FML", "FM1", "FMW"};

static ViString internalPMModeTable[]			=	{"PH7", "PH8"};
	
static ViString externalPMModeTable[]			=	{"PH1", "PH2"};

static ViString triggerEdgeTypeTable[]			=	{"PTR", "PTF"};

static ViString blankingPolarityTable[]			=	{"BPP", "BPN"};	 

static ViString markerPolarityTable[]			=	{"MPP", "MPN"};

static ViString penliftRelayTable[]				=	{"PPO", "PPC"};

static ViString executeCommandTable[]			=	{"GTO", "GTC", "GTD", "GTF", "GTL", "GTS", "GTT", "GTU"};

static ViString powerLevelUnitTable[]			=	{"LOG, PU0", "LOG, PU2", "LIN, PU1"};


/***************************************************************************************/
/*= INSTRUMENT-DEPENDENT STATUS/RANGE STRUCTURE  ======================================*/
/***************************************************************************************/
/* aumg369xb_stringValPair is used in the aumg369xb_errorMessage function			   */
/*=====================================================================================*/
typedef struct  aumg369xb_stringValPair
{
   ViStatus stringVal;
   ViString stringName;
}  aumg369xb_tStringValPair;


/**********************************************************************8888888888*******/
/*= UTILITY ROUTINE DECLARATIONS (Non-Exportable Functions) ===========================*/
/*************************************************************************8888888888****/
ViBoolean	aumg369xb_invalidPointer (void *value);


/***************************************************************************************/
/*= INSTRUMENT SPECIFIC UTILITY ROUTINE DECLARATIONS (Non-Exportable Functions) =======*/
/***************************************************************************************/
ViStatus	aumg369xb_defaultInstrSetup (ViSession vi);
ViStatus	aumg369xb_checkStatus (ViSession vi);


/***************************************************************************************/
/*====== USER-CALLABLE FUNCTIONS (Exportable Functions) ===============================*/
/***************************************************************************************/

/*=====================================================================================*/
/* Function: Initialize														 		   */
/*																			 		   */
/* Purpose:  This function opens the instrument, queries the instrument for its ID,    */
/*           and initializes the instrument to a known state.					       */
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_init (ViRsrc resourceName, 
					ViBoolean IDQuery, ViBoolean resetDevice, 
					ViSession *vi)
{
    ViStatus 	status = VI_SUCCESS;
    ViSession 	rmSession = 0;
	ViChar      rdBuffer[AUMG369XB_BUFFER_SIZE];

    /*- Check input parameter ranges --------------------------------------------------*/
    CHECKPARAM (aumg369xb_invalidPointer (vi), VI_ERROR_PARAMETER4);
	/*---------------------------------------------------------------------------------*/

    /*- Open instrument session -------------------------------------------------------*/
    if ((status = viOpenDefaultRM (&rmSession)) < 0)
        return status;

    if ((status = viOpen (rmSession, resourceName, VI_NULL, VI_NULL, vi)) < 0) 
	{
        viClose (rmSession);
        return status;
    }

    /*- Configure VISA Formatted I/O --------------------------------------------------*/
    CHECKERR (viSetAttribute (*vi, VI_ATTR_TMO_VALUE, 10000));
    CHECKERR (viSetBuf (*vi, VI_READ_BUF|VI_WRITE_BUF, 4000));
    CHECKERR (viSetAttribute (*vi, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS));
    CHECKERR (viSetAttribute (*vi, VI_ATTR_RD_BUF_OPER_MODE,VI_FLUSH_ON_ACCESS));
	
    /*- Identification Query ----------------------------------------------------------*/
    if (IDQuery) 
	{
		ViChar *queryResponse1 = "ANRITSU,MG3691B";
		ViChar *queryResponse2 = "ANRITSU,MG3692B";
		ViChar *queryResponse3 = "ANRITSU,MG3693B";
		ViChar *queryResponse4 = "ANRITSU,MG3694B";
		ViChar *queryResponse5 = "ANRITSU,MG3695B";
		ViChar *queryResponse6 = "ANRITSU,MG3696B";
		
		CHECKERR (viQueryf (*vi, "*IDN?", "%256[^\n]", rdBuffer));													
		
		if(strncmp (rdBuffer, queryResponse1, strlen(queryResponse1)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3691B;
		else if (strncmp (rdBuffer, queryResponse2, strlen(queryResponse2)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3692B;
		else if (strncmp (rdBuffer, queryResponse3, strlen(queryResponse3)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3693B;
		else if (strncmp (rdBuffer, queryResponse4, strlen(queryResponse4)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3694B;
		else if (strncmp (rdBuffer, queryResponse5, strlen(queryResponse5)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3695B;
		else if (strncmp (rdBuffer, queryResponse6, strlen(queryResponse6)) == 0)
			gModelNumber = AUMG369XB_MODEL_MG3696B;
		else
			CHECKERR (VI_ERROR_FAIL_ID_QUERY);
    }
	
	/*- Reset instrument --------------------------------------------------------------*/
    if (resetDevice) 
	{
        CHECKERR (aumg369xb_reset (*vi));
	}
	
	/*- Send Default Instrument Setup -------------------------------------------------*/	
    else
	{
        CHECKERR (aumg369xb_defaultInstrSetup (*vi));
	}
    
	return VI_SUCCESS;  	

Error:
        
    if (*vi != VI_NULL)
    {
        aumg369xb_close(*vi);
        *vi = VI_NULL;
    }
    
    return status;	
}


/*-------------------------------------------------------------------------------------*/
/*- Configuration Functions -----------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/

/*- RF Configuration ------------------------------------------------------------------*/

/*=====================================================================================*/
/* Function: Configure Output Enabled												   */	
/*																			           */
/* Purpose:  This function turns on or turns off the RF output.						   */															   
/*=====================================================================================*/
/*
Specifies whether to turn on the RF output.

Valid Values:
VI_FALSE (0) - Turns off the RF output.
VI_TRUE  (1) - Turns on the RF output. (Default Value)

*/
ViStatus _VI_FUNC aumg369xb_configureOutputEnabled (ViSession vi,
					ViBoolean outputEnabled)
{
	ViStatus	status = VI_SUCCESS;

	CHECKERR (viPrintf (vi, "RF%d;", outputEnabled ? 1 : 0));

	CHECKERR (aumg369xb_checkStatus (vi));

Error:
	return status;
}


/*=====================================================================================*/
/* Function: Configure RF															   */	
/*																			           */
/* Purpose:  This function configures the RF parameters, including the RF state during */
/*           retrace, the RF state during frequency switching, the ramp rest point for */
/*           sweeps that are triggered by a single trigger or external trigger, the RF */
/*           state at reset, the frequency scaling reference multiplier and the        */
/*           attenuation when RF is switched off.			                           */												   
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_configureRF (ViSession vi, 
					ViBoolean retraceRFState, ViBoolean DeltaFRFState,
					ViInt32 rampRest, ViBoolean resetState, 
					ViReal64 frequencyScaling, ViBoolean terminateRFState)
{
	ViStatus	status = VI_SUCCESS;

	CHECKERR (viPrintf (vi, "RT%d, RC%d, RR%d, RO%d;", retraceRFState ? 1 : 0, 
				DeltaFRFState ? 1 : 0, rampRest, resetState ? 0 : 1));

	CHECKERR (viPrintf (vi, "FRS %f TMS, TR%d;", frequencyScaling, terminateRFState ? 1 : 0));

	CHECKERR (aumg369xb_checkStatus (vi));

Error:
	return status;
}


/*- Frequency Configuration -----------------------------------------------------------*/

/*=====================================================================================*/
/* Function: Configure Frequency List												   */	
/*																			           */
/* Purpose:  This function sets the frequency list, including the F0 to F9 and M0 to M9*/
/*           parameters.                                                               */
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_configureFrequencyList (ViSession vi, 
					ViReal64 frequencyList[20])
{
	ViStatus	status = VI_SUCCESS;
	ViInt32		i;

	/*- Check input parameter ranges --------------------------------------------------*/	
	CHECKPARAM (aumg369xb_invalidPointer (frequencyList), VI_ERROR_PARAMETER2);
	/*---------------------------------------------------------------------------------*/

	for (i = 0; i < 10; i++)
	{
		CHECKERR (viPrintf (vi, "F%d %Lf HZ;", i, frequencyList[i]));
		CHECKERR (viPrintf (vi, "M%d %Lf HZ;", i, frequencyList[i + 10]));
	}
	
	CHECKERR (aumg369xb_checkStatus (vi));

Error:
	return status;	
}


/*=====================================================================================*/
/* Function: Configure Frequency Entry												   */	
/*																			           */
/* Purpose:  This function sets the selected frequency.                                */
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_configureFrequencyEntry (ViSession vi, 
					ViInt32 selectedFrequency, ViReal64 frequency)
{
	ViStatus	status = VI_SUCCESS;

	if (selectedFrequency < 10)
	{
		CHECKERR (viPrintf (vi, "F%d %Lf HZ;", selectedFrequency, frequency));
	}
	else
	{
		CHECKERR (viPrintf (vi, "M%d %Lf HZ;", selectedFrequency - 10, frequency));
	}

	CHECKERR (aumg369xb_checkStatus (vi));

Error:
	return status;	
}


/*=====================================================================================*/
/* Function: Configure Delta Frequency												   */	
/*																			           */
/* Purpose:  This function sets the delta frequency.	           			           */
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_configureDeltaFrequency (ViSession vi,
					ViReal64 deltaFrequency)
{
	ViStatus	status = VI_SUCCESS;

	CHECKERR (viPrintf (vi, "DFM %Lf HZ;", deltaFrequency));	

	CHECKERR (aumg369xb_checkStatus (vi));

Error:
	return status;	
}


/*=====================================================================================*/
/* Function: Configure CW Frequency													   */	
/*																			           */
/* Purpose:  This function places the MG369XB in CW mode and configures the CW         */
/*           frequency parameters, including the current frequency, the phase offset   */
/*           and the CW ramp.
/*=====================================================================================*/
ViStatus _VI_FUNC aumg369xb_configureCWFrequency (ViSession vi,
					ViInt32 selectedFrequency, ViBoolean phaseOffsetEnabled, 
					ViReal64 phaseOffset, ViBoolean CWRampEnabled)
{
	ViStatus	status = VI_SUCCESS;
	
	if (selectedFrequency < 10)
	{
		CHECKERR (viPrintf (vi, "CF%d;", selectedFrequency));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -