/// <summary> /// On shutdown we need to dispose our object manually before disposing the control /// </summary> public new void Dispose() { addLog("Dispose() called..."); #if USE_ENTER_KEY #else _continueWait = false; //signal thread to stop Thread.Sleep(100); SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false); waitEvent.PulseEvent(); Thread.Sleep(100); restoreKey(); #endif if (IntermecCamera != null) { #if STREAMING_ON addLog("...Dispose() we DO NOT SWITCH streaming"); #else IntermecCamera.Streaming = false; #endif IntermecCamera.Dispose(); IntermecCamera = null; } #if USE_ENTER_KEY #else //enable HW Trigger of Scanner //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); YetAnotherHelperClass.setHWTrigger(true); #endif #if REMAP_SCAN_TO_ENTERKEY restoreScanKey(); #endif Cursor.Current = Cursors.Default; //base.Dispose(); do not use!! addLog("...Dispose() finished"); }
/// <summary> /// On shutdown we need to dispose our object manually before disposing the control /// </summary> public new void Dispose() { addLog("Dispose() called..."); if (waitThread != null) { _continueWait = false; //signal thread to stop Thread.Sleep(100); SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false); waitEvent.PulseEvent(); Thread.Sleep(100); } //now the wait thread should been stopped if (IntermecCamera != null) { #if STREAMING_ON addLog("...Dispose() we DO NOT SWITCH streaming"); IntermecCamera.Streaming = false; #else IntermecCamera.Streaming = false; #endif IntermecCamera.Dispose(); IntermecCamera = null; } YetAnotherHelperClass.setHWTrigger(true); ITCTools.KeyBoard.restoreKey(); Cursor.Current = Cursors.Default; //Dispose() //base.Dispose(); do not use!! addLog("...Dispose() finished"); }
public new void Dispose() { addLog("Dispose() called..."); _continueWait = false; //signal thread to stop Thread.Sleep(100); SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false); waitEvent.PulseEvent(); Thread.Sleep(100); #if STREAMING_ON //kill SnapShot Thread if (snapshotThread != null) { int iCount = 0; while (iCount < 10 && _bSnapShotThreadRunning) { Thread.Sleep(500); iCount++; } if (_bSnapShotThreadRunning) { if (snapshotThread != null) { snapshotThread.Abort(); } } } #endif Thread.Sleep(100); if (_imager != null) { //restore AimerFlashing mode _imager.AimerFlashing = Imager.AimerFlashingMode.Auto; _imager.LightGoal = 128; _imager.VideoRunning = false; _imager.Dispose(); _imager = null; } //enable HW Trigger of Scanner //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); //removed as problems with ADCComInterface YetAnotherHelperClass.setHWTrigger(true); restoreKey(); Cursor.Current = Cursors.Default; // base.Dispose(); do not use!! addLog("...Dispose() finished"); }
/// <summary> /// Init the CameraControl /// </summary> public IntermecCameraControl2() { InitializeComponent(); #if USE_ENTER_KEY #else //disable HW Trigger of Scanner //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(false); YetAnotherHelperClass.setHWTrigger(false); #endif try { if (IntermecCamera != null) { addLog("Init() old IntermecCamera found. Disposing..."); // IntermecCamera.Streaming = false; //we dont switch streaming except once, ALL THE TIME IntermecCamera.Dispose(); IntermecCamera = null; } else { addLog("Init() Creating NEW IntermecCamera..."); } //added to check for exception in creating a new Camera int iTry = 1; bool bSuccess = false; string sEx = ""; do { try { //using the same sequence as in sample CN3Camera IntermecCamera = new Camera(CameraPreview, Camera.ImageResolutionType.Medium); //IntermecCamera.PictureBoxUpdate = Camera.PictureBoxUpdateType.None; IntermecCamera.PictureBoxUpdate = Camera.PictureBoxUpdateType.Fit; // None;// Fit;// AdjustToFrameSize; bSuccess = true; addLog("Init() IntermecCamera creation OK. Try " + iTry.ToString() + " of 3"); } catch (Intermec.Multimedia.CameraException ex) { sEx = ex.Message; addLog("Init() IntermecCamera creation failed. Try " + iTry.ToString() + " of 3 \nCameraException: \n" + ex.Message); } catch (Exception ex) { sEx = ex.Message; addLog("Init() IntermecCamera creation failed. Try " + iTry.ToString() + " of 3 \nException: \n" + ex.Message); } finally { GC.Collect(); iTry++; } } while (iTry <= 3 && !bSuccess); if (IntermecCamera == null) { throw new FileNotFoundException("IntermecCamera did not load. CnxDShow.cab installed?\nException: " + sEx); } // moving to end of INIT() does not fix problem with NO STREAM AT FIRST INIT()! #if STREAMING_ON addLog("Init() 1 IntermecCamera.Streaming=true..."); IntermecCamera.Streaming = true; //we start with streaming = true ALL THE TIME #else addLog("Init() 1 IntermecCamera.Streaming=true..."); IntermecCamera.Streaming = true; //we start with streaming = true ALL THE TIME #endif #region AutoFlash try { addLog("IntermecCamera testing Flash.Available..."); if (IntermecCamera.Features.Flash.Available) { addLog("IntermecCamera testing Flash.Available OK. Changing to Auto..."); if (IntermecCamera.Features.Flash.SupportsAutoMode) { addLog("IntermecCamera testing Flash.Available OK. Changed to Auto OK"); IntermecCamera.Features.Flash.Auto = true; } else { addLog("IntermecCamera testing Flash.Available OK. No AutoMode support"); } } else { addLog("IntermecCamera testing Flash.Available OK. No Flash support"); } } catch (Exception) { addLog("IntermecCamera testing Flash throwed exception."); } #endregion #if MYDEBUG //for DEBUG only System.Diagnostics.Debug.WriteLine("CurrentViewfinderResolution 1=" + IntermecCamera.CurrentViewfinderResolution.Width.ToString() + "x" + IntermecCamera.CurrentViewfinderResolution.Height.ToString()); #endif //System.Diagnostics.Debug.WriteLine("Current viewfinderRes 2=" + // IntermecCamera.CurrentViewfinderResolution.Width.ToString() + "x" + // IntermecCamera.CurrentViewfinderResolution.Height.ToString()); //moved to end //######## IntermecCamera.SnapshotEvent += new SnapshotEventHandler(IntermecCamera_SnapshotEvent); //IntermecCamera.SnapshotFile.Filename = "FotoKamera_"+ DateTime.Now.ToShortDateString()+ "_" + DateTime.Now.ToShortTimeString() + ".jpg"; IntermecCamera.SnapshotFile.ImageFormatType = Camera.ImageType.JPG; //WARNING, if you dont set this property, snapshot may fail with garbage image IntermecCamera.SnapshotFile.ImageResolution = Camera.ImageResolutionType.Medium; IntermecCamera.SnapshotFile.JPGQuality = 90; IntermecCamera.SnapshotFile.Directory = "\\Temp"; IntermecCamera.SnapshotFile.Filename = _sFileTemplate; IntermecCamera.SnapshotFile.FilenamePadding = Camera.FilenamePaddingType.IncrementalCounter;// None;// Camera.FilenamePaddingType.IncrementalCounter; #if USE_ENTER_KEY #if USE_PRESS_N_HOLD showSnapshot(true); //show a still image #endif #else //remap scan button key to new events mapKey(); //start the scan button watch thread addLog("IntermecBarcodescanControl: starting named event watch thread..."); waitThread = new System.Threading.Thread(waitLoop); waitThread.Start(); #endif #if STREAMING_ON addLog("Init(): we DO NOT SWITCH streaming"); #else addLog("Init() IntermecCamera.Streaming=false..."); IntermecCamera.Streaming = false; //we use streaming=true ALL THE TIME #endif #if REMAP_SCAN_TO_ENTERKEY mapScan2Enter(); #endif //######### TEST ####### does not fix problem with NO STREAM AT FIRST INIT()! //addLog("Init() IntermecCamera.Streaming=true at END of INIT()..."); //IntermecCamera.Streaming = true; //we use streaming=true ALL THE TIME //CameraPreview.Refresh(); //ImageIsInPreview(); // Hook the snapshot event. IntermecCamera.SnapshotEvent += new SnapshotEventHandler(IntermecCamera_SnapshotEvent); } catch (Intermec.Multimedia.CameraException ex) { addLog("CameraException in CameraInit. Is the runtime 'CNxDShow.CAB' installed? " + ex.Message); } catch (Exception ex) { addLog("Exception in CameraInit. Is the runtime 'CNxDShow.CAB' installed?\n" + ex.Message); } if (IntermecCamera == null) { System.Diagnostics.Debug.WriteLine("Exception in CameraInit. Is the runtime 'CNxDShow.CAB' installed?"); throw new FileNotFoundException("Missing Runtimes. Is CNxDShow.CAB installed?"); } //if (IntermecCamera == null) // return; }
public IntermecImagerControl2() { InitializeComponent(); //setup imager try { //disable HW Trigger of Scanner //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(false); //removed as problems with ADCComInterface YetAnotherHelperClass.setHWTrigger(false); _imager = new Imager(ImagerPreview, Imager.PictureResolutionSize.Quarter); _imager.ImagerMode = Imager.ImagerModeType.Imaging; _imager.OnScreenLogo = Imager.OnScreenLogoType.Off; if (_imager.ImageConditioningAvailable) { //change according to Bo Shang, eMail of 22. Juli 2011 02:16 _imager.ImageConditioning.ContrastEnhancement = ImageConditioning.ContrastEnhancementValue.Photo; _imager.ImageConditioning.TextEnhancement = ImageConditioning.TextEnhancementValue.None; _imager.ImageConditioning.ImageRotation = ImageConditioning.ImageRotationValue.None; //use the following to enhance streaming performance _imager.ImageConditioning.Subsampling = ImageConditioning.SubsamplingValue.OneOfEight;// ImageConditioning.SubsamplingValue.None; _imager.ImageConditioning.NoiseReduction = 0; //DO NOT USE other than NONE, a bug will then show a blank preview video _imager.ImageConditioning.ImageLightingCorrection = ImageConditioning.ImageLightingCorrectionValue.None;// Enabled;// None; _imager.ImageConditioning.Brightness = 20; //the following setting changes the image very strong (B&W to Gray) _imager.ImageConditioning.ColorMode = ImageConditioning.ColorModeValue.None;// None; //this for the preview AND changes the way of the snapshot _imager.ImageConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.VeryDark; _imager.ImageConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Bitmap; _imager.ImageConditioning.OutputCompressionQuality = 100; //shutoff laser illumination, gives system exception "Invalid Illumination Status value" //addLog("Trying to set Illumination...\n" + "Current IlluminationAimerStatus=" + _imager.IlluminationAimerStatus.ToString()); //_imager.IlluminationAimerStatus = Imager.IlluminationAimerActivationType.IlluminationOnly; addLog("Trying to set AimerFlashing...\n" + "Current AimerFlashing=" + _imager.AimerFlashing.ToString()); _imager.AimerFlashing = Imager.AimerFlashingMode.AlwaysOff; //_imager.IllumFlashing = Imager.IllumFlashingMode.Auto; addLog("Trying to set LightGoal...\n" + "Current LightGoal=" + _imager.LightGoal.ToString()); _imager.LightGoal = 150; //the following two settings are unsupported on current test device and OS //addLog("Trying to set SetAimerOn...\n" + "Current SetAimerOn=" + _imager.SetAimerOn.ToString()); //_imager.SetAimerOn = false; //addLog("Trying to set SetIllumOn...\n" + "Current SetIllumOn=" + _imager.SetIllumOn.ToString()); //_imager.SetIllumOn = false; //change defaults for snapshot file using explicit settings _imager.SnapShotConditioning.Brightness = 20; _imager.SnapShotConditioning.ColorConversion = ImageConditioning.ColorConversionValue.Grayscale; _imager.SnapShotConditioning.ColorMode = ImageConditioning.ColorModeValue.None; _imager.SnapShotConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.Normal; _imager.SnapShotConditioning.ContrastEnhancement = ImageConditioning.ContrastEnhancementValue.Photo; _imager.SnapShotConditioning.ImageLightingCorrection = ImageConditioning.ImageLightingCorrectionValue.None; _imager.SnapShotConditioning.ImageRotation = ImageConditioning.ImageRotationValue.None; _imager.SnapShotConditioning.NoiseReduction = 0; _imager.SnapShotConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Jpeg; _imager.SnapShotConditioning.OutputCompressionQuality = 80; _imager.SnapShotConditioning.Subsampling = ImageConditioning.SubsamplingValue.None; _imager.SnapShotConditioning.TextEnhancement = ImageConditioning.TextEnhancementValue.None; //change defaults for snapshot file by using already defined ImageConditioning values //disagreed by Bo Shang 3. aug. 2011 /* * _imager.SnapShotConditioning = _imager.ImageConditioning; * _imager.SnapShotConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Jpeg; * _imager.SnapShotConditioning.OutputCompressionQuality = 80; */ //_imager.SnapShotConditioning.Brightness = 20; //_imager.SnapShotConditioning.ColorMode = ImageConditioning.ColorModeValue.None; addLog("================== Imager ===================\n"); addLog(ImageHelper.dumpConditioningValues(_imager.ImageConditioning)); addLog("================= Snapshot ==================\n"); addLog(ImageHelper.dumpConditioningValues(_imager.SnapShotConditioning)); } else { _imager.EnhanceContrast = true; } //remap scan button key to new events ITCTools.KeyBoard.mapKey(); //start the scan button watch thread addLog("IntermecImagerControl-ImagerInit: starting named event watch thread..."); waitThread = new System.Threading.Thread(waitLoop); waitThread.Start(); #if NO_SNAPSHOT_THREAD #else this.OnImagerSnapshot += new IntermecImager_SnapshotEvent(IntermecImagerControl2_OnImagerSnapshot); #endif #if STREAMING_ON _imager.VideoRunning = true; //show hide the right pictureboxes ImagerPreview.Visible = false; ImagerSnapshot.Image = null; ImagerSnapshot.Refresh(); ImagerSnapshot.Visible = true; addLog("IntermecImagerControl2(): calling ShowSnapShot with true"); //showSnapshot(true); // we start with no streaming View #else //start with streaming=off showSnapshot(false); #endif } catch (Intermec.DataCollection.ImagerException ex) { addLog("ImagerException in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message); } catch (Exception ex) { addLog("Exception in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message); } if (_imager == null) { addLog("IntermecImagerControl: Imager init FAILED"); throw new System.IO.FileNotFoundException("IntermecImagerControl: Imager init FAILED - Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n"); } }