Jun 12, 2009

CODE 128

Theo comment của một độc giả, hôm nay mã vạch cung cấp thêm một số thông tin về barcode 128
(Bài viết này được dịch từ tài liệu tiếng Anh, một số từ ngữ có thể không biểu diễn sát nghĩa như bản gốc - Mong nhận được góp ý)

Code 128 hay được biết dưới tên đầy đủ là "Full ASCII-Character set with Code128 ABC autoselection" được giới thiệu lần đầu vào năm 1981 như một loại mã hóa ký số ASCII với mật độ cao.

Code 128 là tập gồm các ký tự số 0-9, ký tự a-z (hoa và thường) và tất cả các ký tự biểu tượng chuẩn ASCII và cả mã điều khiển. Và được chia thành 3 loại là A,B và C.

  • Code 128A bao gồm các ký tự chuẩn ASCII, số, chữ hoa, chữ thường và mã điều khiển.
  • Code 128B bao gồm các ký tự chuẩn ASCII, chữ số, chữ hoa và thường.
  • Code 128C nén 2 ký số trong một ký tự mã hóa, cung cấp một dạng mã hóa nén tốt nhất .

Mã số 128 là rất hiệu quả, mật độ cao symbology đó cho phép các mã hóa dữ liệu của alphanumeric. Các symbology checksum bao gồm một chữ số để xác minh, và các quầy bar cũng có thể được mã xác nhận ký tự của các ký tự xác minh tính chẵn lẻ của mỗi byte dữ liệu. Symbology này đã được triển khai thực hiện rộng rãi trong nhiều ứng dụng tương đối lớn, nơi một số lượng dữ liệu phải được mã hóa trong một số lượng tương đối nhỏ không gian. Nó cũng cho phép cụ thể cơ cấu số dữ liệu sẽ được mã hoá tại, có hiệu quả, đôi mật độ.

Ví dụ về alphanumeric mã hóa trong một quầy bar Mã số 128 mã là:

COMPUTING THE CHECKSUM DIGIT

Before a Code 128 symbol may be encoded, the software must compute the correct checksum digit which will be included in the bar code. The checksum digit is based on a modulo 103 calculation based on the weighted sum of the values of each of the digits in the message that is being encoded, including the start character.

The steps for calculating the check digit are as follows:

  1. Take the value of the start character (103, 104, or 105) and make that the starting value of the running checksum.
  2. Starting with the first data character following the start character, take the value of the character (between 0 and 102, inclusive) multiply it by its character position (1) and add that to the running checksum.
  3. Take each additional character in the message, take its value, and multiply it by its character position, and add the total to the running checksum.
  4. Divide the resulting running checksum by 103. The remainder becomes the checksum digit which is added to the end of the message.
  5. The stop character is appended after the checksum digit.
This is easier to understand with an example. Let's calculate the checksum digit for the sample bar code above, "HI345678". The checksum digit is included in all Code 128 bar codes, but it isn't printed as part of the text below the bar code symbol (as is the case with UPC and EAN symbols).

Barcode START-A H I CODE-C 34 56 78
Character Value 103 40 41 99 34 56 78
Character Position - 1 2 3 4 5 6
Calculation 103 40 * 1 41 * 2 99 * 3 34 * 4 56 * 5 78 * 6
Weighted Sum 103 40 82 297 136 280 468

Summing up the running checksum for each digit, we get 103 + 40 + 82 + 297 + 136 + 280 + 468 = 1406. This value divided by 103 is 1406 / 103 = 13 with a remainder of 67. Thus the checksum digit is the character which has a value of 67.

    NOTE: Note that the checksum starts with the first Start Character, with a weight of 1, and that the first data character also has a weight of 1.

ENCODING THE SYMBOL

Once the checksum digit has been calculated we know the entire message which must be encoded in the bars and spaces. Continuing with our example, we will encode, from zero, the Code 128 bar code we used in our example above: HI345678 with a checksum digit of 67.

In the following text, we will discuss the encoding of the bar code by considering that the number "1" represents a "dark" or "bar" section of the bar code whereas a "0" represents a "light" or "space" section of the bar code. Thus the numbers 1101 represents a double-wide bar (11), followed by a single-wide space (0), followed by a single-wide bar (1). This would be printed in the bar code as:


STRUCTURE OF A CODE 128 BARCODE

A Code 128 bar code consists of a leading quiet zone, one of three start codes, the data itself, a check character, a stop character, and a trailing quiet zone.

The Code 128 specification defines three "character sets" or "character modes." The start code that is used determines which character set will be used. The character set may also be changed in the middle of the bar code. For example, in the bar code above the bar code starts in "Character set A" to encode the text "HI", and then switches to "Character set C" to more efficiently encode the numbers that follow.

To encode a value as a Code 128 bar code, the checksum digit must first be calculated (see procedure above) and the entire bar code, including check digit, may then be encoded as a sequence of bars and spaces.

