Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread184-1767704 Robsuttonjr.

Status
Not open for further replies.

wtotten

IS-IT--Management
Apr 10, 2002
181
US
thread184-1767704

Robsuttonjr. Your last reply in the above mentioned thread was that you figured out how to do this in FoxPro. How to calculate the Voice Pick code. I have the exact same need and would like to know if you can post the VFP code on how you get (calculate) the Voice Pick Code? I saw the link to the CRC16 page in that thread, but I don't quite understand how to use it for this need.

Thank you,
Bill Totten
 
I do. I'm not sure what the data is to be. Here is what Rob posted:
--------------- Directions from online -----------------------

Compute PlainText.

a. PlainText is the 14 digit GTIN appended by the Lot Code and the Date (where present).


b. Do not include the application identifier prefixes or parentheses.

c. There are no spaces between the GTIN, Lot and Date fields.

d. Date if present is represented as YYMMDD with zero packing and no '/' characters.

Compute ANSI CRC-16 Hash of the PlainText ASCII bytes using the standard ANSI CRC-16 hash with the polynomial of X16 + X15 + X2 + 1

Compute the VoiceCode by from the Hash by taking the 4 least significant digits in decimal form (Hash mod 10000)

---------------------- Example: --------------------

GTIN = (01) 10850510002011


Lot = (10) 46587443HG234
PlainText = 1085051000201146587443HG234
VoiceCode = 6359
Large Digits = 59
Small Digits = 63

In my example the GTIN is 10851146002659
My lot code is 012518
The "date" is the Pack date and it is 011518

My question is, in berezniker's code what value do I assign to his "lcStr" variable if these are my values?

Is it 10851146002659012518011518 or something else?

Part of the instructions that Rob posted that he found online says "polynomial of X16 + X15 + X2 + 1". I don't now what that means so I don't know how to construct my lcStr value.

Bill
 
As per Robs samples what lcStr is is the PlainText "1085051000201146587443HG234", he lists the expected CRC-16 checksums.

CRC-16 sounds as if it's just one single well defined checksum, but there are many ways to compute it, and X16 + X15 + X2 + 1 is one of the possible computations.
You don't have to implement that, you're using bereznikers code for that. And I just showed, that SYS(20007) does NOT compute that specific CRC-16 checksum but another variant called CRC-CCITT. But that only means you can't use SS(2007) and have to use bereznikers code.

Instead of setting lcStr to a specific value, just make it a paremeter and ou have a function.

Bye, Olaf.
 
I ran the code from berezniker:
* The code below seems to produce correct result but it hasn't been tested thoroughly.
* Polynom = 0x8005
#DEFINE CRC16 0xA001

* Build CRC table
DIMENSION laCrc[256]

FOR i=0 TO 255

lnData = i
lnCrc = 0
FOR j=0 TO 7
IF BITAND(BITXOR(lnData, lnCrc),1) > 0
lnCrc = BITXOR(BITRSHIFT(lnCrc,1), CRC16)
ELSE
lnCrc = BITRSHIFT(lnCrc,1)
ENDIF

lnData = BITRSHIFT(lnData,1)

ENDFOR

*? i, TRANSFORM(lnCrc, "@0")
laCrc[i+1] = lnCrc
ENDFOR

* Calculate CRC16
lcStr = "1234567898765421"

lnCrc = 0
FOR i=1 TO LEN(lcStr)
lnByte = ASC(SUBSTR(lcStr,i,1))
lnCrc = BITXOR( BITRSHIFT(lnCrc,8), ;
laCrc[BITXOR(BITAND(lnCrc, 0xFF), lnByte)+1])
ENDFOR
? TRANSFORM(lnCrc, "@0")



The ? displays a value of 0x0000BE18 using the "lcStr" value in the code above. If I use Ron's value of "1085051000201146587443HG234" the program returns a value of 0x000066F7. What Ron was, and I am, looking for is a value like what is calculated in Ron's example - the "6359" value:
Lot = (10) 46587443HG234
PlainText = 1085051000201146587443HG234
VoiceCode = 6359
Large Digits = 59
Small Digits = 63

Forgive me, I'm a decent VFP programmer, but I'm not computer science educated person. How do I get a value such as "6359" returned form the routine above? I know how to pass it a parameter and use it as a function. I don't understand how to take the result of something like 0x000066F7 and get that to be 6359.

Can you help?

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top