Carobit Logo
Valid HTML 4.01!

Your Connection
  guest
Log out
Log in or Sign Up
Site Navigation
  Home
Forum Home
Closed Conversations
For Members
  Support
Feedback
Member Search
Carobit Mail
Helpful Links
  Smilies
Formatting
Preview
Originator: mac Printable Version
Title: code 128 barcode checksum
Back to Lounge

Attachments Add Attachment

History
From: Send Carobit Mail mac On: 2008/08/29 09:33:18
anybody know anything about generating barcode checksums?

i'm trying to calculate the check sum for Code 128-B, which is Mod 103
this link is a good description of how it's calculated.

in this case, my original value is 746323
so the formula is:
(104) + (23 * 1) + (20 * 2) + (22 * 3) + (19 * 4) + (18 * 5) + (19 * 6) = 513
513 Mod 103 = 101

so, looking at this chart, i find that the Check Sum for 101 is...
CODE A

what the hell is "CODE A"?
how is that a printable character that i can append to 746323?

any ideas?
(i already tried rebooting, and moving the monitor farther away from my eyes)

From: Send Carobit Mail syscokid On: 2008/08/29 09:36:06
No clue.  Hope this helps!

From: Send Carobit Mail stone5150 On: 2008/08/29 09:59:54
Try dividing by 0.

From: Send Carobit Mail mac On: 2008/08/29 10:03:52
before or after i reboot? (sheesh, be specific, will ya?)

From: Send Carobit Mail stone5150 On: 2008/08/29 10:41:41
During

From: Send Carobit Mail syscokid On: 2008/08/29 10:48:53
How do you get from that chart that the checksum for 101 is Code A?  The Code A for 101 is FNC4, and the Code B is...tada! Code A!  Does this make sense to you, because it's making my head hurt...more than it usually does.

From: Send Carobit Mail mac On: 2008/08/29 10:58:24
ok, good eye.
if i use the result from the Code A column (didn't think of that), i'll be appending a "FNC 4"
what the hell is "FNC 4"?
... the F4 key?
how the hell do i append the F4 key?
it's not in "the lower 128 ASCII characters" (the definition of the "B" in "Code 128-B")!!!

From: Send Carobit Mail syscokid On: 2008/08/29 11:20:44
Sorry, I'm not that smart!  I just look that way.

From: Send Carobit Mail mac On: 2008/08/29 12:02:24
yes you do.  joke's on me!

From: Send Carobit Mail stone5150 On: 2008/08/29 12:13:33
You expect people to know this stuff

in the Lounge!

From: Send Carobit Mail mac On: 2008/08/29 12:28:13
um, i looked for the "Code 128" department, and then the "barcode font" department, then the "anyfuckingthingotherthanthelounge" department, but all i found was the "jokes" department (and one with "Jammer dat het ons niet lukt om vaker te komen!" or some such nonsence).
the lounge was the only place that i thought i could drink a beer while waiting for someone to solve my problems for me.

From: Send Carobit Mail syscokid On: 2008/08/29 12:33:09
Code 128?  Why didn't you say so?  I was researching CODE A !!!!
<unsub>

:-D

From: Send Carobit Mail cleopatrark On: 2008/08/29 17:22:44
42 is always the answer.

From: Send Carobit Mail mac On: 2008/08/30 12:04:28

found it.

see?  and only 3 beers.... ok, maybe 4

http://freebarc....dobsonsw.com/Code128Samples.htm

Andreas Moroder, i owe you a drink.  stop by any time!!!!

From: bdobson On: 2008/08/30 14:43:33
Hey All,

Just a note to let you know that barcode fonts differ in where they place various special characters. The sample code linked above, as well as a little more meaningful information here:

http://freebarc...sw.com/Code128Transformation.htm

Will only work for the Code128 barcode font on
 
http://freebarcodefonts.dobsonsw.com

It's extremely unlikely they will work for any other Code 128 fonts.

Thought I would clarify this as it can be a difficult process putting everything together.

From: Send Carobit Mail mac On: 2008/08/30 15:52:13
hello bdobson,
here, have a drink on me.  don't know how you found me in this bar, but i'm glad you did.
please thank Andreas for me.  your font and his code worked great.

the description you posted explains the process well, if the check digit value is <= 95.  these are all represented by the lower 0 - 127 ACSII set.  but from 96 to 102, it's not so clear.

96   FNC 3   FNC 3   96   1 1 4 3 1 1
97  FNC 2  FNC 2  97  4 1 1 1 1 3
98  SHIFT  SHIFT  98  4 1 1 3 1 1
99  CODE C  CODE C  99  1 1 3 1 4 1
100  CODE B  FNC 4  CODE B  1 1 4 1 3 1
101  FNC 4  CODE A  CODE A  3 1 1 1 4 1
102  FNC 1  FNC 1  FNC 1  4 1 1 1 3 1

for 101, for instance, the chart is very hard to decipher.  what does it mean "CODE A"?



From: bdobson On: 2008/08/30 16:36:36
The left hand column of the table is the Code 128 value, or maybe it's better to think of it as a "Master Value." This is not the ASCII value but the absolute value for Code 128. The Variant A, B, and C values are transient depending on what the current encoding is. For instance, if you start out encoding a barcode with Variant C and encode the string "95", then need to shift to Variant B to encode a function, say DEL, the Code 128 master value for both the Variant C "95" and the Variant B "DEL" is still 95.

In short when dealing with Code 128 it's better to think of the Master Value than what that value means in a particular variant because when you do your Mod 103 checksum, either Variant C "95" or Variant B DEL has the same "Master Value" to compute the checksum.

Does that make sense? I hope so but it can be a confusing mess in there, for sure, and I deal with it every day ;) Beer helps.

