Exemple #1
0
void CMainFrame::on_dev_close_ccd()
{
	if(!theApp.m_CCD.m_isinit)
		return;
	DS_RUNMODE ccd_status=theApp.m_CCD.m_runstatus;

	//if(ccd_status==RUNMODE_PAUSE)
	CameraStop();
	CameraUnInit();
	theApp.m_CCD.m_isinit=FALSE;
	theApp.m_CCD.m_runstatus=RUNMODE_STOP;
}
void CDialog3::OnBnClickedExit()
{
	// TODO: 在此添加控件通知处理程序代码
	CameraStop(); //fp in dll
	CameraUnInit();
	this->SetDlgItemTextA(IDC_PLAY,"&Play");
	this->GetDlgItem(IDC_PLAY)->SetFocus();
	this->GetDlgItem(IDC_SAVEFILE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_SETUP)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_RESOLUTION)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_SAVEIMG)->EnableWindow(FALSE);
	m_RunMode =RUNMODE_STOP;
	return;

}
gboolean on_gtkdemo_window_delete_event      (GtkWidget       *widget,
                                            GdkEvent        *event,
                                            gpointer         user_data)
{
    int i=0;




    for(i=0;i<g_display_max;i++)
    {
        if(g_display_state[i]){
            g_display_state[i]=0;
            gdk_threads_leave ();
            CameraSetTriggerMode(g_hCamera[i], 0);
            pthread_join(g_thread_id[i], NULL);
        }
        if(g_readBuf[i]!=NULL){
            free(g_readBuf[i]);
            g_readBuf[i]=NULL;
        }
        if(g_pRgbBuffer[i]!=NULL){
            free(g_pRgbBuffer[i]);
            g_pRgbBuffer[i]=NULL;
        }
        if(g_hCamera[i]>0){
            //相机反初始化。释放资源。
            CameraUnInit(g_hCamera[i]);
            g_hCamera[i]=-1;
        }

    }


    gtk_main_quit();


 	return FALSE;
}
void CDialog3::OnBnClickedPlay()
{
	// TODO: 在此添加控件通知处理程序代码
	if(m_RunMode == RUNMODE_PLAY)
	{
		CameraStop(); //fp in dll
		CameraUnInit();
		this->SetDlgItemTextA(IDC_PLAY,"&Play");
		this->GetDlgItem(IDC_PLAY)->SetFocus();
		this->GetDlgItem(IDC_SAVEFILE)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_SETUP)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_RESOLUTION)->EnableWindow(FALSE);
		this->GetDlgItem(IDC_SAVEIMG)->EnableWindow(FALSE);
		m_RunMode =RUNMODE_STOP;
		return ;
	}
	else
	{
		BYTE CamNum = this->m_MultiCamList.GetCurSel();//取得组合框当前选中项的下标
		if(this->m_MultiCamList.GetCount() == 0)
		{
			CamNum = 0;
		}
		if(R_ROI == m_Resolution)
		{
			CameraSetROI(m_HOff, m_VOff, m_Width, m_Height); //fp in dll ,to set the resolution
		}
		if(STATUS_OK != CameraInit(SnapThreadCallback, 
			                       m_Resolution,
								   m_pDlg->GetDlgItem(IDC_PICTURE)->m_hWnd, //NULL
								   CamNum+1,
								   m_pDlg))
		 { 
			 MessageBox("Init Camera failed","Error",MB_OK|MB_ICONSTOP);
			 return ;
		}

#ifdef ENABLE_READ_SN_DEBUG
		char SN[32];
		CameraReadSN(SN, 32);
		CString sSN;
		sSN = SN;
		
		CString sUserSN = "WWW.D-IMAGE.NET 0755-61860636";
		if (sSN == sUserSN)
		{
		//	MessageBox(x, "SN is OK!", MB_OK | MB_ICONSTOP);
		}
		else //检查不对,重写一次,写之前请确保EEPROM处于可写状态。
		{
			char* pAddr = sUserSN.GetBuffer(32);
			
			CameraWriteSN(pAddr, 32);

			char cNewSn[32];
			CameraReadSN(cNewSn, 32);
			CString sNewSN = cNewSn;

			if (sNewSN == sUserSN )
			{		
				MessageBox("SN Rewrite Ok!", "SN Error", MB_OK | MB_ICONSTOP);
			}
			else
			{
				MessageBox("SN Rewrite Error!", "SN Error", MB_OK | MB_ICONSTOP);
			}
			CameraUnInit();
			return;
		}
#endif
		// Set AWB Window
		{
			INT width = 0;
			INT hight = 0;
			CameraGetImageSize(&width, &hight);
			CameraSetWBWindow(width>>2, hight>>2, width>>1, hight>>1);
		}
		this->SetDlgItemText(IDC_PLAY, "Sto&p");
		this->GetDlgItem(IDC_SAVEFILE)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_SETUP)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_RESOLUTION)->EnableWindow(TRUE);
		this->GetDlgItem(IDC_SAVEIMG)->EnableWindow(TRUE);
		
		/*WM_USERDEFMSG 用户自定义信息,通过CameraSetMessage()函数得到相机
		Message ID;该Message ID含有Wparam和Lparam信息,将它们传递到信息
		响应函数OnVideoMsg()当中进行判断和处理*/
		CameraSetMessage(this->m_hWnd, WM_USERDEFMSG);
		CameraPlay();
		m_iVideoCnt = 0;
		m_iErrorFrames = 0;
		m_RunMode = RUNMODE_PLAY;
		return;
	}
}