EMDK for Xamarin

Hi I am implementing a barcode scanning application in Xamarin for Android 8.1 and have implemented the code at https://techdocs.zebra.com/emdk-for-xamarin/6-0/tutorial/barcodeapitutor... with Symbol.XamarinEMDK (Zebra) NuGet package v6.0.0.51

The app has a menu which allows you to open various Activities which then allows barcode scanning for different types of products.When the activity opens it runs the code above to initialize the scanner and it mostly appears to work.

However have been having issues with the scanner sometimes not Initializing correctly. The problem appears to be in the InitScanner() method in the example.

//Attahch the Data Event handler to get the data callbacks.
scanner.Data += scanner_Data;

//Attach Scanner Status Event to get the status callbacks.
scanner.Status += scanner_Status;


//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;

All works well until you get to the last line where it sets the config. This line works sometimes, but very regularly it returns the following error

Already scanning. Wait for current scanning to complete.

at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <064cde681fba4dd08eaf8b1bdbbfb8c8>:0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <88e07771519044019747330a4a2ef026>:0
at Symbol.XamarinEMDK.Barcode.Scanner.SetConfig (Symbol.XamarinEMDK.Barcode.ScannerConfig p0) [0x0005b] in <ed07d706a8e748c482573c724434c6e6>:0
at Scanner.ScanActivity.InitScanner () [0x00106] in C:\Users\Andy\Source\Repos\AusPork\Ops 2\Scanner\ScanActivity.cs:86
--- 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 crc64cd00eaebe95119e

However if you check the Status event it is not scanning, and certainly no button has been pressed on the scanner to do a scan.

Given the code I have matches the example on the link except that I am opening an Activity to get to this code, Is this a known bug or is there something else that needs to be added to properly SetConfig or reset the Scanning status?

The end result is that after this error sometimes the scanner works perfectly, and others it will scan but is unable to send data to the data event handler and so no scanning appears to happen.

Darryn Campbell
Hi, that sample code looks a

Hi, that sample code looks a bit old to me.  The decoders should only be set when the scanner is in the IDLE state - if you take a look at the Android sample this was modified a little while back to change when setDecoders() was called: https://github.com/Zebra/samples-emdkforandroid-7_3/blob/master/BarcodeSample1/app/src/main/java/com/symbol/barcodesample1/MainActivity.java#L195.  There is an official Xamarin sample but it looks like the Xamarin sample won't have this issue since the UI controls are disabled when the scanner is enabled (https://github.com/Zebra/samples-emdkforxamarin-2_7/blob/master/BarcodeS...)

The recommended approach is to use DataWedge rather than the EMDK and I have a couple of tutorials on my website with more details on that: http://www.darryncampbell.co.uk/2018/01/16/tutorial-scan-with-datawedge-intent-output-on-zebra-devices-with-xamarin/http://www.darryncampbell.co.uk/2018/04/10/tutorial-the-datawedge-intent-api-with-xamarin/.  DataWedge would actually be a substantially easier approach for your application which has multiple activities that all need to control the scanner.

Vote up!
Vote down!

Points: 0

You voted ‘up’

Log in to post comments