The function CRC16 (var Buff_addr; Len: Word) : Word; Var The index, the CRC: Word; DataPtr: PChar; The begin DataPtr:=PChar (@ Buff_addr); Index:=0; CRC:=0;
While (len & gt; 0) do The begin CRC:=Byte ((CRC SHR 8) or (8) CRC SHL); CRC:=CRC xor Byte (dataPtr [index]); Inc (index); CRC:=CRC xor Byte (SHR (CRC and $ff) 4); CRC:=CRC xor (8) CRC SHL SHL 4; CRC:=CRC xor (SHL (CRC and $ff) 4) SHL 1; The end;
Result:=CRC; The end;
CodePudding user response:
Sister ugly, still take swimming laps,
You have to give under-16 u8, the definition of the two is clearly a custom type or a type of typedef
CodePudding user response:
To be modified, as follows:
The function CRC16 (var Buff_addr; Len: Word) : Word; Var The index, the CRC: Word; DataPtr: PChar; The begin DataPtr:=PChar (@ Buff_addr); Index:=0; CRC:=0;
While (len & gt; 0) do The begin CRC:=Byte (CRC SHR 8) or (CRC SHL 8); CRC:=CRC xor Byte (dataPtr [index]); Inc (index); CRC:=CRC xor Byte (CRC and $ff) SHR 4; CRC:=CRC xor (8) CRC SHL SHL 4; CRC:=CRC xor (SHL (CRC and $ff) 4) SHL 1; The end;
Result:=CRC; The end;
CodePudding user response:
Thank you, I try! Under-16 is double byte unsigned short; U8 unsigned char.
CodePudding user response:
Still have some problems The original function definition is The function CRC16_Modbus (pByteInfo: PByte; ILength: integer); Stdcall; External 'CRC16Modbus. DLL'; Now change to The function CRC16 (var Buff_addr; Len: Word) : Word; The definition of compile error, can be compatible with the original?