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

📄 agilent_gpibctrl.cpp

📁 这个是无线网卡WirelessLAN 测试程序NDIS
💻 CPP
字号:
// Agilent_GPIBCtrl.cpp: implementation of the CAgilent_GPIBCtrl class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "..\ZDUSBMP_DUT.h"
#include "Agilent_GPIBCtrl.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

unsigned Ag_CenterF[] = {2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484};

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAgilent_GPIBCtrl::CAgilent_GPIBCtrl()
{
	SA_DevID = -1;
	GPIB0=0;			
	SA_Addr=18; 

	sprintf(SA_DevAddr, "GPIB%d,%d", GPIB0, SA_Addr);
}

CAgilent_GPIBCtrl::~CAgilent_GPIBCtrl()
{

}

///
void CAgilent_GPIBCtrl::SetGPIB(int num)
{
	GPIB0 = num;			
}

void CAgilent_GPIBCtrl::SetSA(int num)
{
	SA_Addr=num; 
	SetSADevAddr("GPIB", GPIB0, SA_Addr);
}

///
void CAgilent_GPIBCtrl::SetSADevAddr(char *cSession, int iDevFace, int iPriAddr)
{
	sprintf(SA_DevAddr, "%s%d,%d", cSession, iDevFace, iPriAddr);
}

///
bool CAgilent_GPIBCtrl::OpenDevice(INST* DevID, char DevAdd[])
{
	*DevID = iopen(DevAdd);
	if (*DevID <= 0 )
		return false;
	return (itimeout(*DevID, 1000) == 0) ? true : false;
}

bool CAgilent_GPIBCtrl::CloseDevice(INST* DevID)
{
	if (*DevID > 0) 
		return (iclose(*DevID) == 0) ? true : false;
	else
		return true;
}

///
bool CAgilent_GPIBCtrl::Send(INST DevID, char *Cmd)
{
	if (DevID <= 0) 
		return false;
	return (iprintf(DevID, Cmd) == 0) ? true : false;
}


bool CAgilent_GPIBCtrl::Receive(INST DevID, char *cData)
{
	if (DevID <= 0) 
		return false;
	return (iscanf(DevID, "%c", cData) == 1) ? true : false;
}

bool CAgilent_GPIBCtrl::Receive(INST DevID, int *iData)
{
	if (DevID <= 0) 
		return false;
	return (iscanf(DevID, "%d", iData) == 1) ? true : false;
}

bool CAgilent_GPIBCtrl::Receive(INST DevID, float *fData)
{
	if (DevID <= 0) 
		return false;
	return (iscanf(DevID, "%f", fData) == 1) ? true : false;
}

bool CAgilent_GPIBCtrl::ReceiveStb(INST DevID, unsigned char *Stb)
{
	if (DevID <= 0) 
		return false;
	return (ireadstb(DevID, Stb) == 0) ? true : false;
}

///
bool CAgilent_GPIBCtrl::OnLine(INST DevID)
{
	if (DevID <= 0) 
		return false;
	return (ilock(DevID) == 0) ? true : false;
}

bool CAgilent_GPIBCtrl::OffLine(INST DevID)
{
	if (DevID <= 0) 
		return false;
	return (iunlock(DevID) == 0) ? true : false;
}

bool CAgilent_GPIBCtrl::Local(INST DevID)
{
	if (DevID <= 0) 
		return false;
	return (ilocal(DevID) == 0) ? true : false;
}


////+++++++++++++++++++++++++++++++++++++++++++++++++++
bool CAgilent_GPIBCtrl::Check_Instrument()
{
	if(!OpenDevice(&SA_DevID, SA_DevAddr)) return FALSE;

	return true;
}

void CAgilent_GPIBCtrl::Reset_Instruments()
{
	//
	Send(SA_DevID, "*CLS;");
	Send(SA_DevID, "*RST;");
}

