This project has moved. For the latest updates, please go here.

Encoding GS1 DataMatrix

Mar 4, 2014 at 11:46 AM
Hi all, I'm intending to adopt ZXing.net as a barcode printing library, which at a general level is going fine, I'm liking the look of the project. I do have one niggle for which I'm failing to find a solution... A GS1 DataMatrix barcode uses an FNC1 character at the start of the data to indicate "this is GS1" and then as a variable length string terminator through the data. Decoding a GS1 DataMatrix with ZXing I'm seeing 232 in the raw data and 0x1D in the result string, which is what I would expect :) However in the encoding direction I'm not sure what to use? Having 0x1D in the input string has (weirdly!) resulted in 0x1E in the decoded raw data... I'm hoping someone else reading this might have tried the same?
Coordinator
Mar 4, 2014 at 8:31 PM
Short answer: encoding of GS1 DataMatrix isn't supported at the moment.
I looked a little bit through the code. Adding support for GS1 isn't that easy. I got it running only for ASCII encoding.
If you want to try it out you can use the following patch and build your own version.
Index: Source/lib/datamatrix/encoder/ASCIIEncoder.cs
===================================================================
--- Source/lib/datamatrix/encoder/ASCIIEncoder.cs   (revision 88245)
+++ Source/lib/datamatrix/encoder/ASCIIEncoder.cs   (working copy)
@@ -75,7 +75,14 @@
             }
             else
             {
-               context.writeCodeword((char)(c + 1));
+               if (c == 29)
+               {
+                  context.writeCodeword((char)HighLevelEncoder.FNC1);
+               }
+               else
+               {
+                  context.writeCodeword((char)(c + 1));
+               }
                context.Pos++;
             }
More (and better) patches are always welcome.
Marked as answer by MadGav on 3/5/2014 at 2:26 AM
Mar 5, 2014 at 10:30 AM
Thanks mic, I think this will probably be sufficient for my immediate purposes. It would take me some time to dig in to the intricacies of DataMatrix encoding to provide a more general solution, but I have a need for encoding/decoding GS1 AI data so I will certainly be in a position to offer code and/or experience for that. Given ZXing.net is a port from Java ZXing is there any arrangement in place for routing submissions through that project?
Coordinator
Mar 5, 2014 at 6:06 PM
In the past I used the following steps:
  • first I make a patch for ZXing.Net (because I'm more familiar with C# than Java)
  • when it works for ZXing.Net I port the patch to Java
  • after that I test the patch with java
  • now I send the patch to the mailing list of zxing (java version, of course)
  • Sean (coordinator of zxing) reviews that patch, makes some changes, commit it or reject it (it depends)
  • if the patch is commited to the java version if compare that one with my original C# patch and modify ZXing.Net if neccessary
So if you can provide a patch against ZXing.Net I will do the rest.
Mar 6, 2014 at 9:07 AM
Thanks mic, while I'll check the java ZXing source to make sure I'm not duplicating a submission I don't have a java toolchain configured and no other driver to do so. I've done some tests with the patch and the barcodes produced are now scanning the same raw data as samples generated elsewhere.
Jan 26 at 3:48 PM
Is this information still current? (doesn't support GS1, but can do ASCII GS1 with that patch)
I need to generate GS1 DataMatrix, ECC200, ISO/IEC 646. With FNC1s and AIs. I assume to generate FNC1 I would (with this patch) just put \x1d in the input string. For AIs, do I just pass to the encoder literally "(01)"?
Coordinator
Feb 26 at 8:11 PM
It's still true. I didn't add the patch to the sources in the repository.
If I will add it you have to use the ASCII group separator character (decimal value 29, hex 0x1D) between two groups within the content string.