The other value of note in the tables I linked to is the ASCII value. That is the value that will display that particular character in my font set. So, in keeping with the example above, if you were trying to encode a Variant C "95" or a Variant B "DEL," you would display the character in the font at location 145, typically something like var = Chr(145)

I hope I havent made it more confusing ;)

From: bdobson On: 2008/08/30 17:08:35
Duh - I didn't answer your original question. Code 128 allows a bunch of different functions within the three variants, and the ability to shift between variants. (I do not have the Variant A functions listed in my table, cause it makes it a little too confusing, but I'll give a brief rundown for a few of the special characters.) Say your current encoding is Variant B. You will notice that Variant B has a SHIFT value in it at Code 128 value 98. Say you need to put in a carriage return and that's not allowed in Variant B, but it is allowed in Variant A.

So you shove a value 98 character into the string, which is the Variant B SHIFT value. This tells the scanner to read the next character as a Variant A character, and subsequent characters are read as Variant B characters. So, in the string after the SHIFT, you stuff in the character that IN VARIANT A means carriage return (not sure which it is off the top of my head,) and your scanner will add a carriage return to the output.

You specifically asked about CODE A. Those CODE values tell the scanner that you are switching variants, not for just the next character like SHIFT does, but essentially until either another CODE value is found or the barcode ends. Say, for instance, you are encoding MAC12345678, you could encode it all in Variant B, or you could save space by switching between variants, and that is what those CODE statements are for. This is what the encoding would look like in all Variant B (using the master values):

[45] = "M"
[33] = "A"
[35] = "C"
[17] = "1"
[18] = "2"
[19] = "3"
[20] = "4"
[21] = "5"
[22] = "6"
[23] = "7"
[24] = "8"

By switching to Variant C in the middle of the barcode you could lose 3 characters in length:

[45] = "M"
[33] = "A"
[35] = "C"
[99] = [CODE C]
[12] = "12"
[34] = "34"
[56] = "56"
[78] = "78"

Obviously, the longer the series of digits the more space you save by encoding in Variant C.

This is probably overkill to your question but I hope it helps explain.

From: Send Carobit Mail mac On: 2008/08/30 17:34:44
i need another beer.

From: Send Carobit Mail mac On: 2008/08/31 05:06:50
ok, bdobson, that was a great explaination THAT selection can shift to a different Variant, but what if i don't want to shift?
(i presume Variant B is the default)
what if i just want to stay in Variant B regardless of the length?
if my calculated check digit is 101, how do i stay in Variant B?

