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

📄 ni_gpibctrl.cpp

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

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

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

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

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

CNI_GPIBCtrl::CNI_GPIBCtrl()
{
	GPIB0=0;			
	SA_Addr=18; 
}

CNI_GPIBCtrl::~CNI_GPIBCtrl()
{

}

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

void CNI_GPIBCtrl::SetSA(int num)
{
	SA_Addr=num; 	
}

void CNI_GPIBCtrl::OffLine()
{
	//Place the device or interface online or offline.
	//if zero, the device or interface is placed offline.
	ibonl (GPIB0, 0);
}

bool CNI_GPIBCtrl::Check_Instrument()
{
	int	Num_Instruments,            // Number of instruments on GPIB
		PAD,                        // Primary address
		loop;						// Loop counter

	Addr4882_t	Instruments_Array[32];            // Array of primary addresses

	bool SA_Present = FALSE;

	//Reset the GPIB by sending interface clear
	SendIFC (GPIB0); 
	if (ibsta & ERR){
		TRACE(_T("GPIB controller not present.\n"));
		return false;
	}

	for (loop = 0; loop < 30; loop++) {
		Instruments_Array[loop] = (Addr4882_t)(loop + 1);
	}

	Instruments_Array[30] = NOADDR;

	//Find listening devices on the GPIB.
	FindLstn(GPIB0, Instruments_Array, Instruments, 31); 
	if (ibsta & ERR){
		TRACE(_T("No instrument found.\n"));
		OffLine(); //
		return false;
	}

	Num_Instruments = ibcntl;
  
	Instruments[Num_Instruments] = NOADDR;

	for (loop = 0; loop < Num_Instruments; loop++) {
		PAD = GetPAD(Instruments[loop]); //GetPAD(val) => (val & 0xFF)
		if (PAD == SA_Addr)
			SA_Present = TRUE;
	} 

	if (!SA_Present) {
		TRACE(_T("Spectrum Analyzer not present.\n"));
		return FALSE;   // TRUE when there is Spectrum Analyzer
	}

	OffLine();

	return true;
}

void CNI_GPIBCtrl::Reset_Instruments()
{
	SendIFC(GPIB0); //Reset the GPIB by sending interface clear
	ResetSys(GPIB0,Instruments); //Reset and initialize IEEE 488.2-compliant instruments
	Sleep(1000);
	DevClearList(GPIB0,Instruments); //Clear multiple instruments
	SetRWLS(GPIB0,Instruments); //Place instruments in Remote With Lockout State
}

bool CNI_GPIBCtrl::InitSA()
{
	//Support Agilent E4401/2/4/5/7B Series Spectrum Analyers
	
	//******************
	Send(GPIB0,SA_Addr,"CALCulate:LLINe:ALL:DELete;", 27,DABend);//Delete all lines

	//******************
	Send(GPIB0,SA_Addr,"CALC:MARK1:MODE POS;", 19, DABend);//Mark1 Postion
	Send(GPIB0,SA_Addr,"CALC:MARK2:MODE POS;", 19, DABend);//Mark2 Postion
	
	Send(GPIB0,SA_Addr,"CALC:MARK:AOFF;", 15, DABend);//Turn Off all Mark

	//******************
	Send(GPIB0,SA_Addr, "SENS:FREQ:CENT 2412MHZ;", 23, DABend);//Center Frequency=2412

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

	Send(GPIB0,SA_Addr,"SWE:POINTS 200;", 15,DABend);		//POINT = 200

	//-----------------
	Send(GPIB0,SA_Addr,"CONF:CHP;", 9,DABend);//set channel power measurement

	Send(GPIB0,SA_Addr,"CHP:AVER OFF;", 13,DABend);//set average function off

	Send(GPIB0,SA_Addr,"CHP:AVER:TCON EXP;", 18,DABend);//set average mode exponential

	Send(GPIB0,SA_Addr,"CHP:BWID:INT 22MHZ;", 19,DABend); // BW 22MHz

	Send(GPIB0,SA_Addr,"CHP:FREQ:SPAN 66MHZ;", 20,DABend); // SPAN 66MHz
	
	Send(GPIB0,SA_Addr,"SENS:BWIDth 100KHZ;", 19,DABend); // Res BW 100KHz

	Send(GPIB0,SA_Addr,"SENS:BWIDth:VIDeo 100KHZ;", 25,DABend); // VBW 100KHz

	Send(GPIB0,SA_Addr,"SENS:SWE:TIME 200MS;", 20,DABend);	//Sweep time 200ms

	return true;
}

