コード例 #1
0
 public IntermecBarcodescanControl()
 {
     InitializeComponent();
     try
     {
         addLog("IntermecBarcodescanControl: setHWTrigger(true)...");
         //enable HW trigger, a workaround as HW trigger is sometimes disabled on BarcodeReader.Dispose()
         //if (!S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true))
         //{
         //    addLog("IntermecBarcodescanControl: 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("IntermecBarcodescanControl: mapKey()...");
         //we need full control of scan start and end
         ITCTools.KeyBoard.mapKey();
     }
     catch (Exception ex)
     {
         addLog("Exception in IntermecBarcodescanControl: setHWTrigger(true)..." + ex.Message);
     }
     try
     {
         addLog("IntermecBarcodescanControl: new BarcodeReader()...");
         bcr = new BarcodeReader(this, "default");// ();
         addLog("IntermecBarcodescanControl: BarcodeReader adding event handlers...");
         bcr.BarcodeRead         += new BarcodeReadEventHandler(bcr_BarcodeRead);
         bcr.BarcodeReadCanceled += new BarcodeReadCancelEventHandler(bcr_BarcodeReadCanceled);
         bcr.BarcodeReadError    += new BarcodeReadErrorEventHandler(bcr_BarcodeReadError);
         addLog("IntermecBarcodescanControl: starting named event watch thread...");
         waitThread = new System.Threading.Thread(waitLoop);
         waitThread.Start();
         addLog("IntermecBarcodescanControl: enabling Scanner...");
         bcr.ScannerEnable = true;
         addLog("IntermecBarcodescanControl: ScannerOn=false...");
         bcr.ScannerOn = false;
     }
     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("IntermecBarcodescanControl: BarcodeReader init FAILED");
         throw new System.IO.FileNotFoundException("Intermec.Datacollection.dll or ITCScan.DLL missing");
     }
 }
コード例 #2
0
        public new void Dispose()
        {
            addLog("IntermecScanControl Dispose()...");
            _continueWait = false; //signal thread to stop
            SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false);

            waitEvent.PulseEvent();
            System.Threading.Thread.Sleep(100);

            if (bcr != null)
            {
                addLog("IntermecScanControl Dispose(): Calling ScannerOnOff(false)...");
                scannerOnOff(false);
                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(): ending Threads...");
            if (waitThread != null)
            {
                addLog("IntermecScanControl Dispose(): ending event watch thread ...");
                waitThread.Abort();
            }
            if (readThread != null)
            {
                addLog("IntermecScanControl Dispose(): ending Barcode reading thread ...");
                readThread.Abort();
            }
            addLog("...IntermecScanControl Dispose(): end.");
            //base.Dispose(); do not use!!
        }