and massage it and calculate the check digit to to display a human-readable representation of the barcode: 123456789Īnd since the start char has obviously (?) been seen if the barcode has scanned, I can just pre-add it to the runningTotal value to be computed thus, my code is now: private void buttonAppendCode128CheckDigit_Click(object sender, EventArgs e) but which would logically strip out the stop char -since it is not part of the check digit calculation - and (not quite so logically) also strip out the check digit, so what I actually get would be: 123456789 So, if I understand Brian and other sources I'v read correctly, I will read from the barcode scanner what semantically decodes to: 123456789 If my suspicion is correct, what is done when a calculation does end up with a squirrely check digit such as "-" or "" or "~", &c? UPDATE 3 I admit I'm not exactly an ogler of barcodes, so I may have seen such and just not noticed/paid attention, but can barcodes have such check digits as "-" and " "? It seems bizarre I would expect them to always be alphanumerics if not just numerics. If both the stop and start characters were included, then of course that would change the solution, too. Since 1005 % 103 = 78, the check digit would be. Why would the start character be included in the calculation, but not the stop character? Aren't they there just so that the barcode scanner knows from which point to pay attention and thereafter from which point it can resume its electronic snoozing?Īnd then the math (provided Brian is correct about needing to subtract 32 from the ASCII vals) would be: (17*1)+(18*2)+(19*3)+(20*4)+(21*5)+(22*6)+(23*7)+(24*8)+(25*9)ġ7 + 36 + 57 + 80 + 105 + 132 + 161 + 192 + 225 = 1005 I'm not quite grokking Brian Anderson's answer he may be right (probably is), but I would think the start and stop bits would be ignored as far as the check digit calculation goes. Private int ConvertToASCIIInt(char valToConvertToASCII) Private char ConvertToASCIIChar(int code128Modulus) TextBoxCode128WithCheckDigit.Text = barCode + ConvertToASCIIChar(code128Modulus) Int code128Modulus = runningTotal%CODE_128_DIVISOR Int valToMultiply = ConvertToASCIIInt(valToConvertToASCII) String barCode = () įor (int i = barCode.Length - 1 i > -1 i-)Ĭhar valToConvertToASCII = Convert.ToChar(barCode) Last but not least, here is the code I used to compute the Code128 check digits: private void buttonAppendCode128CheckDigit_Click(object sender, EventArgs e) and how they should appear with their calculated check digits (and do, with the code below): 0) 123456789L If this is not the correct value, then I'm understanding something incorrectly. Verily and thus (notwithstanding further ado or adieux), you end up with a value of "123456789L" Penultimate-finally, you convert that value (76), considering it to be an ASCII code, back the other direction to its "presentation" value, namely "L".įinally, you append that calculated character to the original barcode. The next step is to divide that number by the Code128 "magic number" of 103 the value you're interested in is the modulus. You then sum all these up, to arrive at (in this case) 2,445. Then, the ordinal position of each character is multiplied by its ASCII value. for the fabricated barcode number "123456789" the "1" equates to 49, the "2" to 50. However, I would appreciate a "sanity check" by those who may know better/have some empirical observations/mud from the trenches attached to their trench (or lab) coats.Įach character in the barcode, from the left, is first converted into its ASCII code (IOW, a barcode character of "1" is to be viewed as its ASCII Code of 49, etc.) and then that value is multiplied by its ordinal position in the array of chars.Į.g. Based on my understanding* of the check digit calculation for Code128 barcodes (which differs radically/drastically from most of the other standard barcode types), my code below is correct.
0 Comments
Leave a Reply. |