PDA

View Full Version : DeviceLost event



Rob
October 27, 2003, 12:12:47
I am trying to cope with cameras being disconnected and re-connected

The DeviceLost event is fired when the camera is disconnected

Later when the camera is connected again I try to open the device again.
ImagingControl.Device already has the current device name e.g. "Video to 1394 converter" and ImagingControl.DeviceValid is false. Because the device is still invalid, no properties (VideoNorm / VideoFormat) etc. are available. Trying to set Device to empty string "" results in an error. How do I reopen the device?

In your documentation you suggest setting ImagingControl.Device property to an empty string. I find that this results in an error

Run-Time error '32' - The function failed because parts of the object were locked, try again later.

So I do not try this in the DeviceLost event.

What is the correct way to handle cameras being disconnected and connected ?

Rob

Stefan Geissler
October 28, 2003, 14:51:29
Rob,

A reconnection handler could be implemented as follows:


Private Sub cmdReconnect_Click()
' Check, whether there any devices connected
If ICImagingControl1.Devices.Count > 0 Then
' Now we can reset IC Imaging Control
ICImagingControl1.Device = ""
' Use the previously saved device name for reconnection
If CurrentDevice <> "" Then
ICImagingControl1.Device = CurrentDevice
ICImagingControl1.LiveStart
End If
Else
MsgBox "No devices found!"
End If
End Sub


This code segment is not for the Devicelost event handler. It could be used for a reconnect button or in a timer event, sub.

Stefan Geissler
October 28, 2003, 14:59:11
The following code is used to reconnect a lost device automatically. If the device lost event is fired, the timer1 is enabled. In the timer event sub, it is checked, whether a video capture device is connected to the computer. If so, it is opened.


Dim CurrentDevice As String

Private Sub Form_Load()
ICImagingControl1.Device = "DFK 21F04"
If ICImagingControl1.DeviceValid = True Then
Timer1.Enabled = False
CurrentDevice = ICImagingControl1.Device
Caption = CurrentDevice
ICImagingControl1.LiveStart
Else
Timer1.Enabled = True
End If
End Sub

Private Sub ICImagingControl1_DeviceLost()
MsgBox "Device lost"
Caption = "No device"
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
' Check, whether there a device connected
If ICImagingControl1.Devices.Count > 0 Then
' Disable the timer
Timer1.Enabled = False
If CurrentDevice <> "" Then
ICImagingControl1.Device = ""
ICImagingControl1.Device = CurrentDevice
Caption = CurrentDevice
ICImagingControl1.LiveStart
End If
End If
End Sub

Rob
October 29, 2003, 10:50:07
Stefan,

Thanks for your prompt reply. I have tried the sample code you provided but at the line

ICImagingControl1.Device = ""

I get the following assert....

ASSERT Failed
0
At line 10178 of d:\builds\nt32_chk\multimedia\dshow\filters.ks\ksp roxy\ksutil.cpp
Continue? (Cancel to debug)

Which is the same error that I get in the app I am developing. I only get the assert if the device was running prior to being disconnected - i.e. if ICImagingControl.LiveStop was called before the camera was unplugged, it is reconnected without problems.

Stefan Geissler
October 29, 2003, 14:28:31
Rob,

The error does not occur on my computer. Please use the latest driver for the DFG/1394-1. You can download the driver at http://www.1394imaging.com/products/interfaces/dfg13941 . See “WDM driver”.
I have attached my Visual Basic project to this post. This project uses a timer to reconnect a lost DFG/1394-1 automatically.

Rob
October 30, 2003, 12:21:09
Stefan,

Thanks I certainly will try the DFG/1394-1 with the latest driver as soon as I can (unfortunately my unit is out on loan at the moment).

Just to complete the picture, I get this problem using any of the three cameras I have currently. They are

SONY DFW-X700
Unibrain Fire-i 400
and a Panasonic consumer video camera (NV-DS27)

Regards

Rob

Stefan Geissler
October 31, 2003, 10:33:52
Rob,

I have tested this code sample with a Sony DFW-VL500 and original Sony driver without any problems. I have used IC Imaging Control 1.41 and DirectX 8.1 for this project.

Stefan Geissler
November 3, 2003, 14:19:35
Rob,

If the debug version of DirectShow runtime is installed on your computer, then the error message you have reported, occurs any time you remove the video capture device. Therefore install the release runtime version of DirectShow (DirectX).