/// <summary> /// /// Starts up Vimba API and loads all transport layers /// </summary> /// <param name="cameraListChangedHandler">The event handler to handle the camea list changed event</param> public void Startup(CameraListChangedHandler cameraListChangedHandler) { //Instanciate main Vimba object Vimba vimba = new Vimba(); //Start up Vimba API vimba.Startup(); m_Vimba = vimba; bool bError = true; try { //Register camera list change delegate if (null != cameraListChangedHandler) { m_Vimba.OnCameraListChanged += this.OnCameraListChange; m_CameraListChangedHandler = cameraListChangedHandler; } bError = false; } finally { //Release Vimba API if an error occured if (true == bError) { ReleaseVimba(); } } }
/// <summary> /// Releases the camera /// Shuts down Vimba /// </summary> private void ReleaseVimba() { if (m_Vimba != null) { //We can use cascaded try-finally blocks to release the //Vimba API step by step to make sure that every step is executed. try { try { if (null != m_CameraListChangedHandler) { m_Vimba.OnCameraListChanged -= this.OnCameraListChange; } } finally { //Now finally shutdown the API m_CameraListChangedHandler = null; m_Vimba.Shutdown(); } } finally { m_Vimba = null; } } }
/// <summary> /// The event handler for the camera list changed event /// </summary> /// <param name="reason">The reason why this event was fired</param> private void OnCameraListChange(VmbUpdateTriggerType reason) { switch (reason) { case VmbUpdateTriggerType.VmbUpdateTriggerPluggedIn: case VmbUpdateTriggerType.VmbUpdateTriggerPluggedOut: { CameraListChangedHandler cameraListChangedHandler = m_CameraListChangedHandler; if (null != cameraListChangedHandler) { cameraListChangedHandler(this, EventArgs.Empty); } } break; default: break; } }
/// <summary> /// Releases the camera /// Shuts down Vimba /// </summary> private void ReleaseVimba() { if (null != this.m_Vimba) { // We can use cascaded try-finally blocks to release the // Vimba API step by step to make sure that every step is executed. try { try { try { // First we release the camera (if there is one) this.ReleaseCamera(); } finally { if (null != this.m_CameraListChangedHandler) { this.m_Vimba.OnCameraListChanged -= this.OnCameraListChange; } } } finally { // Now finally shutdown the API this.m_CameraListChangedHandler = null; this.m_Vimba.Shutdown(); } } finally { this.m_Vimba = null; } } }