Highlighted
Absent Member.
Absent Member.
714 views

[archive] Communications CRC Calculation??

[Migrated content. Thread originally posted on 03 February 2010]

I need to find a routine for calculating a two character checksum for a communications interface that I need to write. I have downloaded some "C" code examples, but since "C" is not a language that I'm real strong in, I'm having difficulty getting it to work.

What I've tried so far is to put the "C" code in a DLL library that I can call, but I'm not even sure I did that right. I'm hoping that someone either knows of an API call or has written something in Cobol already that would simplifiy this.

I need to be able to take a variable length data block and perform a CRC calculation against it to validate the information received, plus to be able to create one for transmission.

Thanks in advance,

Steve.
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Communications CRC Calculation??

working-storage section.
78 buf-len value 1024.
77 buf pic x(buf-len).
01 crc-var.
02 data-len pic 9(4).
02 crc-x pic x.
02 crc-red-x redefines crc-x pic 9 comp-x.
02 crc pic 9 comp-1.
02 crc-red redefines crc pic xx.
02 crc-hex pic xx.
02 inx pic 9(4).
02 crc-sum pic 9(3).
02 crc-result pic 9(3).


example-proc.
move "1234567890EXAMPLE" to buf
inspect buf replacing trailing spaces by low-values
perform calc-crc.

calc-crc. | CRC calculation unit
*/buf-> buffer variable
initialize crc-var.
inspect buf tallying data-len
for trailing low-values.
*/ computing data length
compute data-len = buf-len - data-len

perform varying inx
from 1
by 1
until inx > data-len
move buf(inx:1) to crc-x
add crc-red-x to crc-sum
end-perform.
divide crc-sum
by 256
giving crc-result
remainder crc
call "ascii2hex" using crc-red crc-hex
display message box
"Buffer : ",buf,x"0a0d",
"Data Length : ",data-len,x"0a0d",
"Checksum : ", crc-hex
title "Info".
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Communications CRC Calculation??

Unfortunatly, I need a CRC16 calculation with error detection: X16+X15+X2+1. This would give a 2 character Checksum for the 9 character string "123456789" of x"3DBB"

Attached is the snippet of "C" code that performs this function.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.