Fix scanner barcode per i plu

This commit is contained in:
2026-07-22 14:50:09 +02:00
parent 74b671586f
commit 5ec7468b1c
4 changed files with 133 additions and 8 deletions
@@ -1,6 +1,7 @@
using Android.OS;
using Com.Honeywell.Aidc;
using SteUp.Shared.Core.BarcodeReader.Dto;
using SteUp.Shared.Core.BarcodeReader.Enum;
namespace SteUp.Maui.Core.System;
@@ -87,13 +88,40 @@ public partial class HoneywellScannerService
var dto = new BarcodeScanDto
{
StringValue = e.BarcodeData,
Type = e.CodeId,
Type = MapCodeId(e.CodeId),
Name = e.CodeId
};
OnScanSuccessful?.Invoke(dto);
}
// Honeywell restituisce il simbologia tramite un Code ID di un solo carattere (getCodeId),
// non un enum. Lo mappiamo su BarcodeType. Ai fini dell'app conta distinguere
// EAN13 / CODE128 / EAN128 (vedi BarcodeManager.IsEanPeso); il resto è best-effort.
private static BarcodeType MapCodeId(string? codeId) => codeId switch
{
"a" => BarcodeType.CODABAR,
"b" => BarcodeType.CODE39,
"c" => BarcodeType.UPCA,
"d" => BarcodeType.EAN13,
"D" => BarcodeType.EAN8,
"e" => BarcodeType.INTERLEAVED_2OF5,
"E" => BarcodeType.UPCE,
"g" => BarcodeType.MSI,
"h" => BarcodeType.CODE11,
"i" => BarcodeType.CODE93,
"j" => BarcodeType.CODE128, // Code 128 e GS1-128 condividono il Code ID 'j'
"I" => BarcodeType.EAN128, // alcune generazioni riportano GS1-128 come 'I'
"r" => BarcodeType.PDF417,
"R" => BarcodeType.MICRO_PDF417,
"s" => BarcodeType.QR,
"w" => BarcodeType.DATAMATRIX,
"x" => BarcodeType.MAXICODE,
"y" => BarcodeType.GS1_DATABAR_14,
"z" => BarcodeType.AZTEC,
_ => BarcodeType.NIL
};
private static Dictionary<string, Java.Lang.Object> GetDefaultProperties() => new()
{
{ BarcodeReader.PropertyEan8Enabled, true },
@@ -1,5 +1,8 @@
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Maui.Devices.Sensors;
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.BarcodeReader.Dto;
using SteUp.Shared.Core.BarcodeReader.Enum;
using SteUp.Shared.Core.Messages.Scanner;
namespace SteUp.Shared.Core.BarcodeReader;
@@ -19,14 +22,31 @@ public class BarcodeManager(
scanner.Register(
onScanSuccessful: dto =>
{
messenger.Send(new NewScannerMessage(dto.StringValue));
var stringValue = dto.StringValue;
if (IsEanPeso(dto))
stringValue = DecodeEanPeso(stringValue);
messenger.Send(new NewScannerMessage(stringValue));
},
onScanFailed: ex =>
{
messenger.Send(new ErrorScannerMessage(ex.Message));
}
onScanFailed: ex => { messenger.Send(new ErrorScannerMessage(ex.Message)); }
);
scanner.Init(() => { scanner.ChangeSettings([("TRIGGER_SCAN_MODE", "ONE_SHOT")]); });
}
private static bool IsEanPeso(BarcodeScanDto barcodeScan) =>
(IsEtichetta128(barcodeScan) || IsEan13(barcodeScan)) && barcodeScan.StringValue is { Length: 13 } &&
barcodeScan.StringValue.StartsWith('2');
private static bool IsEtichetta128(BarcodeScanDto barcodeScan) =>
barcodeScan.Type is BarcodeType.CODE128 or BarcodeType.EAN128;
private static bool IsEan13(BarcodeScanDto barcodeScan) =>
barcodeScan.Type == BarcodeType.EAN13;
private static string DecodeEanPeso(string? barcode)
{
return barcode is not { Length: 13 } ? throw new Exception("Errore durante il parse del barcode (" + barcode + ")") : barcode.Substring(1, 6);
}
}
@@ -1,8 +1,10 @@
namespace SteUp.Shared.Core.BarcodeReader.Dto;
using SteUp.Shared.Core.BarcodeReader.Enum;
namespace SteUp.Shared.Core.BarcodeReader.Dto;
public class BarcodeScanDto
{
public string? StringValue { get; set; }
public string? Type { get; set; }
public BarcodeType? Type { get; set; }
public string? Name { get; set; }
}
@@ -0,0 +1,75 @@
namespace SteUp.Shared.Core.BarcodeReader.Enum;
public enum BarcodeType
{
NIL = 0,
AIRLINE_2OF5_13_DIGIT = 1,
AIRLINE_2OF5_15_DIGIT = 2,
AZTEC = 3,
AUSTRALIAN_POSTAL = 4,
BOOKLAND_EAN = 5,
BPO = 6,
CANPOST = 7,
CHINAPOST = 8,
CHINESE_2OF5 = 9,
CODABAR = 10,
CODABLOCK = 11,
CODE11 = 12,
CODE128 = 13,
CODE16K = 14,
CODE32 = 15,
CODE39 = 16,
CODE49 = 17,
CODE93 = 18,
COMPOSITE = 19,
COUPON_CODE = 20,
DATAMATRIX = 21,
DISCRETE_2OF5 = 22,
DUTCH_POSTAL = 23,
EAN128 = 24,
EAN13 = 25,
EAN8 = 26,
GS1_DATABAR_14 = 27,
GS1_DATABAR_EXPANDED = 28,
GS1_DATABAR_LIMITED = 29,
HONGKONG_2OF5 = 30,
IATA_2OF5 = 31,
IDTAG = 32,
INTERLEAVED_2OF5 = 33,
ISBT128 = 34,
JAPANESE_POSTAL = 35,
KOREAN_POSTAL = 36,
MATRIX_2OF5 = 37,
MAXICODE = 38,
MESA = 39,
MICRO_PDF417 = 40,
MICRO_QR = 41,
MSI = 42,
NEC_2OF5 = 43,
OCR = 44,
PDF417 = 45,
PLESSEY = 46,
POSICODE = 47,
POST_US4 = 48,
QR = 49,
STRAIGHT_2OF5 = 50,
STANDARD_2OF5 = 51,
TELEPEN = 52,
TLCODE39 = 53,
TRIOPTIC = 54,
UK_POSTAL = 55,
UPCA = 56,
UPCE = 57,
UPCE1 = 58,
US_PLANET = 59,
US_POSTNET = 60,
USPS_4CB = 61,
RSS = 62,
LABEL = 63,
HANXIN = 64,
GRIDMATRIX = 65,
INFO_MAIL = 66,
INTELLIGENT_MAIL = 67,
SWEDENPOST = 68,
LAST = 69
}