3 Replies Latest reply on Sep 1, 2016 8:38 AM by Billie Hecox

    Why am I getting an exception during the initialization of the scanner on MC67

    Mike Bedford

      Hello all, using the EMDK for Xamarin on an MC67 running Android/KitKat. I have followed the documents to integrate the EMDK and initialize the scanner. Here is the critical code snippet:

       

              void EMDKManager.IEMDKListener.OnOpened(EMDKManager emdkManager)

              {

                  this.emdkManager = emdkManager;

       

       

                  InitScanner();

              }

       

       

              public void InitScanner()

              {

                  if (emdkManager != null)

                  {

                      if (barcodeManager == null)

                      {

                          try

                          {

       

       

                              barcodeManager = (BarcodeManager)emdkManager.GetInstance(EMDKManager.FEATURE_TYPE.Barcode);

                              scanner = barcodeManager.GetDevice(BarcodeManager.DeviceIdentifier.Default);

       

       

                              scanner.Data += Scanner_Data;

                              scanner.Status += Scanner_Status;

       

       

                              scanner.Enable();

       

       

                              ScannerConfig config = scanner.GetConfig();

                              config.SkipOnUnsupported = ScannerConfig.SkipOnUnSupported.None;

                              config.ScanParams.DecodeLEDFeedback = true;

                              config.ReaderParams.ReaderSpecific.ImagerSpecific.PickList = ScannerConfig.PickList.Enabled;

                              config.DecoderParams.Code39.Enabled = true;

                              config.DecoderParams.Code128.Enabled = true;

                              config.DecoderParams.MaxiCode.Enabled = true;

                              config.DecoderParams.MicroPDF.Enabled = true;

                              config.DecoderParams.Pdf417.Enabled = true;

       

       

                              scanner.SetConfig(config);

       

       

                          }

                          catch (ScannerException e)

                          {

                              PacTracLogger.LogError(context, string.Format("Motorola Scanner exception in InitScanner: {0}", e.ToString()));

                          }

                          catch (Exception ex)

                          {

                              PacTracLogger.LogError(context, string.Format("Motorola Scanner general exception in InitScanner: {0}", ex.ToString()));

                          }

                      }

                  }

              }

       

      I have put a breakpoint on the InitScanner method and have confirmed that it only hits the breakpoint one time. However, I am getting this exception.

       

      Fri Aug/19/2016 18:05 PacTracAndroidLogger [Error] Motorola Scanner exception in InitScanner: Symbol.XamarinEMDK.Barcode.ScannerException: Already scanning. Wait for current scanning to complete.

        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143

        at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00084] in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11643

        at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:264

        at Symbol.XamarinEMDK.Barcode.Scanner.SetConfig (Symbol.XamarinEMDK.Barcode.ScannerConfig p0) [0x0005b] in <filename unknown>:0

        at PocketPacTracAndroid.Scanners.MotorolaScanner.InitScanner () [0x0012b] in C:\Projects\PocketPacTracAndroid\Scanners\MotorolaScanner.cs:141

        --- End of managed Symbol.XamarinEMDK.Barcode.ScannerException stack trace ---

      com.symbol.emdk.barcode.ScannerException: Already scanning. Wait for current scanning to complete.

        at com.symbol.emdk.barcode.Scanner.setConfig(Scanner.java:303)

        at md573277cf34926dd87b474d01bca741cd8.MotorolaScanner.n_onOpened(Native Method)

        at md573277cf34926dd87b474d01bca741cd8.MotorolaScanner.onOpened(MotorolaScanner.java:46)

        at com.symbol.emdk.EMDKServiceConnection.notifyonConnected(EMDKServiceConnection.java:113)

        at com.symbol.emdk.EMDKServiceConnection.onServiceConnected(EMDKServiceConnection.java:93)

        at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)

        at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)

        at android.os.Handler.handleCallback(Handler.java:733)

        at android.os.Handler.dispatchMessage(Handler.java:95)

        at android.os.Looper.loop(Looper.java:136)

        at android.app.ActivityThread.main(ActivityThread.java:5002)

        at java.lang.reflect.Method.invokeNative(Native Method)

        at java.lang.reflect.Method.invoke(Method.java:515)

        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

        at dalvik.system.NativeStart.main(Native Method)

       

      Because I am handling exceptions in a try/catch block, it pretty much moves on and everything works fine. That said, I would like to understand this exception and stop it. Seems to only happen when the app starts, so one time per app lifecycle.

       

      So, why is this happening and how do I fix it? One question I have (that may be causing it), notice how the exception says the error is on line 141? Well, that line is in the InitScanner method but it is: scanner.SetConfig(config); Does calling SetConfig also Init the scanner? So, I am in the InitScanner method but that line calls InitScanner again? If that is not it, other thoughts?

       

      Also, see screenshot, I have no other references to this method. It seems to be called by:

       

              void EMDKManager.IEMDKListener.OnOpened(EMDKManager emdkManager)

              {

                  this.emdkManager = emdkManager;

       

       

                  InitScanner();

              }

       

      Which as you can see in the screen shot has 0 references. InitScanner only has 1 reference which is the method above. So, nothing else can be doing this.

       

      Thanks!

       

      MikeInitScannerExceptions.PNG