French version

The Datamatrix code



This code is part of the family of 2-dimensional codes, it can encode up to 2335 characters on a very small surface. The encoding is done in two stages : first the datas are converted to 8 bits "codeword" (High level encoding) then those are converted to small black and white squares. (Low level encoding) Moreover an error correction system is included, it allows to reconstitute badly printed, erased, fuzzy or torn off datas. In the continuation of this talk, the term "codeword" will be abbreviated to CW and Reed-Solomon code in RS. There are also micro QR codes not studied here.

The general structure.

A 2 x 2 regions code :


Low level encoding.

High level encoding.
Errors detection and correction.
Bar code making.
Since we can create the bar code pattern it remains us to draw it on the screen and to print it on a paper sheet. Two approaches are possibles : It seems there is no free fontfor datamatrix barcode on the net. I've decided consequently to draw this font and to propose it for download. Since each symbol have an even row number and an even column number, I put in each character of the font 4 modules (2 rows and 2 columns). In this manner we have 16 combinations assigned to the 16 first capital letters.
If we give a value at each dot of this 2 x 2 matrix like this :
1 2 4 8
The ASCII value of the character associated to a given matrix is the sum each dot value + 65 (65 = A = no dot, all white !)

The " datamatrix.ttf " font
This font contains the 16 character A (ASCII : 65) to P (ASCII : 80)

Copy this file in the font directory, often named : \Windows\Fonts

Encoding a datamatrix barcode

The software will evolve with 4 steps : Because of the interaction between the different compaction modes it's difficult to make a 100% optimization. Thus the software will split the string into "parts" having the type "numeric", "text" or "byte" afterwards it will change some parts for an other mode if the overload due to switch CWs is greater than the compaction gain. We'll can't make allowance for all the parameters like paddings, ...

A small program to test all that.

Here is a small program written with Visual Basic 6.
The setup file copy the program, Visual Basic
dependencies, source files and the font.

Setup file :

ZIP file without setup :

The Datamatrix$ function have about 750 lines, I thus don't reproduce it here, you can retrieve it in the "form1.frm" file which is with the above program ; with setup program, the "form1.frm" file is in the program directory, "sources" sub-directory.

The function call is like this : resultat$ = Datamatrix$(Chaine$, Dimension%, Type%, CodeErr%)
The last three parameters are optional and are passed by references; on the way back they contain the values actually used. CodeErr% values ​​when the function returns : Now simply display or print the resultat$ string with the datamatrix font for example in a word processor. Office users will be able to even integrate the Datamatrix$ function into a macro in order to automate the processing. To be able to carry out all the processing in a single function, I had to use "Gosub" instead of functions with parameters; I can already hear the programming aesthetes screaming sacrilege.


Do you like this page ?

Is it useful for you ?
Click here !