hoangtu (5th January, 2022), Johnner (29th December, 2021), jomberykaso (29th May, 2022), rafa192 (22nd May, 2022)
I also want to participate in this great topic, below 3 functions 100/100 working for the calculation of the CRC16
1.CRC16_KERMIT
2.CRC16CCITT_False
3.crc16_mcrf4xx
function CRC16_KERMIT(cadena : string):word;
var
valuehex : word;
i: integer;
CRC : word;
Begin
CRC := 0;
While i< length(cadena) do
begin
valuehex := ((strtoint('$'+cadena[i+1]+cadena[i+2]) XOR CRC) AND $0F) * $1081;
CRC := CRC SHR 4;
CRC := CRC XOR valuehex;
valuehex := (((strtoint('$'+cadena[i+1]+cadena[i+2]) SHR 4) XOR LO(CRC)) AND $0F);
CRC := CRC SHR 4;
CRC := CRC XOR (valuehex * $1081);
i:=i+2;
end;
CRC16_KERMIT:=(LO(CRC) SHL 8) OR HI(CRC);
end;
************************************************** **********
function crc16CCITT_False(Buffer:String):Cardinal;
Const polynom=$1021;
var
i,j: Integer;
Initial:word;
begin
Initial:=$ffff;
Result:=Initial;
i:=0;
While i< Length(Buffer) do begin
Result:=Result xor (strtoint('$'+buffer[i+1]+buffer[i+2]) shl 8);
for j:=0 to 7 do begin
if (Result and $8000)<>0 then Result:=(Result shl 1) xor Polynom
else Result:=Result shl 1;
end;
i:=i+2;
end;
Result:=Result and $ffff ;
end;
************************************************** ******
function crc16_mcrf4xx( data: string): word;
var
i,j: integer;
crc:word;
len:int64;
begin
crc:=$FFFF;
len:=length(data);
i:=0;
if len <= 0 then exit
else
begin
while i<len do begin
crc := crc xor strtoint('$'+data[i+1]+data[i+2]);
for j:=0 to 7 do
begin
if odd(crc) then
crc:=(crc shr 1) xor $8408
else
crc:=(crc shr 1);
end;
i:=i+2;
end;
end;
crc16_mcrf4xx:=crc;
end;
********************************
for the use of these functions:
crc16CCITT_False(Data); // data: must be in Hex
crc16_mcrf4xx(Data); // data: must be in Hex
CRC16_KERMIT(Data); // data: must be in Hex
You can check the results using the site https://crccalc.com/
these types of crc16 are commonly used, example bsi valeo and continental 95256, JC and Delphi 25128
Last edited by MYMN; 29th December, 2021 at 05:45 PM.
hoangtu (5th January, 2022), Johnner (29th December, 2021), jomberykaso (29th May, 2022), rafa192 (22nd May, 2022)
Example peugoet 3008 2017, BSI delphi.. mileage : 127000 km
0x2900............00 13 60 F0 FF EC 9F 0F 00 00 E7 7B
00 13 60 F0 : Mileage (127000 * 10 >>to Hex ).
FF EC 9F 0F : =(00 13 60 F0) xor (FF FF FF FF )
E7 7B : is the CRC, obtained using the function CRC16 CCITT False :
CRC16 CCITT False('001360F0FFEC9F0F0000') ; // the function returns: E7 7B
Last edited by MYMN; 29th December, 2021 at 07:54 PM.
Hello everyone... could someone help me with two questions? If so, the first is how to use a filename saved as the date of the day, for example using this type of command:
procedure Button4Click(Sender: TObject);
var e: TXHexEdit
begin
e := GetHexEdit();
if e <> nil then
if SaveDialog1.Execute(' ') then
e.SaveFile( SaveDialog1.FileName );
end;
The second one I've researched endlessly and I haven't found any way to encrypt the scripts with a .udx extension. Can someone help me?
Thank you so much, Hcip once again! The code you posted earlier worked perfectly and this new one will certainly be of great help! I know you've been asked a lot, but in all my searches I didn't find what I was looking for, if it's not too much to ask, how do I encrypt my scrips in udx? No one so far knew how to leave this question in a way that I could understand... (apologies for my English).
Exactly what I've been doing! Thank you so much again for your great help!With that explanation it was clear as light!
Diogo Mello (11th January, 2022)
Hello every one I have to ask what is the problem and how to solve this error, the code is run but when you put text number to the Edit Text and press ok then I get Error, please advise every one.
I have never used upa, but in pascal language, we must assign the types of variables to the declared variables:
in your script:
var n,code:integer;
Regarding your error, it is normal:
you did not give a value to your variable 'Code'
it is necessary to put :
Code:=strtoint(edit1.text);
before that you can put the following code, to avoid the error in case of not entering the value in edit1
if (edit1.text='' ) or ( strtoint(edit1.text)>9999) then begin
MsgBox( 'Your message Here ', 'Error', MB_OK );
exit;
end;
if you want to prohibit entering non-numeric characters you can use this code:
Val(edit1.text,code,i) ;// you have to declare the variable I as an integer
if i<>0 then begin
MsgBox( 'The entered value is not an integer', 'Error', MB_OK );
exit;
end;
I don't know if the val procedure works in the UPA compiler, but it exists in the pascal language
Last edited by MYMN; 31st January, 2022 at 01:26 PM.
hello mate I have another error variable is not an array and the Val procedure is not work in the IDE what should be the problem
Load a clear image, I see nothing,
put your code here to see where the problem ,,
Hello mate here is the code thank you
////////////////////////////////////////////////
procedure EditCode;
Var n, Code: integer;
begin
SetProgramModifiedOnly( True);
if (edit1.text='' ) or ( strtoint(edit1.text)>9999) then begin
if Length(Edit1.Text='')< 4 then begin
MsgBox( 'Enter 4 Numbers Only ', 'Error', 0 );
exit;
end;
end;
Code:=StrtoInt(edit1.text);
SetByteHexEdit($1F6, StrToInt('$'+ Code[1]+Code[2]));
SetByteHexEdit($1F7, StrToInt('$'+ Code[3]+Code[4]));
RefreshHexEdit;
end;
Bookmarks