Added more components
This commit is contained in:
106
PLC/POUs/Components/Utilities/FB_AlarmMessage.TcPOU
Normal file
106
PLC/POUs/Components/Utilities/FB_AlarmMessage.TcPOU
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_AlarmMessage" Id="{4e628f13-10b9-47d9-8d26-ceb4bcb9bf43}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION_BLOCK FINAL FB_AlarmMessage
|
||||
VAR_INPUT
|
||||
xActive : BOOL;
|
||||
xRelease : BOOL;
|
||||
xAcknowledge : BOOL;
|
||||
timOnDelay : TIME := T#0S;
|
||||
timOffDelay : TIME := T#0S;
|
||||
xInUnitTestMode : BOOL := FALSE;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
END_VAR
|
||||
VAR
|
||||
_fbReleaseAlarm : FB_ReleaseSignal;
|
||||
_fbAlarmMessage : FB_TcAlarm;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Filter alarm signal
|
||||
_fbReleaseAlarm(
|
||||
xSignal:= xActive,
|
||||
xRelease:= xRelease,
|
||||
timOnDelay:= timOnDelay,
|
||||
timOffDelay:= timOffDelay);
|
||||
|
||||
// Raise alarm
|
||||
IF _fbReleaseAlarm.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmMessage.bRaised) THEN
|
||||
_fbAlarmMessage.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF ((NOT _fbReleaseAlarm.xReleaseSignal) OR (NOT xRelease)) AND (_fbAlarmMessage.bRaised) THEN
|
||||
_fbAlarmMessage.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF _fbAlarmMessage.eConfirmationState = TcEventConfirmationState.WaitForConfirmation AND (xAcknowledge OR (NOT xRelease)) THEN
|
||||
_fbAlarmMessage.Confirm(0);
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
<Property Name="Active" Id="{4e7fa79e-e44f-42ff-ab45-0e14a9921a12}">
|
||||
<Declaration><![CDATA[PROPERTY Active : BOOL]]></Declaration>
|
||||
<Get Name="Get" Id="{70df159d-fc9d-44c5-ae42-7d731a5dae12}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[Active := _fbAlarmMessage.bActive;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
</Property>
|
||||
<Property Name="Arguments" Id="{f40c819a-ad71-4e81-830e-67d02b4e9e2f}">
|
||||
<Declaration><![CDATA[PROPERTY PUBLIC Arguments : I_TcArguments]]></Declaration>
|
||||
<Get Name="Get" Id="{c1b8ca1b-cb6c-4841-8282-61423914cb4e}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[Arguments := _fbAlarmMessage.ipArguments;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
</Property>
|
||||
<Method Name="FB_init" Id="{59e606ca-879e-463e-9089-6aa9e1011af6}">
|
||||
<Declaration><![CDATA[//FB_Init ist immer implizit verfügbar und wird primär für die Initialisierung verwendet.
|
||||
//Der Rückgabewert wird nicht ausgewertet. Für gezielte Einflussnahme können Sie
|
||||
//die Methoden explizit deklarieren und darin mit dem Standard-Initialisierungscode
|
||||
//zusätzlichen Code bereitstellen. Sie können den Rückgabewert auswerten.
|
||||
METHOD FB_Init: BOOL
|
||||
VAR_INPUT
|
||||
bInitRetains: BOOL; // TRUE: Die Retain-Variablen werden initialisiert (Reset warm / Reset kalt)
|
||||
bInCopyCode: BOOL; // TRUE: Die Instanz wird danach in den Kopiercode kopiert (Online-Change)
|
||||
|
||||
stEventEntry : TcEventEntry;
|
||||
xWithConfirmation : BOOL;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Create alarm
|
||||
_fbAlarmMessage.CreateEx(stEventEntry := stEventEntry, bWithConfirmation := xWithConfirmation);]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Property Name="Raised" Id="{6c8f10b8-0c5e-4665-b985-30ac574d84e9}">
|
||||
<Declaration><![CDATA[PROPERTY Raised : BOOL]]></Declaration>
|
||||
<Get Name="Get" Id="{0ef44270-1843-4da0-932f-31f831130a1d}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[Raised := _fbAlarmMessage.bRaised;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
</Property>
|
||||
<Property Name="Triggered" Id="{84255a39-f5bd-41ec-9bb9-56c375350a5b}">
|
||||
<Declaration><![CDATA[PROPERTY Triggered : BOOL]]></Declaration>
|
||||
<Get Name="Get" Id="{1df049dd-1509-4300-b01e-e32eececdb86}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[Triggered := _fbReleaseAlarm.xReleaseSignal;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
</Property>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
35
PLC/POUs/Components/Utilities/FB_Blinker.TcPOU
Normal file
35
PLC/POUs/Components/Utilities/FB_Blinker.TcPOU
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_Blinker" Id="{84dea953-e299-4743-83b2-332727c2009e}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[{attribute 'analysis' := '-56, -37'}
|
||||
FUNCTION_BLOCK FINAL FB_Blinker
|
||||
VAR_INPUT
|
||||
rFrequency : REAL;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
xOut : BOOL;
|
||||
END_VAR
|
||||
VAR
|
||||
_fbTON1 : TON;
|
||||
_fbTON2 : TON;
|
||||
|
||||
_timTime : TIME;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Calculate wait time
|
||||
IF rFrequency = 0.0 THEN
|
||||
rFrequency := 1.0;
|
||||
END_IF
|
||||
|
||||
_timTime := REAL_TO_TIME((1.0/rFrequency)*0.5*1000.0);
|
||||
|
||||
// Blinker base
|
||||
_fbTON1(IN := NOT _fbTON2.Q, PT := _timTime);
|
||||
_fbTON2(IN := _fbTON1.Q, PT := _timTime);
|
||||
|
||||
// Output
|
||||
xOut := _fbTON1.Q;]]></ST>
|
||||
</Implementation>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
132
PLC/POUs/Components/Utilities/FB_RampGenerator.TcPOU
Normal file
132
PLC/POUs/Components/Utilities/FB_RampGenerator.TcPOU
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_RampGenerator" Id="{eab75824-fb3c-460a-af65-da2b006c5dc1}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[// Must only be called once per cycle!
|
||||
// Otherwise the Interpolation is wrong
|
||||
{attribute 'analysis' := '-56'}
|
||||
FUNCTION_BLOCK FB_RampGenerator
|
||||
VAR_INPUT
|
||||
// Current target value
|
||||
rTarget : REAL;
|
||||
|
||||
// Minimum target value
|
||||
rTargetMin : REAL;
|
||||
|
||||
// Maximum target value
|
||||
rTargetMax : REAL;
|
||||
|
||||
// Ramp up time (min to max)
|
||||
timRampUp : TIME;
|
||||
|
||||
// Ramp down time (max to min)
|
||||
timRampDown : TIME;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
rSetpoint : REAL := 0;
|
||||
|
||||
// Indicates that the target value has been reached
|
||||
xInTarget : BOOL;
|
||||
END_VAR
|
||||
VAR
|
||||
// Cycle time in ms
|
||||
_rCycleTime : REAL;
|
||||
|
||||
// Ramp up speed per cycle
|
||||
// Units per ms
|
||||
_rRampUpSpeed : REAL;
|
||||
|
||||
// Ramp down speed per cycle
|
||||
// Units per ms
|
||||
_rRampDownSpeed : REAL;
|
||||
|
||||
// Distance left to go
|
||||
_rDistanceToGo : REAL;
|
||||
|
||||
// First cycle
|
||||
_xFirstCycle : BOOL := TRUE;
|
||||
|
||||
_fbGetCurTaskIdx : GETCURTASKINDEX;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Get task cycle time during first cycle
|
||||
// Does not work in FB_init and also not with {attribute 'call_after_init'}
|
||||
IF _xFirstCycle THEN
|
||||
_xFirstCycle := FALSE;
|
||||
// Get current task cycle time
|
||||
_fbGetCurTaskIdx();
|
||||
// Convert 100ns to 1ms
|
||||
_rCycleTime := UDINT_TO_REAL(TwinCAT_SystemInfoVarList._TASKInfo[_fbGetCurTaskIdx.index].CycleTime) * 10E-5;
|
||||
END_IF
|
||||
|
||||
// Clamp setpoint to min max values
|
||||
{analysis -37}
|
||||
rTarget := MAX(rTarget, rTargetMin);
|
||||
rTarget := MIN(rTarget, rTargetMax);
|
||||
{analysis +37}
|
||||
|
||||
// Calculate change rates
|
||||
// TIME datatype is handled internally like a UDINT (32-bit). This leads to a resolution in milliseconds.
|
||||
// [_rRampUpSpeed] = units per cycle
|
||||
IF timRampUp <> T#0S THEN
|
||||
_rRampUpSpeed := (rTargetMax - rTargetMin) * (_rCycleTime / TIME_TO_REAL(timRampUp));
|
||||
ELSE
|
||||
_rRampUpSpeed := rTargetMax;
|
||||
END_IF
|
||||
IF timRampDown <> T#0S THEN
|
||||
_rRampDownSpeed := -(rTargetMax - rTargetMin) * (_rCycleTime / TIME_TO_REAL(timRampDown));
|
||||
ELSE
|
||||
_rRampDownSpeed := -rTargetMax;
|
||||
END_IF
|
||||
|
||||
|
||||
// Calculate distance left to go
|
||||
_rDistanceToGo := rTarget - rSetpoint;
|
||||
|
||||
// Calculate new setpoint
|
||||
IF (_rDistanceToGo > 0.0) THEN
|
||||
IF (_rDistanceToGo > _rRampUpSpeed) THEN
|
||||
rSetpoint := rSetpoint + _rRampUpSpeed;
|
||||
ELSE
|
||||
rSetpoint := rTarget;
|
||||
END_IF
|
||||
ELSIF (_rDistanceToGo < 0.0) THEN
|
||||
IF (_rDistanceToGo < _rRampDownSpeed) THEN
|
||||
rSetpoint := rSetpoint + _rRampDownSpeed;
|
||||
ELSE
|
||||
rSetpoint := rTarget;
|
||||
END_IF
|
||||
ELSE
|
||||
rSetpoint := rTarget;
|
||||
END_IF
|
||||
|
||||
// Check if we are in range of target range
|
||||
IF ABS(rSetpoint-rTarget) <= 0.001 THEN
|
||||
xInTarget := TRUE;
|
||||
ELSE
|
||||
xInTarget := FALSE;
|
||||
END_IF ]]></ST>
|
||||
</Implementation>
|
||||
<Property Name="CycleTime" Id="{12c00f80-a9cf-4d1b-ac68-3c3e59228015}">
|
||||
<Declaration><![CDATA[PROPERTY CycleTime : REAL]]></Declaration>
|
||||
<Get Name="Get" Id="{06853e5f-48e3-4643-ae4f-e23a07d71695}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[CycleTime := _rCycleTime;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
</Property>
|
||||
<Method Name="SetStart" Id="{06f2b416-7cfb-4f46-94e3-4002d92fc703}">
|
||||
<Declaration><![CDATA[METHOD SetStart
|
||||
VAR_INPUT
|
||||
rStartpoint : REAL;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[rSetpoint := rStartpoint;]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
44
PLC/POUs/Components/Utilities/FB_ReleaseSignal.TcPOU
Normal file
44
PLC/POUs/Components/Utilities/FB_ReleaseSignal.TcPOU
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_ReleaseSignal" Id="{95131698-43c9-4438-8f9f-0d910656ef66}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION_BLOCK FINAL FB_ReleaseSignal
|
||||
VAR_INPUT
|
||||
// Signal to filter
|
||||
xSignal : BOOL := FALSE;
|
||||
|
||||
// Release signal output
|
||||
xRelease : BOOL := TRUE;
|
||||
|
||||
// Time for xSignal to be true before setting xReleaseSignal to true
|
||||
timOnDelay : TIME := T#0MS;
|
||||
|
||||
// Time for xSignal to be false before setting xReleaseSignal to false
|
||||
timOffDelay : TIME := T#0MS;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
// Filtered signal
|
||||
xReleaseSignal : BOOL;
|
||||
END_VAR
|
||||
VAR
|
||||
// Timer for on filtering
|
||||
_fbOnDelayTimer : TON;
|
||||
|
||||
// Timer for off filtering
|
||||
_fbOffDelayTimer : TON;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Delay on signal if signal is released
|
||||
_fbOnDelayTimer(IN:= xSignal AND xRelease, PT:= timOnDelay);
|
||||
IF _fbOnDelayTimer.Q THEN
|
||||
xReleaseSignal := TRUE;
|
||||
END_IF
|
||||
|
||||
// Delay off signal, return false even if off timer is still active
|
||||
_fbOffDelayTimer(IN:= (NOT xSignal), PT:= timOffDelay);
|
||||
IF _fbOffDelayTimer.Q OR (NOT xRelease) THEN
|
||||
xReleaseSignal := FALSE;
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
34
PLC/POUs/Components/Utilities/FC_HashFNV1a_32Bit.TcPOU
Normal file
34
PLC/POUs/Components/Utilities/FC_HashFNV1a_32Bit.TcPOU
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FC_HashFNV1a_32Bit" Id="{59a77c23-437d-4f1e-ae71-d5303ce54b27}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION FC_HashFNV1a_32Bit : UDINT
|
||||
VAR_INPUT
|
||||
psKey : POINTER TO STRING;
|
||||
END_VAR
|
||||
VAR
|
||||
// FNV-1a Hash value, seeded with starting value
|
||||
_udiHash : UDINT := 16#811C9DC5;
|
||||
|
||||
_uiCounter : UINT;
|
||||
END_VAR
|
||||
|
||||
VAR CONSTANT
|
||||
// FNV-1a prime number for a 32bit hash
|
||||
udiPrime : UDINT := 16#01000193;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Version 1.2
|
||||
IF psKey = 0 THEN
|
||||
FC_HashFNV1a_32Bit := 0;
|
||||
RETURN;
|
||||
END_IF
|
||||
WHILE psKey^[_uiCounter] <> 0 DO
|
||||
_udiHash := (_udiHash XOR BYTE_TO_UDINT(psKey^[_uiCounter])) * udiPrime;
|
||||
_uiCounter := _uiCounter + 1;
|
||||
END_WHILE
|
||||
|
||||
// Return calculated Hash
|
||||
FC_HashFNV1a_32Bit := _udiHash;]]></ST>
|
||||
</Implementation>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
Reference in New Issue
Block a user