looks like i can't.  so that means i have to understand what "CODE A" means:

bear with me while i think this out - the question is at the end...

in my original example, my value is 746323
so the formula to find the check sum is:
(104) + (23 * 1) + (20 * 2) + (22 * 3) + (19 * 4) + (18 * 5) + (19 * 6) = 513
513 Mod 103 = 101

in Andreas' code, the final line builds the return string:

    code128 = Chr(154) + tmp + Chr(cs) + Chr(156)

Chr(154) is the Start character
tmp is the original value being encoded
Chr(cs) is the Chr() of the calculated check sum (the prize)
Chr(156) is the Stop character

cs is the "nut" here.
in MY original example, 513 Mod 103 = 101
so cs is 101

and Andreas' code handles (converts) it like this:

    If cs = 0 Then
        cs = 128
    ElseIf cs <= 94 Then
        cs = cs + 32
    Else
        cs = cs + 50        '<-- true
    End If

therefore:

cs = 101 + 50
so cs is changed to 151
and Chr(151) is the check sum character.

according to your Transformation chart, 151 is the value in the ASCII column for 101.

in your explaination, you said >>"Those CODE values tell the scanner that you are switching variants"<<, so i'm inferring that focus will jump to Variant A. (am i correct?)

but (in the chart that shows Variant A) the value returned for 101 from that column would be "FNC 4".

so the instruction "CODE A" implies that the focus shifts to the Variant A column, returning "FNC 4".

i don't even see FNC 4 in ANY ASCII chart.  how can Andreas' code be resolving a character that's not even in the ASCII set?

i'm clearly still not understanding what instruction "CODE A" implies.  does focus shift to Variant A (and what is "FNC 4") or does focus shift to the ASCII column?

beer++

From: Send Carobit Mail cleopatrark On: 2008/08/31 07:44:48
Ohhhhhhhh I see it is so clear to me now.  After all that you just simply have a beer and call it a day.

From: bdobson On: 2008/08/31 08:43:32
The check digit is Variant independent, so it doesn't matter what it means in whatever variant your encoding in, in the check digit position it's only value to the barcode, or the scanner reading it, is the Code 128 value it represents. The check digit position is really outside of the data your encoding.

Now the ASCII stuff - and I'm trying to figure out how to have this make sense so bear with me - Technically speaking, the only correlation between Code 128 and ASCII is because we are rendering the barcode in this situation with a font. If you were drawing just bars, say you were programming and rendering it as a bitmap, you would not worry about ASCII at all, because you would be drawing the bars with calls to DrawLine() or some such thing.

When you draw a code 128 character with a font, you are only drawing those bars and spaces that are located at, say, position 151 in your example above.

Let's look at character A, because it's easier to deal with. I just happened to build my font so that if you press A on the keyboard, in Arial you would get a latin A, and in the code128 font set you would get the bars and spaces that represent the Code 128 value "A" in Variant B. I could have just as easily put in bars and spaces that represent Q when you press the A button on the keyboard, but it would have been an algorithmic nightmare.

There is no ASCII value for FNC 4. But there is, in my font set, bars and spaces encoded in a character, that represents FNC 4 in Variant A. I could have put it at 155, 199, or 220, or any other location I wanted. In order to make an algorithmic conversion easy I put it where I put it. But I had to put it somewhere, so that someone that needed those bars and spaces could render it on the screen by drawing that particular character.

In short, any relation between ASCII and Code 128 is arbitrary. Some of the data you can encode with Code 128 are also in the ASCII character set, but only because those are characters we need to function in an English speaking environment so it makes sense that both specifications would include those characters.

So, to reiterate, when your working with Code 128 the ASCII doesn't matter at all to the Code 128 specification. Where is does matter is that if your using a font, and you need to render code 128 values with that font, you need a way to easily figure out where a certain value is encoded in the font set at what character position. That, and only that, is the reason for the ASCII column in the table.


