/// <summary> /// update all cameras /// </summary> /// <param name="state">vision state</param> private void Update(WebcamVisionStereo state) { DateTime reference_time = new DateTime(2008, 1, 1); int time_step_mS = (int)(1000 / state.fps); bool grabbed = false; time_step_mS = (int)(1000 / state.fps); DateTime last_called = DateTime.Now; const int sleep_time_mS = 100; bool looping = true; while (looping) { if (!Pause) { // grab images if (state.active_camera) { DateTime start_time = DateTime.Now; state.Grab(); _callback(_data); grabbed = true; TimeSpan diff = DateTime.Now.Subtract(start_time); while ((diff.TotalMilliseconds < time_step_mS) && (state.Running)) { diff = DateTime.Now.Subtract(start_time); Thread.Sleep(sleep_time_mS); } } else { Thread.Sleep(sleep_time_mS); } } else { //for (int i = 0; i < 100; i++) Thread.Sleep(sleep_time_mS); _callback(_data); } if (grabbed) { if ((PauseFile != null) && (PauseFile != "")) { if (File.Exists(PauseFile)) { Pause = true; } else { Pause = false; } } } // break out if (((_loop) && (!state.Running)) || (!_loop)) { looping = false; } } }
/// <summary> /// update all cameras /// </summary> /// <param name="state">vision state</param> private void Update(WebcamVisionStereo state) { DateTime reference_time = new DateTime(2008, 1, 1); int time_step_mS = (int)(1000 / state.fps); bool grabbed = false; time_step_mS = (int)(1000 / state.fps); DateTime last_called = DateTime.Now; const int sleep_time_mS = 100; bool looping = true; while (looping) { if (!Pause) { // grab images if (state.active_camera) { DateTime start_time = DateTime.Now; state.Grab(); _callback(_data); grabbed = true; TimeSpan diff = DateTime.Now.Subtract(start_time); while ((diff.TotalMilliseconds < time_step_mS) && (state.Running)) { diff = DateTime.Now.Subtract(start_time); Thread.Sleep(sleep_time_mS); } } else { Thread.Sleep(sleep_time_mS); } } else { //for (int i = 0; i < 100; i++) Thread.Sleep(sleep_time_mS); _callback(_data); } if (grabbed) { if ((PauseFile != null) && (PauseFile != "")) { if (File.Exists(PauseFile)) Pause = true; else Pause = false; } } // break out if (((_loop) && (!state.Running)) || (!_loop)) looping = false; } }
/// <summary> /// ThreadStart delegate /// </summary> public void Execute() { WebcamVisionStereo state = (WebcamVisionStereo)_data; Update(state); }