www.pudn.com > GPIBPM.rar > TLSCtr.cpp
// TLSCtr.cpp: implementation of the CTLSCtr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "Agilentnew.h"
#include "TLSCtr.h"
#include "math.h"
typedef int (__stdcall SEND) (int,int,char *,int,int);
typedef int (__stdcall RECEIVE) (int,int,char *,int,int);
typedef int (__stdcall INIT) ();
#define LV 299792458
RECEIVE *receive;
SEND *sendcmd;
HINSTANCE dllHandle;
CString cmmd;
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTLSCtr::CTLSCtr()
{
stwl=1509;
endwl=1640;
int i;
for(i=0;i<3;i++){
off[i][0]=0.11;
off[i][1]=0.25;
off[i][2]=6.5;
}
dllHandle=LoadLibrary("Gpib32.dll");
sendcmd=(SEND *)GetProcAddress(dllHandle,"Send");
receive=(RECEIVE *)GetProcAddress(dllHandle,"Receive");
GetProfileString( "DWDM Dir","Config","wdmcfg.bin",path,MAX_PATH);
}
CTLSCtr::~CTLSCtr()
{
FreeLibrary(dllHandle);
}
void CTLSCtr::SetWL(double wl)
{
INIT * init;
init=(INIT *)GetProcAddress(dllHandle,"Init");
init();
cmmd.Format("sour0:wav %4.2fnm",wl);
char data[100];
int rs;
strcpy(data,(LPCTSTR)cmmd);
rs=sendcmd(0,5,data,0,0);
return;
}
BOOL CTLSCtr::GetWL(double *wl,int num)
{
long chx[5];
int i,j;
CStdioFile fp;
DWORD len,pos;
char mn[30];
BOOL f=FALSE;
int sn;
testf[num]=2;
if(chsp[num]<2){
for(i=0;i<5;i++){
if(chnum>65&&chnum<99.9)
chx[i]=180000+(chnum+(i-2)*(chsp[num]+1))*100;
else if(chnum>=0&&chnum<=64)
chx[i]=190000+(chnum+(i-2)*(chsp[num]+1))*100;
else return FALSE;
}
ntotal[num]=7;
np[num]=3;
npst[num]=2;
for(i=0,j=4;i<7;i++){
if(i<2)
wl[i]=(double)LV/chx[j--]+off[num][chsp[num]];
else if(i>=2&&i<=4){
if(i==2)
wl[i]=(double)LV/chx[j]-off[num][chsp[num]];
if(i==3)
wl[i]=(double)LV/chx[j];
if(i==4)
wl[i]=(double)LV/chx[j--]+off[num][chsp[num]];
}else
wl[i]=(double)LV/chx[j--]-off[num][chsp[num]];
}
}else if(chsp[num]==2){
ntotal[num]=5;
np[num]=3;
npst[num]=1;
for(i=-1;i<=1;i++){
if(i==0){
for(j=-1;j<=1;j++)
wl[i+1+j+1]=chnum+j*off[num][2];
}else if(i>0)
wl[4]=chnum+20-off[num][2];
else wl[0]=chnum-20+off[num][2];
}
}else {
if(!fp.Open(path,CFile::modeNoTruncate|CFile::typeBinary))
return FALSE;
len=fp.GetLength();
pos=fp.GetPosition();
while(pos