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

📄 pci_7200.cpp

📁 VC写的PCI7200数据采集卡控制CCD程序
💻 CPP
字号:
// PCI_7200.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "PCI_7200.h"
#include <time.h> 
#include "String.h"
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}



// This is an example of an exported variable
//PCI_7200_API int nPCI_7200=0;

// This is an example of an exported function.
//PCI_7200_API int fnPCI_7200(void)
//{
//	return 42;
//}

// This is the constructor of a class that has been exported.
// see PCI_7200.h for the class definition

//CPCI_7200::CPCI_7200()
//{ 
//	return; 
//}

bool InitCCD(U8 CCDNumber)
{
	U16 CardNum=0;
	U32 BufSize;
	if(Register_Card (PCI_7200, CardNum)<0)//regiser card
	{
		MessageBox(NULL,"No card detected!","Warnning",MB_OK); 
		return false;
	}
	//Check buffersize
	DI_InitialMemoryAllocated(CardNum,&BufSize);
	if(BufSize<16384*CCDNumber)
	{
		MessageBox(NULL,"Not enough DMA buffer!","Warnning",MB_OK); 
		return false;
	}
	//PCI 7200 card now working in DMA mode, 
	//and will be started by CN2 pin37, eq I_TRIG of PCI7200
	DI_7200_Config(CardNum,TRIG_EXT_STROBE,DI_WAITING,DI_TRIG_RISING,IREQ_FALLING);//外部触发模式
	//non-double_buffered mode
	DI_AsyncDblBufferMode(CardNum,0);//单缓冲模式
	AcqDataBuf=(AcqData*)new AcqData[4096*1024];//申请内存
	//reset shutter
	ResetShutter();//复位快门
	return true;
}

void CloseCCD()
{
	U16 CardNum=0;
	U32 count;
	DI_AsyncClear(CardNum, &count);
	//reset shutter
	ResetShutter();//复位快门
	if(AcqDataBuf!=NULL)//删除内存
		delete []AcqDataBuf;
	Release_Card(0);
}

void ResetShutter()
{
	U16 CardNum=0;
	//line0: dark frame; line1: close;line2: open
	DO_WritePort(CardNum,0,0); 
	DO_WritePort(CardNum,0,0x07);//
	Sleep(50);
	DO_WritePort(CardNum,0,0x03);
	DO_WritePort(CardNum,0,0x02);
	DO_WritePort(CardNum,0,0x00);
	/*
	DO_WriteLine(CardNum,0,2,0);
	DO_WriteLine(CardNum,0,2,1);
	DO_WriteLine(CardNum,0,2,0);//a positive pulse is send to line 2 of output
	*/
} 

void OpenShutter(bool Light)//line0: dark frame;line2: open; line1: close
{
	U16 CardNum=0;
	//line0: dark frame; line1: close;line2: open
	if(Light)
	{
		DO_WritePort(CardNum,0,0);  
		DO_WritePort(CardNum,0,0x04);  
		Sleep(50);
		DO_WritePort(CardNum,0,0);
	}
	else//暗场
	{
		DO_WritePort(CardNum,0,0);  
		DO_WritePort(CardNum,0,0x1);
		Sleep(50);
		DO_WritePort(CardNum,0,0);
	}
}

void CloseShutter()
{
	U16 CardNum=0;
	//line0: dark frame; line1: close;line2: open
	DO_WritePort(CardNum,0,0);
	DO_WritePort(CardNum,0,0x02);
	Sleep(50);
	DO_WritePort(CardNum,0,0);
}

void AbortExposureCCD()
{
	U16 CardNum=0;
	U32 count;
	DI_AsyncClear (CardNum, &count);
	ResetShutter();
}

void StartExposureCCD(bool Light)
{
	U16 CardNum=0;
	U8 CCDNumber=1;
	DI_ContReadPort(CardNum,0,AcqDataBuf,1024*4096*CCDNumber,CLKSRC_EXT_SampRate,ASYNCH_OP);//soso改,原来为1023*4096,SYNCH_OP
	OpenShutter(Light);
}

void StopExposureCCD()
{
	CloseShutter();
}

U32 CaptureCCD(U8 CCDNumber,U16 buffer[],U16 WaitTime)
{
/*
	[Example Code Fragment] 
	card = Register_Card(PCI_7200, card_number); 
	...  
	DI_7200_Config(card,TRIG_INT_PACER, DI_NOWAITING, DI_TRIG_FALLING, IREQ_FALLING); 
	DI_AsyncDblBufferMode (card, 0); // non-double-buffered mode 
	DI_ContReadPort(card, 0, pMem, data_size, (F64)sample_rate, ASYNCH_OP) 
		 do { 
		   DI_AsyncCheck(card, &bStopped, &count); 
				  } while (!bStopped);  
	DI_AsyncClear(card, &count); 
					  ... 
	Release_Card(card);
*/
	BOOLEAN bStopped;
	U32 count;
	clock_t start,end;
	U16 CardNum=0;
	unsigned short i,j;
	//AcqDataBuf=(AcqData*)new AcqData[4096*1024];//申请内存
	//DI_ContReadPort(CardNum,0,AcqDataBuf,1024*4096*CCDNumber,CLKSRC_EXT_SampRate,ASYNCH_OP);//soso改,原来为1023*4096,SYNCH_OP
	start=clock();
	while(1)	//进入循环,等待DMA结束
	{
		DI_AsyncCheck(CardNum, &bStopped, &count);
		if(bStopped)//数据传输完成
		{
			DI_AsyncClear(CardNum, &count);
			//读数据
			if(CCDNumber==1)
			{
				for(i=0;i<4096;i++)
					for(j=0; j<1024;j++)
					{   
						buffer[i*2048+j]=(AcqDataBuf+i*1024+j)->InDataLeft;
						buffer[i*2048+2047-j]=(AcqDataBuf+i*1024+j)->InDataRight;
					}
			}
			break;
		}
		else
		{
			//检验是否超时
			end=clock();
			if(end-start>=WaitTime*1000)
			{
				DI_AsyncClear(CardNum, &count);
				MessageBox(NULL,"DMA timeout!","Warnning",MB_OK); 
				break;
			}	
		}
	}
	//if(AcqDataBuf!=NULL)//删除内存
	//	delete []AcqDataBuf; 
	return count;
}

⌨️ 快捷键说明

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