4 Replies Latest reply on Sep 23, 2016 1:04 PM by Mike Bedford

    Exception setting config on scanner using EMDK for Xamarin

    Mike Bedford

      Hello all, as the title suggests, I have been having an issue with setting the config for the scanner. It generates an exception (at bottom of this thread) EVERY SINGLE TIME:

       

      Therefore, I have to also believe that the config I am trying to specify is not actually getting applied.

       

      As a last resort, before I posted this issue, I downloaded the sample barcode app (BarcodeScanningTutorial) and made NO changes to the code and sure enough, the same thing is happening to the sample provided on the site. Here is the code snippet that is failing, this is inside of initScanner(); As you can see, the only change I did make, which does not affect the code, is I wrapped the problem child which is the call scanner.SetConfig(config); in a try catch block so I can trap that call and exception by itself.

       

                                  //EMDK: Configure the scanner settings

                                  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 = false;

                                  try

                                  {

                                      scanner.SetConfig(config);

                                  }

                                  catch (Exception ex)

                                  {

                                      Console.WriteLine(string.Format("Exception setting config. Exception: {0}", ex.ToString()));

                                  }

       

      Here is the error (Stack Trace) that I got from the console output from that try catch exception:

       

      09-21 16:10:23.110 I/mono-stdout(15081): com.symbol.emdk.barcode.ScannerException: Already scanning. Wait for current scanning to complete.

      09-21 16:10:23.120 I/mono-stdout(15081): at com.symbol.emdk.barcode.Scanner.setConfig(Scanner.java:303)

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

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

        at md5bb34e478d867dfa25d7f85c991bd27cf.MainActivity.n_onOpened(Native Method)

        at md5bb34e478d867dfa25d7f85c991bd27cf.MainActivity.onOpened(MainActivity.java:75)

      09-21 16:10:23.120 I/mono-stdout(15081): at md5bb34e478d867dfa25d7f85c991bd27cf.MainActivity.n_onOpened(Native Method)

      09-21 16:10:23.120 I/mono-stdout(15081): at md5bb34e478d867dfa25d7f85c991bd27cf.MainActivity.onOpened(MainActivity.java:75)

      09-21 16:10:23.120 I/mono-stdout(15081): at com.symbol.emdk.EMDKServiceConnection.notifyonConnected(EMDKServiceConnection.java:113)

      09-21 16:10:23.120 I/mono-stdout(15081): at com.symbol.emdk.EMDKServiceConnection.onServiceConnected(EMDKServiceConnection.java:93)

        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)

      09-21 16:10:23.120 I/mono-stdout(15081): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)

      09-21 16:10:23.120 I/mono-stdout(15081): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)

      09-21 16:10:23.120 I/mono-stdout(15081): at android.os.Handler.handleCallback(Handler.java:733)

      09-21 16:10:23.120 I/mono-stdout(15081): at android.os.Handler.dispatchMessage(Handler.java:95)

      09-21 16:10:23.120 I/mono-stdout(15081): at android.os.Looper.loop(Looper.java:136)

      09-21 16:10:23.120 I/mono-stdout(15081): 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)

      09-21 16:10:23.120 I/mono-stdout(15081): at java.lang.reflect.Method.invokeNative(Native Method)

      09-21 16:10:23.120 I/mono-stdout(15081): at java.lang.reflect.Method.invoke(Method.java:515)

      09-21 16:10:23.120 I/mono-stdout(15081): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)

      09-21 16:10:23.120 I/mono-stdout(15081): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

      09-21 16:10:23.120 I/mono-stdout(15081): at dalvik.system.NativeStart.main(Native Method)

       

      Please advise how to fix this. I am certain that it is happening to everybody since I used the sample program provided by Zebra which also is written per the documentation as well.

       

      Thanks!

       

      Mike

        • Re: Exception setting config on scanner using EMDK for Xamarin
          Kanagal Raj Ramaswamy

          The scanner configuration can be set only when the scanner is IDLE and no reads pending. Otherwise the calling the scannet.setConfig will result in failure with error as “Scanning in progress”.

          As per the code, you are  trying to call the scanner.setConfig without waiting for scanner go to IDLE state and no pending reads. This results failure to set configuration. 

           

          You can do something like below:

          @Override

          public void onStatus(StatusData statusData) {

           

           

            ScannerStates state = statusData.getState();

            switch (state) {

            case IDLE:

           

           

            if (!scanner.isReadPending()) {

           

           

            //Set the configuration required if user requested

            if (isUserRequestedToSetConfig) {

            setConfig(); //Set the scanner configuration in setConfig.

            }

           

           

            //Submit scanner read to start scanning if needed

           

           

            }

            else {

            //Previous read is still pending.. please wait for next IDLE state

            }

            break;

            case WAITING:

            // "Scanner is waiting for trigger press...";

           

           

            break;

            case SCANNING:

            // "Scanning...";

           

           

            break;

            case DISABLED:

            //disabled.";

           

           

            break;

            case ERROR:

            // "An error has occurred.";

           

           

            break;

            default:

            break;

            }

          }

          1 of 1 people found this helpful
            • Re: Exception setting config on scanner using EMDK for Xamarin
              Mike Bedford

              Thank you for the response.

               

              I understand what you are saying and it makes sense that the scanner would not apply a config if it is in the middle of a read. HOWEVER, I think it is important to note, as I also pointed out in my first post, that I am doing the exact same thing as all of the documentation AND the sample barcode scanning application published by Zebra, which also has the exception by the way.

               

              Furthermore, this happens (again as does the barcode scanning demo application) during the initialization of the scanner. I have not asked it to do a read. So, I don't know why the scanner would be reading.

               

              That said, I can see how maybe it needs to be idle before setting the config, I will try that based on your suggestions above and if that is the case, I believe the Zebra documentation and sample barcode app is also flawed and should be updated.

               

              I will report back my findings. In the meantime, I encourage you or anybody to simply run the demo barcode application provided by Zebra. You don't need to make any changes to it. Observe what happens when it tries to set the config and you will see this is an issue.

               

              Thanks!

               

              Mike

              • Re: Exception setting config on scanner using EMDK for Xamarin
                Mike Bedford

                Okay, I tried your suggestion the sample barcode demo application and this resolves the issue. I saw your last response as well and am glad to hear it was already sent to the team because there is apparently an issue with the docs and sample as your suggestion has resolved it. Thank you very much for the help and of course, I will always help report and improve when I can. Along those lines, I also have another thread posted with another big issue (that also happened again right now while testing your recommendations on the demo app). Hopefully we can get going on that thread as well.

                 

                As for this issue, here is exactly what I did, based on your recommendations:

                 

                In the demo app, in the InitScanner method, take out these lines:

                                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 = false;

                 

                 

                                scanner.SetConfig(config);

                 

                And wrap them in a new method call, you can name it what you want but this is what mine now looks like:

                 

                        private void setScannerConfig()

                        {

                            try

                            {

                                //EMDK: Configure the scanner settings

                                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 = false;

                 

                 

                                scanner.SetConfig(config);

                                Console.WriteLine(string.Format("Config set properly."));

                            }

                            catch (Exception ex)

                            {

                                Console.WriteLine(string.Format("Exception setting config. Exception: {0}", ex.ToString()));

                            }

                        }

                 

                Now, find the scanner_Status method. Look for if (state == StatusData.ScannerStates.Idle). You are going to add your method call to set the config in there, so we ensure the scanner is idle and not doing a read before applying the config. There should also be a flag of some sort (I used a bool) so that you only set it one time on startup, or anytime after by setting the flag. So, it should look like this, where scanConfigChangeNeedsSet is your flag.

                 

                            if (state == StatusData.ScannerStates.Idle)

                            {

                                statusStr = "Scanner is idle and ready to submit read.";

                                try

                                {

                                    if (scanner.IsEnabled && !scanner.IsReadPending)

                                    {

                                        if (scanConfigChangeNeedsSet)

                                        {

                                            setScannerConfig();

                                            scanConfigChangeNeedsSet = false;

                                        }

                                        scanner.Read();

                                    }

                                }

                                catch (ScannerException e1)

                                {

                                    statusStr = e1.Message;

                                }

                            }

                 

                Hope this helps others until the docs are updated. Thanks again for the support Kanagal!

                 

                Mike