rbWiki > RCL > BarCode > Manual Encode 128

Manual Encode 128

Table of contents
No headers

By default Barcode.AutoEncode is set to true. For most applications, you should use the AutoEncode feature - which creates the encoded version of the data automatically.

Set AutoEncode to False and manually encode the data for a Code 128 BarCode when you have special requirements. 

If you are unfamiliar with Code 128, I will try to give you a quick tutorial, as Code 128 is more complicated than most other one-dimensional barcodes.

The first thing you must know about Code 128 is that it has three different character sets (A, B, and C).  That means one set of bars can mean three different things based on which set is currently in use.  The other tricky bit is that you have the option of switching character sets in the middle of the code.  I think you see now why this is a more difficult code.

Character set A can encode most symbol characters (!,$,/, etc.) as well as all uppercase letters and the ten digits.  In addition, it can encode the "special" ASCII characters, such as carriage return, line feed, null, escape, etc.
 
Character set B encodes all symbol characters, upper and lowercase letters and the ten digits.
 
Character set C encodes 100 pairs of numbers.  That is, one set of bars could mean "05" or "43", etc.  This effectively doubles the density of Code 128 when using numbers only.  Also note, because they are numeric pairs, the Code C portion must have an even number of digits.

Now that you know what the differences in the codes are, you now have to know how to use them with the BarCode component.  Since all normal ASCII characters are used by Code 128, we must use special characters to tell the component what to do.  The BarCode component uses ASCII values #208 through #242 for this purpose.  If you’re using the Object Inspector to type the Data property, you hold down the Alt key, then type (on the numeric keypad) 0 + the number  (Alt-0208 for instance).  The table below lists all of the special characters.  

#208  START A
#209   START B
#210  START C

These are the special START CODE characters.  Each Code 128 barcodes MUST START with one of the three above. Which start code you use is obviously which character set is active.  You cannot use a start code in the middle of a symbol.  See the table below for the special codes used to switch to a different character set.  

 Special Char  Character Set A  Character Set B  Character Set C
 #201  Function 3  Function 3  <none>
 #202  Function 2  Function 2  <none>
 #203  TempShift to B  TempShift to A   <none>
 #204  Switch to C  Switch to C  <none>
 #205  Switch to B  Function 4  <none>
 #206  Function 4   Switch to A   Switch to A
 #207  Function 1  Function 1  Function 1
 #211  NUL  <none>  <none>
 #212  SOH   <none>  <none>
 #213  STX  <none>  <none>
 #214  ETX   <none>  <none>
 #215  EOT   <none>  <none>
 #216  ENQ   <none>  <none>
 #217  ACK   <none>  <none>
 #218  BEL   <none>  <none>
 #219  BS   <none>  <none>
 #220  HT   <none>  <none>
 #221  LF   <none>  <none>
 #222  VT   <none>  <none>
 #223  FF   <none>  <none>
 #224  CR     <none>  <none>
 #225  SO     <none>  <none>
 #226  SI   <none>  <none>
 #227  DLE   <none>  <none>
 #228  DC1   <none>  <none>
 #229  DC2   <none>  <none>
 #230  DC3    <none>  <none>
 #231  DC4    <none>  <none>
 #232  NAK    <none>  <none>
 #233  SYN    <none>  <none>
 #234  ETB    <none>  <none>
 #235  CAN    <none>  <none>
 #236  EM    <none>  <none>
 #237  SUB     <none>  <none>
 #238  ESC    <none>  <none>
 #239  FS    <none>  <none>
 #240  GS   <none>  <none>
 #241  RS   <none>  <none>
 #242  US   <none>  <none>
  

Got all that?  <smile>  Ok, so here’s what that table means:  if the current character set is A, then a #205 means Switch to Code B.  If the current set was B, that same #205 means Function 4. 

The Switch codes are all boldfaced because you’ll probably use those the most.  A Switch code means "Switch to Character Set X for the remainder of the code, or until another Switch code is encountered."

The Temp-Shift codes means "Shift to Code X for the next character only."

The "Function" codes mean different things based on your barcode reader.  Generally they are explained in the reader’s documentation.

Ok, I think a few examples are in order:

Let’s say you want to encode the text "CODE 128".  Character set A is sufficient.  Here’s how:

  ppBarCode1.Data := #208 + 'CODE 128'; 

If you were using the Object Inspector, you would’ve typed {Alt-0208}CODE 128.    

Here’s a little more advanced example.  We want to encode "1234 abcd".  We can use Set C, since we have an even number of digits.  Then we have to switch to Set B for the lowercase letters.

  ppBarCode1.Data := #210 + '1234' + #205 + ' abcd';

Ok, one last example.  We want to encode "Soft Sector 1996", but we want a Carriage Return in between "Soft" and "Sector".  Here goes:

  ppBarCode1.Data := #209 + 'Soft' + #203 +  #224 + 'Sector ' + #204 + '1996';

See what happened there?  We started off in Set B and wrote "Soft", then we Temp Shifted to A to encode the CR.  The we wrote "Sector" in Set B.  Finally, we switched to Set C to encode "1996."

Tags
none

Files (0)

 
You must login to post a comment.