public new void Dispose() { addLog("IntermecScanControl Dispose()..."); #if USEWAITLOOP //stop WaitLoop thread _continueWait = false; //signal threads to stop SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false); waitEvent.PulseEvent(); System.Threading.Thread.Sleep(100); int iTry = 0; while (_bWaitLoopRunning && iTry < 5) { System.Threading.Thread.Sleep(300); iTry++; } addLog("IntermecScanControl Dispose(): ending Threads..."); //is the waitThread (waitLoop) still running? if (waitThread != null) { addLog("IntermecScanControl Dispose(): ending event watch thread ..."); waitThread.Abort(); } #endif //dispose BarcodeReader if (bcr != null) { // addLog("IntermecScanControl Dispose(): Calling CancelRead(true)..."); // bcr.CancelRead(true); addLog("IntermecScanControl Dispose(): Disposing BarcodeReader..."); //bcr.ThreadedRead(false); bcr.BarcodeRead -= bcr_BarcodeRead; bcr.Dispose(); bcr = null; addLog("IntermecScanControl Dispose(): BarcodeReader disposed"); } try { addLog("IntermecScanControl Dispose(): enabling HardwareTrigger..."); //replaced this call as ADCComInterface made problems //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); YetAnotherHelperClass.setHWTrigger(true); YetAnotherHelperClass.setNumberOfGoodReadBeeps(1); } catch (Exception ex) { addLog("IntermecScanControl Dispose(), Exception: enabling HardwareTrigger: " + ex.Message); } addLog("IntermecScanControl Dispose(): restoring Scan Button Key..."); ITCTools.KeyBoard.restoreKey(); addLog("...IntermecScanControl Dispose(): end."); //base.Dispose(); do not use!! }
public IntermecBarcodescanControl4() { InitializeComponent(); try { addLog("IntermecBarcodescanControl4: setHWTrigger(true)..."); //enable HW trigger, a workaround as HW trigger is sometimes disabled on BarcodeReader.Dispose() //if (!S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true)) //{ // addLog("IntermecBarcodescanControl4: setHWTrigger(true)...FAILED. Trying again"); // Thread.Sleep(50); // S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); //try again //} //replaced above code with the following, there were problems with load/unload the ADCComInterface inside S9CConfig YetAnotherHelperClass.setHWTrigger(true); //change number of good read beeps to zero YetAnotherHelperClass.setNumberOfGoodReadBeeps(0); addLog("IntermecBarcodescanControl4: mapKey()..."); //we need full control of scan start and end //ITCTools.KeyBoard.mapKey(); //we use the standard scan key assignement: addLog("IntermecBarcodescanControl4: restoreScanKeyDefault()..."); ITCTools.KeyBoard.restoreScanKeyDefault(); } catch (Exception ex) { addLog("Exception in IntermecBarcodescanControl4: setHWTrigger(true)..." + ex.Message); } try { //Cannot use Keydown etc within a usercontrol, we will not get the events!!!!! //ITCTools.KeyBoard.createMultiKey(); #if USEWAITLOOP addLog("IntermecBarcodescanControl2: starting named event watch thread..."); waitThread = new System.Threading.Thread(waitLoop); waitThread.Start(); #endif addLog("IntermecBarcodescanControl4: new BarcodeReader()..."); //create a new BarcodeReader instance bcr = new BarcodeReader(this, "default");// (); addLog("IntermecBarcodescanControl4: BarcodeReader adding event handlers..."); bcr.BarcodeRead += new BarcodeReadEventHandler(bcr_BarcodeRead); bcr.BarcodeReadCanceled += new BarcodeReadCancelEventHandler(bcr_BarcodeReadCanceled); bcr.BarcodeReadError += new BarcodeReadErrorEventHandler(bcr_BarcodeReadError); addLog("IntermecBarcodescanControl4: enabling Scanner..."); bcr.ScannerEnable = true; addLog("IntermecBarcodescanControl4: ScannerOn=false..."); bcr.ScannerOn = false; addLog("Enabling event driver scanning"); bcr.ThreadedRead(true); } catch (BarcodeReaderException ex) { bcr = null; System.Diagnostics.Debug.WriteLine("BarcodeReaderException in IntermecScanControl(): " + ex.Message); } catch (Exception ex) { bcr = null; System.Diagnostics.Debug.WriteLine("Exception in IntermecScanControl(): " + ex.Message); } if (bcr == null) { addLog("IntermecBarcodescanControl4: BarcodeReader init FAILED"); throw new System.IO.FileNotFoundException("Intermec.Datacollection.dll or ITCScan.DLL missing"); } #if TESTMODE //testcodes = new string[8]; testCodeCount = testcodes.Length; testCodePos = 0; #endif }