Skip to main content

[archive] Communications CRC Calculation??

  • February 4, 2010
  • 4 replies
  • 1 view

[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.

4 replies

[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.
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".

[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.
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.

[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.
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.

[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.
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.