ZXing.Net.Mobile scanner does not put result to Edittext but does to Toast on first attempt

Hi,
I am using Visual Studio 2017 with the latest packages for Xamarin and ZXing.Net.Mobile 2.4.1. I implemented the standard barcode reader and it seems to work if I scan a VIN number from an image of a VIN barcode from my monitor, but if I try it on a real car, it takes about three attempts for it to display it in the Edittext where I want to show the result. I changed my code to put the result in a Toast, and it works everytime on the first attempt, but as soon as I change it to put the result into an Edittext, it seems to take multiple attempts.

Can anyone tell me what I may be doing wrong??

Here is the code I am using:

//Barcode scanner
        Button buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
        buttonScanCustomView.Click += async delegate
        {
            MobileBarcodeScanner.Initialize(Application);
            var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            scanner.AutoFocus();
            scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
            scanner.BottomText = "Wait for the barcode to automatically scan!";
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            options.UseCode39ExtendedMode = true;
            options.TryHarder = true;
            options.AutoRotate = false;                
            options.PossibleFormats = new System.Collections.Generic.List<ZXing.BarcodeFormat>()
        {
            ZXing.BarcodeFormat.CODE_39
        };
            var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = false });

            if (result != null)
            {                    
                HandleScanResult(result, VIN);
            }
            else
            {
                Android.Widget.Toast.MakeText(this, "Barcode not found. Please re-scan.", Android.Widget.ToastLength.Short).Show();
            }
        };

    void HandleScanResult(ZXing.Result result, EditText txtVIN)
    {
        string msg = "";
        if (result != null && !string.IsNullOrEmpty(result.Text))
            msg = GetCleanVIN(result.Text);
        else
            msg = "Scanning Canceled!";
        //this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Short).Show());
        this.RunOnUiThread(() => txtVIN.Text = msg);
    }

Answers

  • asusmaniasusmani Member ✭✭

    I also wanted to add: When I have it in debug mode, I can actually see that ZXing.Result actually has a scanned value, but it just doesn't push it to the Edittext control....

    Not sure what is going on!

Sign In or Register to comment.