A little PYTHON code for basic barcode checking before using an ESC/POS printer barcode renderig function. This ensures the barcode will be renderer correctly.
Note that most ESC/POS printers, such as the Epson TM T20ii, don't usually bother
with the checksums and stuff; they only care about the character set and the length
of the string. There are also some special formats, for example the CODE128 should be
prefixed with {B
for alphanumeric barcodes, etc.
-
UPC: UPC barcodes are 12 digits long, numeric only and include a checksum as the last digit. You calculate the checksum by summing each of the odd position numbers multiplied by 3 and then by adding the sum of the even position numbers. The final digit of the result is subtracted from 10 to calculate the check digit (or left as-is if already zero).
-
EAN EAN barcodes are either 8 (EAN8) or 13 (EAN13) digits long, numeric only nd include a checksum as the last digit. The checksum is the same as UPC, but the numbers are processed from the end, so the odd digits are last, third before last, etc.
-
NW7: the NW7 barcode has a start and stop character comprised between A to D, then the content of the barcode is comprised of numbers and characters -, ., $, /, +. It has a variable length and no checksum is required.
-
CODABAR: the codabar barcode has the same restrictions as NW7.
-
CODE39: Code 39 specification defines 43 characters, consisting of uppercase letters (A through Z), numeric digits and a number of special characters (-, ., $, /, +, %, and space). The symbol '*' can be used as a start/stop chacacter. It is sometimes used with an optional modulo 43 check digit.
-
CODE93: Code 93 uses the same character set as Code 39 with 2 check digits (module 47).
-
CODE128: it is identical to Code128, but with a maximum of 35 symbol characters (43 data characters).
-
GS1: http://www.databar-barcode.info/ https://www.gs1.org/barcodes/databar
- GS1 Omnidirectional: 14 digits
- GS1 truncated: 14 digits
- GS1 limited: 14 digits, leading digit is always 0 or 1
- GS1 expanded: maximum 74 numeric/41 alphanumberic