void CNI_GPIBCtrl::SetTestChannel(int iTestChannel)
{
	//Set CF
	char buffer[200];  	
    sprintf(buffer,"SENS:FREQ:CENT %dMHZ;",NI_CenterF[iTestChannel]);
	Send(GPIB0,SA_Addr,buffer, 23,DABend);
  
}

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

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

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

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

	
	Send(GPIB0,SA_Addr,"CALC:MARK:AOFF;", 15, DABend);//Turn Off all Mark

	Send(GPIB0,SA_Addr,"CALC:MARK1:STAT ON;", 19, DABend); //Mark1 Start
	Send(GPIB0,SA_Addr,"CALC:MARK2:STAT ON;", 19, DABend); //Mark2 Start

	Send(GPIB0,SA_Addr,"CHP:BWID:INT 22MHZ;", 19,DABend); // BW 22MHz
	Send(GPIB0,SA_Addr,"CHP:FREQ:SPAN 66MHZ;", 20,DABend); // SPAN 66MHz

	Send(GPIB0,SA_Addr,"SENS:BWIDth 100KHZ;", 19,DABend); // Res BW 100KHz

	Send(GPIB0,SA_Addr,"SENS:BWIDth:VIDeo 100KHZ;", 25,DABend); // VBW 100KHz

	//
	Send(GPIB0,SA_Addr,"CALC:MARK1:MAX;", 14, DABend);	

	Send(GPIB0,SA_Addr,"CALC:MARK1:Y?;", 14, DABend); //get value of mask1
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';	
	Ampl= (float)strtod(readbuf, NULL);


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

	Send(GPIB0,SA_Addr,"CALC:MARK2:Y?;", 14, DABend); //get value of mask2
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';	
	Ampl1= (float)strtod(readbuf, NULL);


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

	Send(GPIB0,SA_Addr,"CALC:MARK2:Y?;", 14, DABend); //get value of mask2
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';	
	Ampl2= (float)strtod(readbuf, NULL);


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

	Send(GPIB0,SA_Addr,"CALC:MARK2:Y?;", 14, DABend); //get value of mask2
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';	
	Ampl3= (float)strtod(readbuf, NULL);


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

	Send(GPIB0,SA_Addr,"CALC:MARK2:Y?;", 14, DABend); //get value of mask2
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';	
	Ampl4= (float)strtod(readbuf, NULL);

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

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


	Send(GPIB0,SA_Addr,"READ:CHP?;", 10, DABend); //read CHP
    Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);
    readbuf[ibcntl-0] = '\0';
	
	fCPower= (float)strtod(readbuf, NULL);
	
	return fCPower;
}

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


	Send(GPIB0,SA_Addr,"CALC:MARK:AOFF;", 15, DABend);//Turn Off all Mark

	Send(GPIB0,SA_Addr,"CALC:MARK1:STAT ON;", 19, DABend); //Mark1 Start

	Send(GPIB0,SA_Addr,"CALC:MARK1:MAX;", 14, DABend);	//set max

	Send(GPIB0,SA_Addr,"CALC:MARK:X?;", 13, DABend);     //read frequency command

	Receive(GPIB0,SA_Addr,readbuf, 12,STOPend);	//get value
	readbuf[ibcntl-0] = '\0';
	freq = strtod(readbuf, NULL);

	return freq;

}

⌨️ 快捷键说明

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