Esempio n. 1
0
 /// <summary>
 /// Called when the LineaPro scans a barcode.
 /// </summary>
 /// <param name="barcode">The string barcode data.</param>
 /// <param name="aType">The barcode type.</param>
 public override void BarcodeData(string barcode, int aType)
 {
     if (BarcodeScanned != null)
     {
         BarcodeScanned.Invoke(this, new BarcodeScannedEventArgs(barcode, (Barcodes)aType));
     }
 }
Esempio n. 2
0
 private void BarcodeEntryTextbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         e.Handled          = true;
         e.SuppressKeyPress = true;
         BarcodeScanned?.Invoke(this, new BarcodeScannedEventArgs(this.Text));
         this.Text = "";
     }
 }
Esempio n. 3
0
        private void DecodedData(object sender, CaptureHelper.DecodedDataArgs e)
        {
            //Remove delay issues, run this first
            SendResponse(Responses.None);

            //Decouple DecodedData
            _buffer = e.DecodedData.DataToUTF8String;

            BarcodeScanned?.Invoke(this, e);
        }
 public ScanPageViewModel()
 {
     barcodeText          = string.Empty;
     IsScanning           = true;
     ScanCompletedCommand = new Command((barcodeText) =>
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             IsScanning = false;
             Application.Current.MainPage.Navigation.PopModalAsync();
             BarcodeText = barcodeText?.ToString();
             BarcodeScanned?.Invoke(this, barcodeText?.ToString());
         });
     });
     CompletedCommand = new Command(() =>
     {
         if (!string.IsNullOrEmpty(BarcodeText))
         {
             IsScanning = false;
             Application.Current.MainPage.Navigation.PopModalAsync();
             BarcodeScanned?.Invoke(this, barcodeText?.ToString());
         }
     });
     FlashCommand = new Command(() =>
     {
         if (flashOn)
         {
             FlashImageSource = ImageSource.FromFile("ic_flash_off.png");
         }
         else
         {
             FlashImageSource = ImageSource.FromFile("ic_flash_on.png");
         }
         FlashOn = !FlashOn;
     });
     CloseCommand = new Command(() =>
     {
         IsScanning = false;
         Application.Current.MainPage.Navigation.PopModalAsync();
     });
 }
Esempio n. 5
0
        private async void _readTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _readTimer.Stop();

            try
            {
                string data = await ReadAsync();

                var datas = data.Split(new char[] { STX, ETX }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var d in datas)
                {
                    if (d.Contains(HEARTBEAT_RESPONSE))
                    {
                        //Heartbeat
                    }
                    else if (d.Contains(NOREAD_RESPONSE))
                    {
                        _logger.Verbose($"Barcode could not scan. Ip: {IpAddress}");
                        BarcodeCouldNotScanned?.Invoke(this, null);
                    }
                    else
                    {
                        string barcode = d.Replace(NOREAD_RESPONSE, "")
                                         .Replace("!", "").Replace(HEARTBEAT_RESPONSE, "")
                                         .Replace((STX).ToString(), "")
                                         .Replace((ETX).ToString(), "");
                        _logger.Verbose($"Barcode scanned. Barcode: {barcode}, Ip: {IpAddress}");
                        BarcodeScanned?.Invoke(this, new BarcodeEventArgs(barcode, Name));
                    }
                }

                _readTimer.Start();
            }
            catch
            {
                Disconnect();
            }
        }
        public async Task StartScan(bool useFrontCamera = false, MobileBarcodeScanningOptions options = null)
        {
            try
            {
                var scanner = new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                };
                scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_128,
                        BarcodeFormat.QR_CODE
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = useFrontCamera,
                    TryHarder        = true,
                    DisableAutofocus = false
                }, (result) =>
                {
                    BarcodeScanned?.Invoke(this, result.Text);
                    MessagingCenter.Send(this, Constants.BARCODE_SCANNED, result.Text);
                });

                Device.StartTimer(TimeSpan.FromSeconds(3), () =>
                {
                    scanner.AutoFocus();
                    return(true);
                });
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }
        }
 private void OnBarcodeScanned(BarcodeEventArgs args)
 {
     BarcodeScanned?.Invoke(this, args);
 }
Esempio n. 8
0
        private async Task InitializeMediaCaptureAsync()
        {
            // Do not use ConfigureAwait(false), subsequent calls must come from Dispatcher thread
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var device = _panel.HasValue
                ? devices.FirstOrDefault(d => d.EnclosureLocation?.Panel == _panel)
                : devices.FirstOrDefault();

            // TODO: remove this hack, it defaults the camera to any camera if it cannot find one for a specific panel
            device = device ?? devices.FirstOrDefault();

            if (device == null)
            {
                throw new InvalidOperationException("Could not find camera device.");
            }

            _rotationHelper = new CameraRotationHelper(device.EnclosureLocation);
            _rotationHelper.OrientationChanged += OnOrientationChanged;

            // Initialize for panel
            var settings = new MediaCaptureInitializationSettings
            {
                VideoDeviceId = device.Id,
            };

            // Do not use ConfigureAwait(false), subsequent calls must come from Dispatcher thread
            await MediaCapture.InitializeAsync(settings);

            // Set flash modes
            MediaCapture.SetFlashMode(FlashMode);
            MediaCapture.SetTorchMode(TorchMode);

            // Set to capture element
            CaptureElement.Source = MediaCapture;
            // Mirror for front facing camera
            CaptureElement.FlowDirection = _panel == Windows.Devices.Enumeration.Panel.Front
                ? FlowDirection.RightToLeft
                : FlowDirection.LeftToRight;

            // Start preview
            // Do not `ConfigureAwait(false), orientation must be set on Dispatcher thread
            await MediaCapture.StartPreviewAsync();

            // Set preview rotation
            await UpdatePreviewOrientationAsync().ConfigureAwait(false);

            // Start barcode scanning
            if (BarcodeScanningEnabled)
            {
                _barcodeScanningSubscription.Disposable =
                    GetBarcodeScanningObservable().Subscribe(result =>
                {
                    BarcodeScanned?.Invoke(result);
                });
            }

            IsInitialized = true;

            lock (_initializationGate)
            {
                _initializationTask = null;
            }
        }
Esempio n. 9
0
 private void RaiseRemoveProduct(string barCode)
 {
     BarcodeScanned?.Invoke(this, new BarcodeScannedEventArgs(barCode, false));
 }
 private async void HandleScabResult(Result result)
 {
     Device.BeginInvokeOnMainThread(async() => await this.navigationService.NavigateAsync($"/{ScanRoutes.Navigation}/{ScanRoutes.Main}"));
     BarcodeScanned?.Invoke(this.scanPage, result.Text);
 }