CRC Calculation for SLC 500 PLC Driver

G

Thread Starter

Gopa

If anybody have source code for CRC calculation for slc 500 plc driver pls send to me. (VB/VC)
 
There is an example, in Borland Delphi (Pascal), buts it´s work, you must be initialize CRC=0. AB document No.1770-6.5.16 explains the DF1 protocol. But be carefully, there is NAK code mistake in pag.2-6; NAK code is 15h not 0Fh.

-------------------------------------------
procedure CalCRC(var CRC: Word; X: Byte);
var
I: Integer;
begin
WordRec(CRC).Lo:= WordRec(CRC).Lo XOR X;
for I:= 1 to 8 do
begin
if (CRC and $0001) = 1
then begin
CRC:= CRC shr 1;
CRC:= CRC xor $A001;
end
else CRC:= CRC shr 1;
end;
end;
---------------------------------------------
best regards
Sergio
 
L
Interestingly enough, the DF1 and Modbus CRC are the same but one is "forward" and one is "reverse". Thus DF1 starts with CRC=3D0, while Modbus starts with CRC=3D0xFFFF.

Unless 512 bytes of ROM (or pre-init data) kills you, most people would use the "table-lookup" method to cut 95% of the CPU work out of the
design.

This is described for Modbus in the various Modicon tech docs on-line - or the DF1 version is fully described (oddly enough) in the ODVA
Ethernet/IP spec Volume #1, Appendix C-7 CIP Data Management. You'll see both the "slow bit-shift" method and the fast table-lookup method there.

regards

Lynn August Linse, Senior IA Application Engineer
15353 Barranca Parkway, Lantronix Inc, Irvine CA 92618
[email protected] www.lantronix.com
Tel: (949)279-3969 Fax: (949)453-7152
 
Top