question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Only QR-codes can be scanned. Not e.g EAN13.

See original GitHub issue

The scanner in my app can’t recognize any barcodes - except for QR codes. I have tried to configure the ZXingScannerComponent to enable EAN13 Barcodes:

//TS file
formatsEnabled: BarcodeFormat[] = [BarcodeFormat.EAN_13];

//template
<zxing-scanner
  #scanner
  [torch]="torchEnabled"
  [(device)]="currentDevice"
  (scanSuccess)="onCodeResult($event)"
  [formats]="formatsEnabled"
...

And I can confirm this configuration by logging the formats in the AfterViewInit method:

 @ViewChild('scanner') scanner: ZXingScannerComponent;

 ngAfterViewInit(): void {
    console.log(this.scanner.formats); //prints only 7, which is EAN_13
  }

However, the scanner still doesn’t recognize EAN_13 barcodes but does still recognize QR-codes even though QR codes are not enabled. I have also tried to enable almost all barcode types, but still, the scanner will only recognize QR-codes. 😕

I am using the following versions: "@zxing/ngx-scanner": "^3.0.0" and "@angular/core": "~9.1.4",

Any thoughts on what might be wrong here?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
anderswalthercommented, Aug 6, 2020

We got it working by having the zxing-scanner component as a viewchild. It is not super pretty but maybe that will also work for you…:

TEMPLATE: <zxing-scanner #scanner … …

</zxing-scanner>

COMPONENT:

enabledFormats: BarcodeFormat[] = [
  BarcodeFormat.CODE_128,
  BarcodeFormat.CODE_39,
  BarcodeFormat.EAN_13,
  BarcodeFormat.ITF,
];
@ViewChild('scanner') scanner: ZXingScannerComponent;
ngAfterViewInit(): void {
  setTimeout(() => {
    /* we need to force the component to set the enabled formats. Binding doesn't work.
       Must happen after the scanner component has been initialized
    */
    this.scanner.formats = this.enabledFormats;
  }, 3000);
}
1reaction
artursoareshsvcommented, Aug 28, 2020

The solution above worked fine, but made the performance decrease. Is it possible to set on the lib all the formats as default in order to mitigate this bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to Barcodes vs. QR Codes: Analysis and Comparison
Both QR codes and barcodes store information about an item or product in a machine-readable format that can be easily scanned with a...
Read more >
How to choose the right barcode type for your application
Will barcodes be scanned with smartphones? Sometimes? Smartphone scanners vary, but many phones can read UPC-A, EAN 13, Code 128, Code 39, QR...
Read more >
iOS 16 - Scanning barcode | Apple Developer Forums
Our app doesn't scan barcode correctly, only QRCode are recognized. For example EAN13 are not detected by the "AVCaptureMetadataOutput".
Read more >
Strange happened when Scanning EAN13 Barcode by using ...
then there is a problem to read the barcode, but these barcodes are a valid ean13 barcode, and it can be read easily...
Read more >
EAN 13 Barcode Explained
Barcode fonts are a quick and easy way to create barcodes - provided the barcode is not too complicated, a good example would...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found