Thema: Modbus CRC

Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: Modbus CRC

  Alt 3. Feb 2006, 14:25
Herzlich willkommen in der Delphi-PRAXiS, Enzo.

Vielleicht funktioniert es hiermit:

Delphi-Quellcode:
function CRC16(const s: String; const start, polynom: Word): Word;
var
  w, i, j: Word;
  b: Byte;
begin
  Result := start;
  for i := 1 to (2 + Length(S)) do begin
    if i > Length(S)
      then b := 0
      else b := Ord(S[i]);
    for J := 1 to 8 do begin
      w := (b shr 7) xor (Result shr 15);
      if (w = 1) then Result := Result xor polynom;
      Result := (Result shl 1) or w;
      b := b shl 1;
    end;
  end;
end;
Grüße vom marabu
  Mit Zitat antworten Zitat