bool CAgilent_GPIBCtrl::InitSA()
{
	//Support Agilent E4401/2/4/5/7B Series Spectrum Analyers
	
	Send(SA_DevID, "SENS:FREQ:CENT 2437MHZ;");//Center Frequency=2437MHz

	Send(SA_DevID, "SENS:FREQ:SPAN 66MHZ;");// Span=66MHz

	Send(SA_DevID, "UNIT:POW DBM;"); //DBM

	Send(SA_DevID, "DISP:WIND:TRAC:Y:SCAL:RLEV 20DBM;"); //ref power level = 20dbm

	Send(SA_DevID, "SENS:BWIDth 100KHZ;"); // Res BW 100KHz

	Send(SA_DevID, "SENS:BWIDth:VIDeo 100KHZ;"); // VBW 100KHz
  
	Send(SA_DevID, "SENS:SWE:TIME 200MS;");	//Sweep time 200ms

	Send(SA_DevID, "SWE:POINTS 200;");		//POINT = 200

	//-----------------
	Send(SA_DevID, "CALCulate:LLINe:ALL:DELete;");//Delete all lines

	Send(SA_DevID, "CALCulate:LLINe1:CONTrol:INTerpolate:TYPE LINear;");//Sets frequency interpolation linear

	Send(SA_DevID, "CALCulate:LLINe1:AMPLitude:INTerpolate:TYPE LINear;");// Sets amplitude interpolation linear 
   
	Send(SA_DevID, "CALCulate:LLINe:CONTrol:DOMain FREQuency;");//Sets Frequency domain

	Send(SA_DevID, "CALCulate:LLINe:CMODe FIXed;");//Sets limit line relative
	
	//******************
	Send(SA_DevID, "CALC:MARK1:MODE POS;");//Mark1 Postion
	 
	Send(SA_DevID, "CALC:MARK:AOFF;");//Turn Off all Mark

	Send(SA_DevID, "CALC:MARK1:STAT ON;"); //Mark1 Start

	return true;
}

void CAgilent_GPIBCtrl::SetTestChannel(int iTestChannel)
{
	//Set CF
	char buffer[200];  	
    sprintf(buffer,"SENS:FREQ:CENT %dMHZ;",Ag_CenterF[iTestChannel]);
	Send(SA_DevID, buffer);
}

int CAgilent_GPIBCtrl::GetGPIB()
{
	return GPIB0;
}

int CAgilent_GPIBCtrl::GetSA()
{
	return SA_Addr;
}


