Search code examples
c#.netxamarinbarcodegs1-datamatrix

GS1 barcode parsing - It seems that there is no separating character


I have a program for parsing GS1 Barcodes (with Zebra scanner), which worked just fine, atleast I thought it was OK... Until I came across one box with 2 GS1 barcodes.. one "linear" and one data matrix (UDI). For linear, it worked just fine, I successfully got out the GTIN and Serial. But datamatrix is different. For some reason, its content is a bit longer than linear code, it has some production date and something else at the end.

This is the Linear code: (01)00380652555852(17)260221(21)25146965079(30)1 This is data matrix: (01)00380652555852(17)260221(21)2514696507911210222240SA60AT225

I have problems with parsing out the Serial number - 25146965079. Serial number in GS1 has a length of 1-20 characters. This one has 11, but How can I make it stop after the 9 characters? How can I know that the serial ends there? I tried transforming each character to UDI, but it seems that there is no special separating character or anything.. so I honestly donjt know what to do. Does anyone have any idea?

This the code, if anyone wanna try anything https://prnt.sc/1x2sw8l

Those codes/products came right from the manufacturer, so there shouldnt be anything wrong with the code, I guess...


Solution

  • If you verify the barcode with a scanner that is designed to interpret a GS1 structure, you will see that the generated barcode is in fact incorrect.

    You are missing a GS after the serial number, these codes MUST end a variable-length field if it's not the last one. This is specified in GS1 general specifications section 7.8.5.2

    Without this separator you can't know where the serial ends - or, a machine interpreting the code can't know.

    Tell the manufacturer that they need to study the GS1 specs.

    Edit: the "correct" version would be:

    (01)00380652555852(17)260221(21)25146965079<GS>(11)210222(240)SA60AT225
    

    The parentheses and group separator <GS> are not included literally in the code.

    Since you have two variable-length identifiers (21) and (240) you need a GS no matter what you do. Only alternative would be to have some padding for serial number, then you could do without separator.