PDA

View Full Version : Problem restarting livevideo after DeviceLost



Florian Meuche
June 3, 2010, 14:40:35
Hi,

i have already read the posts regarding the device lost event and how to reconnect a lost video device.
But i cant get it to work.
Basically i am starting a timer which looks for the number of connected devices.
If a device is found i set the device name to an empty String and so on.
After that i check if the found device is valid and after that i call LiveStart.
Then the application is hanging without any exception.

I am using a DFK USB-lt2 Video Konverter and a PAL Kamera connected via S-Video.
The Software is written in vb.net / c# in Visual Studio 2008.i Have installed IC Imaging Control Version 3.0.6.

Thanks for any suggestions...

Stefan Geissler
June 3, 2010, 17:27:54
The application hanging without any message sounds for a threading problem. I suppose, you simply enable a timer in the device lost event. How does your device lost event handler and timer event handler look like?

You should not display any information in form controls directly from the device lost event. You can do this using delegates.

Florian Meuche
June 4, 2010, 10:23:02
The Event Handler look like this:



namespace Grabberchecker
{

public partial class Form1 : Form
{
String Devicename;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
if (icImagingControl1.DeviceValid)
{
Devicename = icImagingControl1.Devices[0].Name;
icImagingControl1.LiveStart();
}
}

private void icImagingControl1_DeviceLost(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1_Tick(sender, e);
Application.DoEvents(); // the timer.tick event is only fired if there is a breakpoint within
// otherwise the application is hanging...
}

private void timer1_Tick(object sender, EventArgs e)
{
if (icImagingControl1.Devices.Length>0)
{
timer1.Enabled = false;
if (icImagingControl1.Device != "") // Device = "DFG/USB2-lt"
{
icImagingControl1.Device = ""; //no Device open
}
icImagingControl1.Device = Devicename; // Device = "DFG/USB2-lt"
if (icImagingControl1.DeviceValid) // true
icImagingControl1.LiveStart(); // after that the DeviceSettings are lost/reseted..
}
}


}
}

Stefan Geissler
June 4, 2010, 14:44:45
Hi Florian,

please remove
timer1_Tick(sender, e);
Application.DoEvents();

This causes your application hanging, because these functions called from a different thread than your form's thread. Usually timer1.Enabled = true; starts the timer, thus the timer event is called correctly from the Form's thread.

Florian Meuche
June 4, 2010, 15:09:27
Hallo Stefan,

thanks for Your reply but if i do so the Application keeps hanging and the Timer is not started even if i set a breakpoint inside the Tick Event Handler.
I think it is some kind of driver problem, because after the Device Lost event everything is froozen...

Stefan Geissler
June 4, 2010, 16:06:39
Hello.

please remove all from the Device Lost event and check, whether the application keeps hanging.

Also remove the lines
if (icImagingControl1.Device != "") // Device = "DFG/USB2-lt"
{
icImagingControl1.Device = ""; //no Device open
}

They are not needed, because the device already has gone.

I also suggest to set the timer intervall to at least 100ms.

Florian Meuche
June 7, 2010, 11:11:08
Hello,

if there is no code inside the Device Lost event, the application keeps running,
otherwise it hangs.

The Timer Interval is 200ms.

Best Regards

Florian

Stefan Geissler
June 7, 2010, 17:30:36
And did you enable the timer in your timer event?

Florian Meuche
June 8, 2010, 09:33:34
I enabled the timer in a button click event. I started the application, unplugged the video konverter without any code inside the device lost event and clicked the button. Then the timer was started and the application kept running.

If i enable the timer within the device lost event the timer is not started and the application is hanging. I also tried to start a backgroundworker and a while loop within the device lost event with the same result.

I tried this on three different computers and two different video konverters, all with win xp sp3 and ic imaging control 3.0.6 with the same result. I also tried diffent USB cables and ports...

Florian Meuche
June 8, 2010, 10:16:31
I have downloaded and installed another device driver for the Video Konverter (v1.0.1.6) and tried it again.

Now it is working if i enable the Timer by a button click. If the timer is enabled by the device lost event it´s hanging again.

Here is the code example:



using System;
using System.Windows.Forms;

namespace Grabberchecker
{
public partial class Form1 : Form
{
String Devicename;
Int32 ticker = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (icImagingControl1.DeviceValid)
{
Devicename = icImagingControl1.Devices[0].Name;
icImagingControl1.LiveStart();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (icImagingControl1.Devices.Length > 0)
{
timer1.Enabled = false;
icImagingControl1.Device = Devicename; // Device = "DFG/USB2-lt"
if (icImagingControl1.DeviceValid) // true
{
icImagingControl1.VideoFormat = "UYVY (768x576)"; //after unplugging, the Video Format is set to "UYVY (352x288)"
icImagingControl1.InputChannel = "01 Video: SVideo"; //after unplugging,the Input Channel is set to "00 Video: Composite"
icImagingControl1.LiveStart();
}
}
ticker++;
textBox1.Text = Convert.ToString(ticker); // this is only for checking if the timer is running...
Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true; // with the button_click everything works fine
}
private void icImagingControl1_DeviceLost(object sender, EventArgs e)
{
//timer1.Enabled = true; if i do something here it´s all over!
}
}
}



Is it a normal behaviour that the input channel and the video Format is reseted after the device lost event?

Florian

Stefan Geissler
June 8, 2010, 13:20:08
Hello


Is it a normal behaviour that the input channel and the video Format is reseted after the device lost event?

Yes, this is normal. No one saves this, except you use SaveDeviceStatetoFile and LoadDeviceStateFromFile.

You may create a support case at http://www.imagingcontrol.com/en_US/support/case/ thus you can send me a small sample project that reproduces your problem.

Stefan Geissler
June 8, 2010, 18:02:08
Hello,

using IC Imaging Control 3.0 you must use Delegates to do something in your main thread:



public delegate void EnableTimerDelegate();

private void EnableTimer()
{
timer1.Enabled = true;
}

private void icImagingControl1_DeviceLost(object sender, EventArgs e)
{
BeginInvoke(new EnableTimerDelegate(EnableTimer));
}


Then all is working fine!