unit unCRC16_Modbus;
interface
function CalCRC16(AData:array of Byte; AStart,AEnd:Integer): Word;
implementation
function CalCRC16(AData:array of Byte; AStart,AEnd:Integer): Word;
const
GENP = $A001;
var
crc:Word;
i:Integer;
tmp:Byte;
procedure CalOneByte(AByte:Byte);
var
j:Integer;
begin
crc:=crc xor AByte;
for j := 0 to 7 do
begin
tmp:=crc and 1;
crc:=crc shr 1;
crc:= crc and $7FFF;
if tmp = 1 then
crc:= crc xor GENP;
crc:=crc and $FFFF;
end;
end;
begin
crc:=$FFFF;
for i := AStart to AEnd do
CalOneByte(AData【i】);
Result:=crc;
end;
end.