From: bdobson On: 2008/08/31 08:59:38
Perhaps a better example regarding your ASCII question is the good old "WingDing" font set.

If you press A on the keyboard in that font set it draws a picture. There's no correlation between that picture and an ASCII A. You wont find that picture in the ASCII character set.

Same with the code 128 font set. You press A on the keyboard and it draws a picture. The fact that that picture, properly encoded with a start, check digit, and stop character means something to a barcode scanner is completely arbitrary. It's still just a picture that gets printed when you press that A character.


From: Send Carobit Mail mac On: 2008/09/02 09:06:34
bdobson,
i'm not sure we're looking at this elephant from the same direction.
it seems to me (programmer) that ASCII is definitely relevant, and it also seems to me that i'm only really interested in calculating that damn checksum digit (and not any of the rest of the digits, neither the original value to be converted, nor the Stop or Start characters because the rest of the characters are all static), getting the checksum digit depends on the ONE place on the chart that my calculated value lands me.
one checksum (or Code 128) value, one corresponding cell on the chart.
in my case, the Code 128 value is 101.
that lands me on the cell that says "CODE A"
so "CODE A" means that i HAVE to jump over and use the character in Variant A, so i HAVE to use "FNC 4".
and i have to convert that character to an ASCII character using Chr() (in my VB code)

now, i did find right under my nose, or more accurately, right under your Transformation Chart
http://freebarc...sw.com/Code128Transformation.htm
the following instruction that, had i seen it before, would have led me to writing code similar to Andreas':

***********  begin quote ************
Converting from Code 128 to ASCII:
1) Check for Code 128 value 0 [Variant B Space, Variant C 00] If Code 128 value is 0 than ASCII value equals 128
2) If Code 128 value is between 1 and 94 inclusive than ASCII value equals Code 128 value + 32
3) If Code 128 value is greater than 94 than ASCII value equals Code 128 Value + 50

For instance, Code 128 value 0 will equal ASCII value 128. Code 128 Value 1 [Variant B !, Variant C 01] will equal 1 + 32 equals ASCII value of 33. Code 128 value 98 [Variant B SHIFT, Variant C 98] will equal 98 + 50 equals ASCII Value of 148.

*************  end quote  ****************

and therefore, Andreas' gem:

    If cs = 0 Then
        cs = 128
    ElseIf cs <= 94 Then
        cs = cs + 32
    Else
        cs = cs + 50        '<-- true
    End If

so, my final thought is that FNC 4 must equal Chr(151)
and, in the right-most Variant column, called ASCII, i see that there IS a 151.

so, speaking of 151, anyone up for a shot of REALLY STRONG RUM?

From: Send Carobit Mail syscokid On: 2008/09/02 09:09:20
ù

I see we're back on topic!

From: bdobson On: 2008/09/03 18:24:02
OK - I understand your point. However, I really need to stress that the ASCII conversion is only an issue because in this case we are building the barcode with fonts. If we were drawing it with calls to drawline or drawrect or something it would not be an issue.

Regarding check digits, and values, and variants, ASCII is totally irrelevant. The Code 128 spec does not require ASCII at all, and if you are thinking in terms of ASCII you can easily get caught (Believe me I know! The code base I have been using since I first released my very first barcode product had a bug in it that was reported, for the first time, today! The cause... of course, translating a Code 128 value to an ASCII value to properly render it as a font.)

So, again, I have to stress that Code 128 does NOT require ASCII. Rendering it with a font does, but only to figure out what character code contains the spaces and bars that will properly render the barcode.

From: Send Carobit Mail mac On: 2008/09/04 10:48:07
got it.  and i will probably someday need to know this, as my customer is using them more and more.  i may want to find a way of skipping VBA translation and go directly to drawing the font.
i really appreciate all the help you gave me, bdobson!  if this forum still gave points, i'd double them!
but sadly, you're just going to have to let me buy you a cyber-beer.  and i'll double that!

Enter your comments here

As a guest you will only be able to see what a comment posted by you would look like by clicking the Preview button. You can't actually participate by posting comments to this conversation.

Number of viewers: 15