I need to verify Telegram which i need to send through TCPIP. I need to calculate Checksum with XOR. The length is 1 Byte. My input is hex string and i need output also as Hex string.
Does anybody know how to do it? I tried to write smt but unsuccessfully.
I am checking chekcum at https://www.scadacore.com/tools/program ... alculator/ and first output is smt i need.
Just in case you missed it, TCP/IP already have built in CRC check, so your received data can't be corrupted (if so, the network card will itself ask for the packet again, and will not provide you data).
Edit : Also CRC8 and CRC16 are different.
You could use oscat basic library for computing/checking CRC8
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmm actually i need to calculate checksum to send it at the end of telegram to get the response. So my Telegram is assembled from: header, data length, data and checksum of data. data is representing command. I have two possibilities: to send ASCII telegram where i can write in ASCII or hex or i send binary telegram in hexadecimal code. received answer is in hexadecimal code so i thought ok lets have all in hex. i use twincat and have beckhoffs PLC and The checksum of the TCIP telegram is not transferred into TwinCAT. Because of this also Oscar lib doesn't help me. Or is there possibility to open it in TwinCAT?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FUNCTIONCRC_GEN : DWORDVAR_INPUT
  PT : POINTERTOARRAY[0..32000] OFBYTE;
  SIZE : INT;
  PL : INT;
  PN : DWORD;
  INIT : DWORD;
  REV_IN : BOOL;
  REV_OUT : BOOL;
  XOR_OUT : DWORD;END_VARVAR
  pos : INT;
  shift : INT;
  dx: BYTE;
  bits: INT;END_VAR(*version2.0  16.Jan. 2011programmer   hugotestedby    tobiasCRC_GENgeneratesaCRCchecksumfromablockofdataandreturns thechecksuminaDWORDtobeconnectedtothedatafortransmission.
theCRCPolynomisspecifiedwiththeconfigvariablePNandthelengthofthePolynomisspecifiedbyPLAPolynomx4+X+1isrepresentedby0011withlength4, thehighestorderbitisnotspecifiedatall..
Theinputdataisanarrayofbyteofanysize, thefunctioniscalledbyCRC_GEN(ADR(array),SIZEOF(array), ....).
*)(*alignpolygon*)shift :=32-PL;PN :=SHL(PN, shift);(*loadfirst4bytesintoregisterminimummessagesizeis4bytes
  forsmallermessagesfillwith0#satthebeginning*)FORpos :=0TO3DO
  IFREV_INTHENCRC_GEN :=SHL(CRC_GEN, 8)ORREVERSE(PT^[pos]); ELSE CRC_GEN := SHL(CRC_GEN, 8) OR PT^[pos]; END_IF;END_FOR;pos :=4;(*xorwithinitvalue*)CRC_GEN :=CRC_GENXORSHL(init, shift);(*calculateCRCforeachbyte*)WHILEpos<sizeDO
  IFREV_INTHENDX :=REVERSE(PT^[pos]); ELSE DX := PT^[pos]; END_IF;
  pos :=pos+1;
  (*crccalculationforonebyte*)
  FORbits :=0TO7DO
    IFCRC_GEN.31THEN
      CRC_GEN :=(SHL(CRC_GEN, 1)ORBOOL_TO_DWORD(DX.7))XORPN;
    ELSE
      CRC_GEN :=SHL(CRC_GEN, 1)ORBOOL_TO_DWORD(DX.7);
    END_IF;
    dx :=SHL(dx, 1);
  END_FOR;END_WHILE;(*allbytesareprocessed, needtofinishtheregisters32bits*)FORbits :=0TO31DO
  IFCRC_GEN.31THEN
    CRC_GEN :=(SHL(CRC_GEN, 1)ORBOOL_TO_DWORD(DX.7))XORPN;
  ELSE
    CRC_GEN :=SHL(CRC_GEN, 1)ORBOOL_TO_DWORD(DX.7);
  END_IF;END_FOR;(*finalXOR*)CRC_GEN :=SHR(CRC_GEN, shift)XORXOR_OUT;(*reversethecrc_outputifnecessary*)IFREV_OUTTHENCRC_GEN :=REFLECT(CRC_GEN, PL); END_IF;(*typicalcrcpolynomsCRC-4-ITU       x4+x+1           (ITUG.704, p. 12)   0x3or0xC(0x9)CRC-5-ITU       x5+x4+x2+1       (ITUG.704, p. 9)   0x15or0x15(0x0B)BluetoothCRC-5-USB       x5+x2+1         (use: USBtokenpackets)   0x05or0x14(0x9)CRC-6-ITU       x6+x+1           (ITUG.704, p. 3)   0x03or0x30(0x21)CRC-7         x7+x3+1         (use: telecomsystems, MMC)   0x09or0x48(0x11)CRC-8-ATM       x8+x2+x+1         (use: ATMHEC)   0x07or0xE0(0xC1)CRC-8-CCITT     x8+x7+x3+x2+1     (use: 1-Wirebus)   0x8Dor0xB1(0x63)CRC-8-Dallas/Maxim   x8+x5+x4+1       (use: 1-Wirebus)   0x31or0x8C(0x19)CRC-8         x8+x7+x6+x4+x2+1   0xD5or0xAB(0x57)CRC-8-SAEJ1850   x8+x4+x3+x2+1     0x1Dor0xB8CRC-10         x10+x9+x5+x4+x+1   0x233or0x331(0x263)CRC-12         x12+x11+x3+x2+x+1(use: telecomsystems)   0x80For0xF01(0xE03)CRC-15-CAN       x15+x14+x10+x8+x7+x4+x3+1   0x4599or0x4CD1(0x19A3)CRC-16-Fletcher   NotaCRC; see Fletcher's checksum   Used in Adler-32 A & B CRCsCRC-16-CCITT   x16+x12+x5+1(XMODEM,X.25, V.41, Bluetooth, PPP, IrDA; known as "CRC-CCITT")   0x1021 or 0x8408 (0x0811)CRC-16-IBM   x16+x15+x2+1(USB, manyothers; also known as "CRC-16")   0x8005 or 0xA001 (0x4003)CRC-24-Radix-64   x24+x23+x18+x17+x14+x11+x10+x7+x6+x5+x4+x3+x+1   0x864CFBor0xDF3261(0xBE64C3)CRC-32-Adler   NotaCRC; see Adler-32   See Adler-32CRC-32-MPEG2   x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1   0x04C11DB7or0xEDB88320(0xDB710641)AlsousedinIEEE802.3CRC-32-IEEE802.3   x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1(V.42)   0x04C11DB7or0xEDB88320(0xDB710641)CRC-32C(Castagnoli)   x32+x28+x27+x26+x25+x23+x22+x20+x19+x18+x14+x13+x11+x10+x9+x8+x6+1   0x1EDC6F41or0x82F63B78(0x05EC76F1)CRC-64-ISO   x64+x4+x3+x+1(use: ISO3309)   0x000000000000001Bor0xD800000000000000(0xB000000000000001)CRC-64-ECMA-182   x64+x62+x57+x55+x54+x53+x52+x47+x46+x45+x40+x39+x38+x37+x35+x33+x32+x31+x29+x27+x24+x23+x22+x21+x19+x17+x13+x12+x10+x9+x7+x4+x+1(asdescribedinECMA-182p.63)   0x42F0E1EBA9EA3693or0xC96C5795D7870F42(0x92D8AF2BAF0E1E85)*)(*revisionhistoryhm  9.6.2007    rev1.0   Â
  originalversionhm  11.9.2007    rev1.1
  deletedunusedvariableihm  9. oct2007   rev1.2
  addedinitcodeforcrcandxor_out
  addedrefelctinandreflect_out(rev_inundRev_out)hm  2. jan2008  rev1.3
  smallchangesforperformanceimprovementshm  16. mar. 2008  rev1.4
  changedtypeofinputsizetouinthm  10. mar. 2009  rev1.5
  removednestedcommentshm  16. jan. 2011  rev2.0
  newversion*)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I need to verify Telegram which i need to send through TCPIP. I need to calculate Checksum with XOR. The length is 1 Byte. My input is hex string and i need output also as Hex string.
Does anybody know how to do it? I tried to write smt but unsuccessfully.
I am checking chekcum at https://www.scadacore.com/tools/program ... alculator/ and first output is smt i need.
i tried to help myself with https://forum-de.codesys.com/viewtopic.php?t=456#p1679:
Here is ok 16bit and WORD so i need to change that bu i dont understand statement inside of IF condition.
So if anybody knows how to calculate CRC8 with Hex string input would really appreciate for help.
Just in case you missed it, TCP/IP already have built in CRC check, so your received data can't be corrupted (if so, the network card will itself ask for the packet again, and will not provide you data).
Edit : Also CRC8 and CRC16 are different.
You could use oscat basic library for computing/checking CRC8
Hello,
Hmm actually i need to calculate checksum to send it at the end of telegram to get the response. So my Telegram is assembled from: header, data length, data and checksum of data. data is representing command. I have two possibilities: to send ASCII telegram where i can write in ASCII or hex or i send binary telegram in hexadecimal code. received answer is in hexadecimal code so i thought ok lets have all in hex. i use twincat and have beckhoffs PLC and The checksum of the TCIP telegram is not transferred into TwinCAT. Because of this also Oscar lib doesn't help me. Or is there possibility to open it in TwinCAT?
oscat CRC_GEN code:
Thank you!