-> Hier kostenlos registrieren
Hallo zusammen,
ich möchte im TIA Portal Safety eine CRC16 Checksumme Berechnen.
Gibt es dafür schon fertige Bausteine?
Im Anhang (PDF) ist mein Beispiel für eine CRC Berechnung in FUP, das Problem wo ich noch habe ist das man keinen Rücksprung in Rücksprung haben darf!
Folgenden Code möchte ich in FUP Safety Programmieren
ich möchte im TIA Portal Safety eine CRC16 Checksumme Berechnen.
Gibt es dafür schon fertige Bausteine?
Im Anhang (PDF) ist mein Beispiel für eine CRC Berechnung in FUP, das Problem wo ich noch habe ist das man keinen Rücksprung in Rücksprung haben darf!
Folgenden Code möchte ich in FUP Safety Programmieren
Code:
REGION Initialization and input data processing
// Defining initial value for algorithm
#tempCRC := #initValue;
// Input array size calculation
#tempLowerLimit := LOWER_BOUND(ARR := #array, DIM := #ARRAY_FIRST_DIMENSION);
#tempUpperLimit := UPPER_BOUND(ARR := #array, DIM := #ARRAY_FIRST_DIMENSION);
// check paramter `noOfELements`, if gretaer than zero check if fits to array size
IF #noOfElements > 0 THEN
IF #noOfElements > (#tempUpperLimit - #tempLowerLimit + 1) THEN
#status := #ERR_NO_OF_ELEMENTS;
#error := TRUE;
ENO := FALSE;
#LGF_CalcCRC16 := #tempCRC;
RETURN;
ELSE
#tempUpperLimit := #tempLowerLimit + #noOfElements - 1;
END_IF;
END_IF;
END_REGION
REGION CRC calculation
FOR #tempIndexArray := #tempLowerLimit TO #tempUpperLimit DO
// Perform division using XOR function for appropriate word in array (with shift byte into MSB of 16bit CRC)
#tempCRC := #tempCRC XOR SHL(IN := BYTE_TO_WORD(#array[#tempIndexArray]), N := #SHIFT_ONE_BYTE);
FOR #tempIndexCRC := #CRC_LOOP_LOWER_LIMIT TO #CRC_LOOP_UPPER_LIMIT DO
// Check if MSB is set
IF #tempCRC.%X15 THEN
// Shift left and perform division by mask polynomial using XOR function
#tempCRC := SHL(IN := #tempCRC, N := #SHIFT_ONE_BIT) XOR #mask;
ELSE
// Shift left without division
#tempCRC := SHL(IN := #tempCRC, N := #SHIFT_ONE_BIT);
END_IF;
END_FOR;
END_FOR;
END_REGION
REGION Outputs assignment
#LGF_CalcCRC16 := #tempCRC;
#status := #STATUS_NO_ERROR;
#error := FALSE;
ENO := TRUE;
END_REGION