A Code 128 bar code has the following physical structure:

  1. Start code, which is the code 103, 104, or 105 from the encoding table below (either 11010000100 (Start-A), 11010010000 (Start-B), or 11010011100 (Start-C).
  2. Each of the data bytes of the message, encoded with the encoding table below.
  3. The checksum byte, calculated as described above and encoded using the table below.
  4. Stop character of 11000111010.
  5. Termination bar of 11.

CODE 128 ENCODING TABLE

This table indicates how to encode each digit of a Code 128 bar code. Note that it is easiest to think of each character as a value between 0 and 105, inclusive, rather than thinking of them as characters. The character that a value represents depends on what mode (or character set) you're in-so rather than thinking of a character as "A" or "B", etc. it is more appropriate to think of it as 33, 34, etc.

VALUE WHICH REPRESENTS IN
CHARACTER SET
ENCODING VALUE WHICH REPRESENTS IN
CHARACTER SET
ENCODING
A B C A B C
00 SP SP 00 11011001100 53 U U 53 11011101110
01 ! ! 01 11001101100 54 V V 54 11101011000
02 " " 02 11001100110 55 W W 55 11101000110
03 # # 03 10010011000 56 X X 56 11100010110
04 $ $ 04 10010001100 57 Y Y 57 11101101000
05 % % 05 10001001100 58 Z Z 58 11101100010
06 & & 06 10011001000 59 [ [ 59 11100011010
07 ' ' 07 10011000100 60 \ \ 60 11101111010
08 ( ( 08 10001100100 61 ] ] 61 11001000010
09 ) ) 09 11001001000 62 ^ ^ 62 11110001010
10 * * 10 11001000100 63 _ _ 63 10100110000
11 + + 11 11000100100 64 NUL ` 64 10100001100
12 , , 12 10110011100 65 SOH a 65 10010110000
13 - - 13 10011011100 66 STX b 66 10010000110
14 . . 14 10011001110 67 ETX c 67 10000101100
15 / / 15 10111001100 68 EOT d 68 10000100110
16 0 0 16 10011101100 69 ENQ e 69 10110010000
17 1 1 17 10011100110 70 ACK f 70 10110000100
18 2 2 18 11001110010 71 BEL g 71 10011010000
19 3 3 19 11001011100 72 BS h 72 10011000010
20 4 4 20 11001001110 73 HT i 73 10000110100
21 5 5 21 11011100100 74 LF j 74 10000110010
22 6 6 22 11001110100 75 VT k 75 11000010010
23 7 7 23 11101101110 76 FF l 76 11001010000
24 8 8 24 11101001100 77 CR m 77 11110111010
25 9 9 25 11100101100 78 SO n 78 11000010100
26 : : 26 11100100110 79 SI o 79 10001111010
27 ; ; 27 11101100100 80 DLE p 80 10100111100
28 < < 28 11100110100 81 DC1 q 81 10010111100
29 = = 29 11100110010 82 DC2 r 82 10010011110
30 > > 30 11011011000 83 DC3 s 83 10111100100
31 ? ? 31 11011000110 84 DC4 t 84 10011110100
32 @ @ 32 11000110110 85 NAK u 85 10011110010
33 A A 33 10100011000 86 SYN v 86 11110100100
34 B B 34 10001011000 87 ETB w 87 11110010100
35 C C 35 10001000110 88 CAN x 88 11110010010
36 D D 36 10110001000 89 EM y 89 11011011110
37 E E 37 10001101000 90 SUB z 90 11011110110
38 F F 38 10001100010 91 ESC { 91 11110110110
39 G G 39 11010001000 92 FS | 92 10101111000
40 H H 40 11000101000 93 GS } 93 10100011110
41 I I 41 11000100010 94 RS ~ 94 10001011110
42 J J 42 10110111000 95 US DEL 95 10111101000
43 K K 43 10110001110 96 FNC3 FNC3 96 10111100010
44 L L 44 10001101110 97 FNC2 FNC2 97 11110101000
45 M M 45 10111011000 98 SHIFT SHIFT 98 11110100010
46 N N 46 10111000110 99 Code C Code C 99 10111011110
47 O O 47 10001110110 100 Code B FNC4 Code B 10111101110
48 P P 48 11101110110 101 FNC4 Code A Code A 11101011110
49 Q Q 49 11010001110 102 FNC1 FNC1 FNC1 11110101110
50 R R 50 11000101110 103 START A START A START A 11010000100
51 S S 51 11011101000 104 START B START B START B 11010010000
52 T T 52 11011100010 105 START C START C START C 11010011100
STOP STOP STOP 11000111010

CODE 128 ENCODING EXAMPLE

We will now code the above example, HI345678, in Code 128. As we calculated in the Checksum Digit Calculation section, the checksum digit is 67. So we must also code the checksum digit at the end of the message.

We encode each digit using the encoding table above.

  1. The START-A character: 11010000100.
  2. The digit "H" encoded as: 11000101000.
  3. The digit "I" encoded as: 11000100010.
  4. The "CODE-C" character: 10111011110.
  5. The digits "34" encoded as: 10001011000.
  6. The digits "56" encoded as: 11100010110.
  7. The digits "78" encoded as: 11000010100.
  8. The checksum digit of 67 encoded as: 10000101100.
  9. The STOP character: 11000111010.
  10. The termination bar: 11.
This is shown in the following graphical representation where the bar code has been sectioned-off into areas that reflect each of the 10 components just mentioned.



Summary CODE 128:

Character Set: The full ASCII set (128 characters). One of the advantages of this symbology is the ability to encode all 128 characters of the standard ASCII code chart.
Encodation: Three bars and three spaces are required to encode a character.
Start/Stop Pattern: One of three start characters A, B, or C shall be used at the beginning of the symbol to define initial code set. The stop pattern is seven elements comprised of four bars and three spaces. The Start/Stop pattern shall not be used within the symbol nor shown in human-readable interpretation.
Code Type: Modular, varying length (UCC/EAN - 128 has several formats defined).
Human Readable: Optional; although it is typically used.
Check Character: Required (Modulus 103 calculation).
Encoded Information: Contingent upon data requirements.
Allowable Sizes: Minimum "X" Dimension: .0075 inches.
Allowable Symbol Height: The greater of .25 inch or 15% of the symbol length.

07-01-2009

No comments: