PDA

View Full Version : how to know when camera is disconnected?



akfromvizzitec
June 20, 2007, 11:45:23
hi friend!

im using the image source camera in my MFC project (vc6.0)

when the camera is running (in live), if there is any problem with cable, camera or any malfunction, how to catch that error and also i need show the error to another dialog which i have created in my project..?

im using MFC dialog based application.

thanks in advance

truly..

AK

Stefan Geissler
June 20, 2007, 12:59:10
Hello AK,

In order to detect a lost camera you can use the device lost event:

http://www.imagingcontrol.com/support/documentation/class/meth_descGrabberListener_deviceLost.htm

If you inherit an own class from GrabberListener, you can past the handle of your application's window to the new class. If the DeviceLost event fires, you can post a message to your main application. The application can react in its message handler to this message.

Following code shows the deviceLost method in the GrabberListener inherited CListener class:


//////////////////////////////////////////////////////////////////////////
/*! Set the parent window handle that recieves the device lost
message. It must be called from the application's main window.
*/
void CListener::SetParentWindow(CWnd *pcDrawWindow)
{
m_hParentWindow = pcDrawWindow;
}


void CListener::deviceLost( Grabber& param)
{
m_hParentWindow->PostMessage(WM_USER+1,0,0);
}


In the application's window the message map must be enhanced:


BEGIN_MESSAGE_MAP(CTesterDlg, CDialog)
//{{AFX_MSG_MAP(CTesterDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER+1, OnDeviceLost) // <- Its the new message!
END_MESSAGE_MAP()


And this is the "OnDeviceLost" method:


void CTesterDlg::OnDeviceLost()
{
// Clear the grabber obkect.
m_pcGrabber->stopLive();
m_pcGrabber->closeDev();

MessageBox("Device Lost","Tester");
}