Home > Back-end >  Which brother can help me put this function into Delphi, thanks a lot ~
Which brother can help me put this function into Delphi, thanks a lot ~

Time:10-13

Under-16 CRC16 (void * Buff_addr, under-16 len)
{
Buff_addr u8 * dataPtr=(u8 *);
Under-16 index=0;
Under-16 CRC=0;

While (len -)
{
CRC=(u8) (crc> 8) | (crc<8);
CRC ^=dataPtr [index++];
CRC ^=(u8) (crc& 0 XFF) & gt;> 4.
CRC ^=(crc<8) & lt; <4.
CRC ^=((crc& 0 XFF) & lt; <4) & lt; <1;
}

The return of CRC;
}

CodePudding user response:


Give sister a ~

CodePudding user response:

 
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?

CodePudding user response:

CodePudding user response:

refer to 6th floor camdw response:

still have some problemThe 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?




The function CRC16_Modbus (pByteInfo: PByte; ILength: integer); Stdcall; External 'CRC16Modbus. DLL';
Or
The function CRC16_Modbus (pByteInfo: PChar; ILength: integer); Stdcall; External 'CRC16Modbus. DLL';

The function CRC16 (pByteInfo: PChar; ILength: integer) : Word;

CodePudding user response:

Turned out to be so called
Var
Data: an array of Byte [0.. 2048].
ICount, iResult: Integer;
IResult=CRC16_Modbus (@ Data, iCount);

Now I want to directly replace
IResult=CRC16 (@ Data, iCount); Basic not Delphi this way ~!

CodePudding user response:


Can, defines CRC16 as
function CRC16 (pByteInfo: an array of Byte;; ILength: integer) : integer;

CodePudding user response:

references 9 f camdw response:
turned out to be so called
Var
Data: an array of Byte [0.. 2048].
ICount, iResult: Integer;
IResult=CRC16_Modbus (@ Data, iCount);

Now I want to directly replace
IResult=CRC16 (@ Data, iCount); Basic not Delphi this way ~!


If this call iResult:=CRC16_Modbus ( @ Data, iCount); Is defined as the following:
The function CRC16 (Buff_addr: PChar; Len: integer) : integer;

If this call iResult:=CRC16_Modbus (Data, iCount); Is defined as the following:
The function CRC16 (Buff_addr: an array of Byte; Len: integer) : integer;

CodePudding user response:

The function CRC16 (Buff_addr: PChar; Len: integer) : integer;
Var
The index, the CRC: integer;
DataPtr: PChar;
The begin
DataPtr:=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; Compile ok, a running error ~ from the CRC:=CRC xor Byte (dataPtr [index]); began

CodePudding user response:

CRC check is? If so, I have here the DELPHI

CodePudding user response:

I this is a dedicated, how to upload files?nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related