bool CAgilent_GPIBCtrl::CheckThirdMask(int iTestChannel)
{
	char readbuf[80];
	char tmp[30];
	
	float Ampl, Ampl1, Ampl2, Ampl3, Ampl4;
	int data;

	if(iTestChannel!=13){
		Send(SA_DevID, "CHP:BWID:INT 22MHZ;"); // BW 22MHz
		Send(SA_DevID, "CHP:FREQ:SPAN 66MHZ;"); // SPAN 66MHz
	}else{
		Send(SA_DevID, "CHP:BWID:INT 27MHZ;"); // BW 27MHz
		Send(SA_DevID, "CHP:FREQ:SPAN 80MHZ;"); // SPAN 80MHz
	}	
	Send(SA_DevID, "SENS:BWIDth 100KHZ;"); // Res BW 100KHz
	Send(SA_DevID, "SENS:BWIDth:VIDeo 100KHZ;"); // VBW 100KHz


	Send(SA_DevID, "CALC:MARK:AOFF;");//Turn Off all Mark

	Send(SA_DevID, "CALC:MARK1:STAT ON;"); //Mark1 Start
	Send(SA_DevID, "CALC:MARK2:STAT ON;"); //Mark2 Start


	//
	Send(SA_DevID, "CALC:MARK1:MAX;");	

	Send(SA_DevID, "CALC:MARK1:Y?;"); //get value of mask1
	Receive(SA_DevID, readbuf);
	Ampl= (float)strtod(readbuf, NULL);


	//
	if (Ag_CenterF[iTestChannel] != 2484){
		data = Ag_CenterF[iTestChannel]*1000 - 14500;
	}else{
		data = Ag_CenterF[iTestChannel]*1000 - 18000;
	}
	sprintf(tmp, "CALC:MARK2:X %dKHZ;", data);
	Send(SA_DevID, tmp); //set mask 2

	Send(SA_DevID, "CALC:MARK2:Y?;"); //get value of mask2
	Receive(SA_DevID, readbuf);
	Ampl1= (float)strtod(readbuf, NULL);


	//
	if (Ag_CenterF[iTestChannel] != 2484){
		data = Ag_CenterF[iTestChannel]*1000 + 14500;
	}else{
		data = Ag_CenterF[iTestChannel]*1000 + 18000;
	}
	sprintf(tmp, "CALC:MARK2:X %dKHZ;", data);
	Send(SA_DevID, tmp ); //set mask 2

	Send(SA_DevID, "CALC:MARK2:Y?;"); //get value of mask2
	Receive(SA_DevID, readbuf);
	Ampl2= (float)strtod(readbuf, NULL);


	//
	if (Ag_CenterF[iTestChannel] != 2484){
		data = Ag_CenterF[iTestChannel]*1000 - 26000;
	}else{
		data = Ag_CenterF[iTestChannel]*1000 - 29000;
	}
	sprintf(tmp, "CALC:MARK2:X %dKHZ;", data);
	Send(SA_DevID, tmp ); //set mask 2

	Send(SA_DevID, "CALC:MARK2:Y?;"); //get value of mask2
	Receive(SA_DevID, readbuf);
	Ampl3= (float)strtod(readbuf, NULL);


	//
	if (Ag_CenterF[iTestChannel] != 2484){
		data = Ag_CenterF[iTestChannel]*1000 + 26000;
	}else{
		data = Ag_CenterF[iTestChannel]*1000 + 29000;
	}
	sprintf(tmp, "CALC:MARK2:X %dKHZ;", data);
	Send(SA_DevID, tmp ); //set mask 2

	Send(SA_DevID, "CALC:MARK2:Y?;"); //get value of mask2
	Receive(SA_DevID, readbuf);
	Ampl4= (float)strtod(readbuf, NULL);

	if ((Ampl-Ampl1)>=30 && (Ampl-Ampl2)>=30 && (Ampl-Ampl3)>=50 && (Ampl-Ampl4)>=50)
		return true;
	else
		return FALSE;
}

float CAgilent_GPIBCtrl::ReadCHP(int iTestChannel)
{
	char readbuf[80];
	
	float fCPower;
	
	if(iTestChannel!=13){
		Send(SA_DevID, "CHP:BWID:INT 22MHZ;"); // BW 22MHz
		Send(SA_DevID, "CHP:FREQ:SPAN 66MHZ;"); // SPAN 66MHz
	}else{
		Send(SA_DevID, "CHP:BWID:INT 27MHZ;"); // BW 27MHz
		Send(SA_DevID, "CHP:FREQ:SPAN 80MHZ;"); // SPAN 80MHz
	}
	Send(SA_DevID, "SENS:BWIDth 100KHZ;"); // Res BW 100KHz
	Send(SA_DevID, "SENS:BWIDth:VIDeo 100KHZ;"); // VBW 100KHz


	Send(SA_DevID, "READ:CHP?;"); //read CHP
	Receive(SA_DevID, readbuf);
	
	fCPower= (float)strtod(readbuf, NULL);
	
	return fCPower;
}

double CAgilent_GPIBCtrl::ReadCarrierWaveFreq()
{
	char readbuf[20];
	double freq;
	
	Send(SA_DevID, "CHP:BWID:INT 500KHZ;"); // BW 500KHZ
	Send(SA_DevID, "CHP:FREQ:SPAN 500KHZ;"); // SPAN 500KHZ
    Send(SA_DevID, "SENS:BAND:RES 100KHZ;"); //// Res BW 100KHz
    Send(SA_DevID, "SENS:BAND:VID 30KHZ;"); // VBW 100KHz 


	Send(SA_DevID, "CALC:MARK:AOFF;");//Turn Off all Mark

	Send(SA_DevID, "CALC:MARK1:STAT ON;"); //Mark1 Start

	Send(SA_DevID, "CALC:MARK1:MAX;");	//set max

	Send(SA_DevID, "CALC:MARK:X?;");     //read frequency command

	Receive(SA_DevID, readbuf);
	freq = strtod(readbuf, NULL);

	return freq;
}

⌨️ 快捷键说明

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