Closed ertankucukoglu closed 1 year ago
Hi @ertankucukoglu I can't seem to reproduce the issue you are having with my simple demo attached below (at least while running on Delphi).
program CRCTest;
uses
HlpHashFactory,
HlpIHash,
HlpCRC,
HlpICRC,
HlpConverters,
System.SysUtils;
var
LCRC: IHash;
Bytes: TBytes;
CRC: TBytes;
I: Integer;
begin
try
var
str := '0017544553543030303032363036FF8A7507DF820803000001';
Bytes := TConverters.ConvertHexStringToBytes(str);
for I := 49 to 77 do // loop all CRC16 standards
begin
LCRC := THashFactory.TChecksum.TCRC.CreateCRC(TCRCStandard(I));
CRC := (LCRC as ICRC).ComputeBytes(Bytes).GetBytes;
Writeln(TConverters.ConvertBytesToHexString(CRC, false) + ' ' +
LCRC.Name);
CRC := [];
LCRC := nil;
end;
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Note, I only swapped out your helper functions for mine as I do not have access to yours.
output from above is attached below
540D TCRC-16/AUG-CCITT
8FFD TCRC-16/BUYPASS
AA9F TCRC-16/CCITT-FALSE
A7CB TCRC-16/CDMA2000
E13A TCRC-16/CMS
696A TCRC-16/DDS-110
712C TCRC-16/DECT-R
712D TCRC-16/DECT-X
B27E TCRC-16/DNP
D177 TCRC-16/EN13757
5560 TCRC-16/GENIBUS
D3A1 TCRC-16/GSM
92F8 TCRC-16/LJ1200
B33E TCRC-16/MAXIM
6254 TCRC-16/MCRF4XX
5BC3 TCRC-16/OPENSAFETY-A
8860 TCRC-16/OPENSAFETY-B
51DA TCRC-16/PROFIBUS
038D TCRC-16/RIELLO
67EF TCRC-16/T10-DIF
5BA8 TCRC-16/TELEDISK
ABBF TCRC-16/TMS37157
5048 TCRC-16/USB
C988 TCRC-A
E135 TKERMIT
AFB7 TMODBUS
9DAB TX-25
2C5E TXMODEM
2CB1 TCRC-16/NRSC-5
Are you certain your ToHex
extension does not cache the result of it's previous computation to a global variable?
I confirm that the issue does not exist on console application. You are correct that it is my helper function TBytes.ToHex() causing problems. Sorry about the noise.
BTW, I still cannot get any F39A as a result. I doubt it but, is there any CRC 16 standard which HashLib4Pascal does not support?
So HashLib4Pascal supports all standard
CRC's except CRC 82.
That been said, if the data you are hashing is the correct one expected to give you that checksum then there is one other suspicion, that the specified CRC is a custom one.
For you to test out that theory, you need some details about the CRC you are trying to compute such as
Do you by chance have the polynomial of the crc you wish to compute?
Unfortunately, not. Only information I have is I need to calculate CRC of 2 bytes. I have no expectations at all but I am expecting an answer for tomorrow.
Given I have a custom CRC at hand and all these details about it, can I use HashLib4Pascal as it is to calculate that custom CRC, or there is still need for implementation?
Thank you.
You can calculate a custom CRC using HashLib4Pascal but you need those 5 details I requested above as those are the building blocks for any CRC implementation.
Here are the details I found
Algorithm is called as CRC-16/ARC by this web site. https://crccalc.com
Now, I am just not sure how I should use these values for custom CRC calculation.
BTW, input hex data is 544553543030303032363036FF8A7507DF820803000001
Thanks & Regards, Ertan
first of all, the CRC you are looking for TCRCStandard.ARC
already exists so no need to do any custom calculations.
your original code had a couple of issues though.
CRC ARC
in your loop, you were meant to start the loop from 48
.You are right on your listed issues.
I didn't know that CRC ARC
belongs to CRC16 group and thought the naming convention starts with CRC16 for all in the CTRL+SPACE list within Delphi IDE.
Just by looking at the list closely and one can see sequential numbers skip 48. I can see it now.
Seller of the device I am working provided absolutely no details as to CRC. I just know it is 2 bytes and its position in the data packet. I was doing trial and error until I actually find input data and the standard.
As always, thank you for your support.
Glad I was able to help.
Hello,
First of all thank you again for making this library MIT license and thank you to all who supported that.
I am provided a documentation for TLV communication with a device. There is no specific standard clearly indicated in the document. It says "CRC calculation". I assumed that is CRC16 since size in communication is 2 bytes only.
There is an example application provided. No SDK or code examples from the seller of the device, I am alone to solve this one.
Below is the data sent to the device by sample application. 02 at the beginning and 03 at the end should not be included in CRC calculation and F39A is the calculated CRC. 02 0017544553543030303032363036FF8A7507DF820803000001 F39A 03
I have following code that tries to calculate all supported CRC16 values for 0017544553543030303032363036FF8A7507DF820803000001 value
My problem is output always adds to previous result as below
I just cannot be sure that the calculation actually works fresh for each loop.
How can I clear buffer/data in the loop?
Thanks & Regards, Ertan