force C40 encoding mode in data matrix
Hello, I'd like to create a datamatrix qr code with C40 encoding. There's a french institutional website (https://interop.esante.gouv.fr/datamatrixins-1.0-SNAPSHOT/) which allow me to verify my qr Code. Here is my code:
var writer = new BarcodeWriter
{
Format = ZXing.BarcodeFormat.DATA_MATRIX,
Options = new DatamatrixEncodingOptions
{
DefaultEncodation = (int?)Encodation.C40,
Height = 175,
Width = 175
},
Encoder = new DataMatrixWriter()
};
writer.Write("IS010000000000000000000000S1123456789876543S21.2.250.1.213.1.4.8"+(char)29+"S3MATHIEU MICHEL"+(char)29+"S4MELON"+(char)29+"S5MS610-02-1966")
.Save(@"C:\Barcode.png");
When I try to validate generated qr code, it fails and says that C40 encoding is incorrect. When I look at C40Encoder.cs, it seems that the problem is located here (encode method):
if ((count % 3) == 0)
{
int newMode = HighLevelEncoder.lookAheadTest(context.Message, context.Pos, EncodingMode);
if (newMode != EncodingMode)
{
// Return to ASCII encodation, which will actually handle latch to new mode
context.signalEncoderChange(Encodation.C40);
break;
}
}
If I remove that portion of code, or if I remove break statement, generated qr code is validated. Is that portion of code really necessary (or at least break statement)?
Yes, these lines are necessary to switch between different encoding modes. A round-trip test (encoding and decoding) shows that the encoded barcode with the current implementation can be successfully decoded. The implementation is correct at this point. I think you need something different. There is a requirement of the French government that the DataMatrix code should be using the C40 encoding only. You need an encoding switch to force the use of C40 and prevent switching between different modes. There is already an implementation of that switch in the java version of zxing: https://github.com/zxing/zxing/pull/1495 I have to port that enhancement to ZXing.Net. Meanwhile, you can build your own version of ZXing.Net and remove the two lines of code.
Hello guys, i have the exact same requirements (from the french government too).
Is this issue still relevant ? (i think so otherwise this issue will no longer be open).
If not, there is a easier workaround than build an update version of this library ?
thanks !
It's relevant. I didn't find the time to port the changes in the java version to .net.
Hello, This problem is resolved in master and by enabling FORCE_C40, see this commit.
A release is planned with any changes?
I will build a new release as soon as possible. But there is a lot of work which has to be done before.
Looking forward to that release, Thanks!
Please try version 0.16.9, available via nuget