We need to parse the GS1 datamatrix barcode which will be provided by other party. We know they are going to use GTIN(01), lot number(10), Expiration date(17), serial number (21). The problems is that barcode reader output a string, the format is like this 01076123456789001710050310AC3453G321455777. Since there is not separator and both serial number and lot number are variable length according to GS1 standard, we have trouble to identify segments. My understanding is that it seems like the best way to parse is to embed the parser in the scanning device, not from the application. But we didn't plan an embed software yet. How can I implement the parser? Any suggestions?
There should be a FNC1 character at the end of a variable-length field; so that FNC1 will appear between the G3
and the 21
.
FNC1 is invisible to humans but can be detected by scanners and should be reproduced in the string reported by the scanner as the GS character (ASCII value 29). Simply send the string directly to a text file and examine the text with a hex reader. The GS
character representing the barcode's FNC1 separator should be obvious.
If you can, it might be an idea to swap the sequence of the 21
field and the 10
field since you appear to be using a pure-numeric for 21
. This would make the barcode produced a little shorter.
cmd
and create a file which will have –
Traweek One way to deal with this is to program the scanner to replace FNC1 with space or another plain text character before sending it to your application. The scanner manufacturer usually provides a tool to produce programming bar codes that can do simple substitutions in the scanner. Then you can parse the data without having to handle special characters.
~
. –
Abey the bestway is you do your code. put in your form an editbox, and adoquery, do the select to your table.
with this code it will parse the gtin, serial, expdate and batch.
for example:
01001917780231522116080557521871457989211726083110Y008179 01036647980113261726043010X3D285V21136R4EG4NMKCDN7144261780 010019177800529521137374405177714565882817260630103037011 01036647980113261726043010X3D285V21136R4EG4NM38DA7144261780 01036647980113261726043010X3D285V21136R4EG4MVV4G67144261780 01036647980113261726043010X3D285V21136R4EG4MW26VM7144261780 01036647980113261726043010X3D285V21136R4EG5CC5EV07144261780 01036647980113261726043010X3D285V21136R4EG55T1GC87144261780 01001917780231522112897347314271457989211726083110Y008179 01036647980540711725073110W3H254V21136C4CVRTEDPDM7145458484 01001917780231522118590092518371457989211726083110Y008179
use this code:
Edit1.Text:=ADOQuery1.FieldByName('QRCode').AsString;
GTIN:='';
EXPDATE:='';
BATCH:='';
Serial:='';
while (GTIN='') or (BATCH='') or (EXPDATE='') or (Serial='') do
begin
if GTIN='' then
begin
GTIN := copy(Edit1.Text,3,14);
Edit1.Text:=StringReplace(Edit1.text,'01'+GTIN,'',[rfReplaceAll]);
end;
if copy(Edit1.Text,0,3)='714' then
Edit1.Text:=copy(Edit1.Text,12,100);
if (BATCH='') and (copy(Edit1.Text,0,2)='10') then
begin
if Pos(Delimiter, Edit1.Text)>0 then
BATCH:=copy(Edit1.Text,3,Pos(Delimiter, Edit1.Text)-3)
else
BATCH:=copy(Edit1.Text,3,30);
Edit1.Text:=StringReplace(Edit1.text,'10'+BATCH+Delimiter,'',[rfReplaceAll]);
Edit1.Text:=StringReplace(Edit1.text,'10'+BATCH,'',[rfReplaceAll]);
end;
if (copy(Edit1.Text,0,2)='17') and (EXPDATE='') then
begin
EXPDATE := copy(Edit1.Text,3,6);
Edit1.Text:=StringReplace(Edit1.text,'17'+EXPDATE+Delimiter,'',[rfReplaceAll]);
Edit1.Text:=StringReplace(Edit1.text,'17'+EXPDATE,'',[rfReplaceAll]);
end;
if (copy(Edit1.Text,0,2)='21') and (Serial='') then
BEGIN
if Pos(Delimiter, Edit1.Text)>0 then
Serial := copy(Edit1.Text,3,Pos(Delimiter, Edit1.Text)-3)
else
Serial := copy(Edit1.Text,3,100);
Edit1.Text:=StringReplace(Edit1.text,'21'+Serial+Delimiter,'',[rfReplaceAll]);
Edit1.Text:=StringReplace(Edit1.text,'21'+Serial,'',[rfReplaceAll]);
END;
end;
© 2022 - 2025 — McMap. All rights reserved.