int CProcessThread::Run()
{
	while(1)
	{	
		ofstream m_ofsLog8;   //日志文件流,用于储存接收的消息
		m_ofsLog8.open("log-8读取图像消息.txt",ios::app);
		if(work)
		{  
			int m_width=0, m_height=0, len=0;
			CameraGetImageSize(m_ProcessIndex,&m_width, &m_height);
			CameraGetImageBufferSize(m_ProcessIndex,&len, CAMERA_IMAGE_GRAY8/*CAMERA_IMAGE_BMP*/);	
			unsigned char *m_inBuf = new unsigned char[len];
		
		    if(CameraQueryImage(m_ProcessIndex,m_inBuf, &len, CAMERA_IMAGE_GRAY8/*CAMERA_IMAGE_BMP*/)==API_OK)			
			{	
				// 获取当前系统时间
				time_t t = time( 0 ); 			
				strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A",localtime(&t) );	
				m_ofsLog8<<tmp<<"--------------读取图像成功\n"; // 接收的消息

		    	//CameraVertFlipBuf(m_inBuf,m_width*3,m_height);
				// draw lines 
			/*	for (int i= 100; i<=120; i++)
				{
					for (int j=0; j<m_width; j++)
					{
						*(m_inBuf+(i*m_width+j)*3+0) = 0x00;
						*(m_inBuf+(i*m_width+j)*3+1) = 0x00;
						*(m_inBuf+(i*m_width+j)*3+2) = 0xff;
					}
				}*/

				PicInformation tempInformation;
				tempInformation.m_image=m_inBuf;
				tempInformation.width=m_width;
				tempInformation.height=m_height;
				CMicroMecanumDlg *hwnd=(CMicroMecanumDlg * )AfxGetMainWnd();  
				hwnd->SendMessage(WM_PROCESS_MESSAGE,0,(LPARAM)&tempInformation);
				
			}
			else
			{
				// 获取当前系统时间
				time_t t = time( 0 ); 			
				strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A",localtime(&t) );				
				m_ofsLog8<<tmp<<"--------------读取图像失败\n"; // 接收的消息
				delete []m_inBuf;
				Sleep(10);
			}			
		}
		m_ofsLog8.close();
    }
	return 1;
}
Beispiel #2
0
int CALLBACK SnapThreadCallback(BYTE *pBuffer)
{
#if 0
	int Width = 0;
	int Height= 0;
	if (STATUS_OK != CameraGetImageSize(&Width, &Height))
	{
		return FALSE;	
	}
	for (int i= 100; i<=101; i++)
	{
		for (int j=0; j<Width; j++)
		{
			*(pBuffer+(i*Width+j)*3+0) = 0x00;
			*(pBuffer+(i*Width+j)*3+1) = 0x00;
			*(pBuffer+(i*Width+j)*3+2) = 0xff;
		}
	}
#endif
	return TRUE;
}
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;
	}
}