igorocampos / ESCPOS

A ESC/POS Printer Commands Helper
56 stars 22 forks source link

Printing Bar Code128 #9

Closed ghost closed 4 years ago

ghost commented 4 years ago

As stated in the manual:

When using the CODE 128 in this printer, take the following points into account for data transmission: The top of the bar code data string must be code set selection character (any of CODE A, CODE B or CODE C) which selects the first code set.

Your settings for CODE 128 would then be: 0x1D, 0x6B, 0x49, (byte)(barCode.Length + 2), 0x7B, 0x41

I like both ESCPOS and ESCPOS_NET.

igorocampos commented 4 years ago

Hi @bookhanming,

You are right! I completely missed that instruction because it is in a different page of the manual. Here it follows the instructions quoted by you: image

I guess when I tested it, I took by granted because a barcode was print, however I never read it to really know if its data was correct. I guess it is missing a couple of bytes then.

Furthermore, in the next page of the manual it states: image

Do you know why it is necessary to keep those spaces? Is it only for CODE128 too?

Thank for your help :)

ghost commented 4 years ago

Thanks for your reply. I love your ESCPOS.

From my finding with real thermal receipt printer (CP-Q1T), without the code set selection character, the barcode CODE128 would not be printed at all. Meanwhile, with the proper code set selection character (CODE A / CODE B / CODE C), the length of code set selection character itself (2 bytes) must be count as well as the barcode length.

For example: (let say the barcode is "1234567890")

This will print readable barcode "12345678" (the first eight digits) only: 0x1D, 0x6B, 0x49, (byte)(barCode.Length + 0), 0x7B, 0x41 };

This will not print at all using my thermal receipt printer. 0x1D, 0x6B, 0x49, (byte)(barCode.Length + 0) };

You can further refer to CODE A, CODE B, and CODE C table. As for myself, I will stick it to CODE A (alphanumerical, BUT the letters in uppercase only)

As for the spaces, I am sorry, I, too, do not understand it very well. So far I am able to print barcode CODE128 over 15 alphanumeric characters and read it with handheld scanner correctly.

It is an honor to receive a constructive reply from you.

igorocampos commented 4 years ago

Thank you for helping this project.

My tests were done in an EPSON TM-T20 printer, I find that your way of sending the bytes is the correct way and probably the most compatible with other printers. As for my tests, when I scanned the code printed by 0x1D, 0x6B, 0x49, (byte)(barCode.Length + 0) } it skipped the first 2 letters of the code!

Another interesting fact, if I send 0x1D, 0x6B, 0x49, (byte)(barCode.Length + 2) } and then put 2 white spaces in the beginning of the barcode data like this: $" {data}"

It also prints correctly (without skipping any characters when read by a scanner). So my guess is that the type (CODE A, CODE B, etc) is being inferred by my printer when a wrong type is sent.

I will fix my library so it can print correctly. About the spaces, I believe they are not really necessary since your tests and mine didn't use them and the scanner read the data successfully.