Small refactoring
- Moved fb's around - Removed libraries from repo
This commit is contained in:
631
PLC/POUs/Analog/FB_AnalogInput.TcPOU
Normal file
631
PLC/POUs/Analog/FB_AnalogInput.TcPOU
Normal file
@@ -0,0 +1,631 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_AnalogInput" Id="{532e1013-5a2e-43c7-8863-3ad112d7d7e8}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION_BLOCK FB_AnalogInput
|
||||
VAR_INPUT
|
||||
// Analog input value
|
||||
iAnalogValue AT %I* : INT;
|
||||
|
||||
// Card has detected an open circuit
|
||||
xUnderrange AT%I* : BOOL;
|
||||
|
||||
// Input is overloaded
|
||||
xOverrange AT %I* : BOOL;
|
||||
|
||||
// Input card has error
|
||||
// EL30xx also sets this if an underrange or overrange error is present
|
||||
xErrorCard AT %I* : BOOL;
|
||||
|
||||
// IO config data
|
||||
stAnalogIOConfig : ST_ANALOG_IO_CONFIG;
|
||||
|
||||
// Error and warning config data
|
||||
stAnalogEWConfig : ST_ANALOG_EW_CONFIG;
|
||||
|
||||
// Global switch to dissable all errors
|
||||
xReleaseErrors : BOOL := TRUE;
|
||||
|
||||
// Enables or dissables errors from min max values
|
||||
xReleaseLimitErrors : BOOL := FALSE;
|
||||
|
||||
// Enables or dissables hardware errors
|
||||
xReleaseHardwareErrors : BOOL := TRUE;
|
||||
|
||||
// Input to confirm all errors
|
||||
xConfirmAlarms : BOOL;
|
||||
|
||||
// Input to tell the fb thats ist used inside a unit test
|
||||
// Fb will not throw error messages
|
||||
{attribute 'hide'}
|
||||
xInUnitTestMode : BOOL := FALSE;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
// Scaled output value
|
||||
rScaledValue : REAL;
|
||||
|
||||
// Error in function block
|
||||
xError : BOOL;
|
||||
|
||||
// Warning active
|
||||
xWarning : BOOL;
|
||||
|
||||
// Low level error
|
||||
xErrorLow : BOOL;
|
||||
|
||||
// Low level warning
|
||||
xWarningLow : BOOL;
|
||||
|
||||
// High level warning
|
||||
xWarningHigh : BOOL;
|
||||
|
||||
//High level error
|
||||
xErrorHigh : BOOL;
|
||||
END_VAR
|
||||
VAR
|
||||
// Scaling factor for conversion
|
||||
_rConversionFactor : REAL;
|
||||
|
||||
// Base offset for scaling factor
|
||||
_rBaseOffset : REAL;
|
||||
|
||||
// Min warning level
|
||||
_rMinWarningLevel : REAL;
|
||||
|
||||
// Max warning level
|
||||
_rMaxWarningLevel : REAL;
|
||||
|
||||
// Min error level
|
||||
_rMinErrorLevel : REAL;
|
||||
|
||||
// Max error level
|
||||
_rMaxErrorLevel : REAL;
|
||||
|
||||
// Scaling config error
|
||||
_xConfigError : BOOL := FALSE;
|
||||
|
||||
// Limits config error
|
||||
_xEWConfigError : BOOL := FALSE;
|
||||
|
||||
// Delayed Signal warning low
|
||||
_fbSignalDelayWarningLow : FB_ReleaseSignal;
|
||||
|
||||
// Delayed Signal warning high
|
||||
_fbSignalDelayWarningHigh : FB_ReleaseSignal;
|
||||
|
||||
// Delayed Signal error low
|
||||
_fbSignalDelayErrorLow : FB_ReleaseSignal;
|
||||
|
||||
// Delayed signal error high
|
||||
_fbSignalDelayErrorHigh : FB_ReleaseSignal;
|
||||
|
||||
// Delayed signal for underrange error
|
||||
_fbSignalDelayUnderrangeError : FB_ReleaseSignal;
|
||||
|
||||
// Delayed signal for overload error
|
||||
_fbSignalDelayOverloadError : FB_ReleaseSignal;
|
||||
|
||||
// Delayed signal for card error
|
||||
_fbSignalDelayCardError : FB_ReleaseSignal;
|
||||
|
||||
// Helper variables used in reset error flag
|
||||
_xAlarmsActive : BOOL;
|
||||
_xInputErrorsActive : BOOL;
|
||||
|
||||
// Max process value
|
||||
_iAIMax : INT;
|
||||
|
||||
// Min process value
|
||||
_iAIMin : INT;
|
||||
|
||||
// Clamped analog value
|
||||
_iClampedAnalogValue : INT;
|
||||
|
||||
// Internal scaled value
|
||||
_rScaledValue : REAL;
|
||||
|
||||
// Name of the function block
|
||||
_sName : STRING;
|
||||
|
||||
// Internal warning flags
|
||||
_xWarningLow : BOOL;
|
||||
_xWarningHigh : BOOL;
|
||||
_xWarning : BOOL;
|
||||
|
||||
// Internal error flag
|
||||
_xErrorLow : BOOL;
|
||||
_xErrorHigh : BOOL;
|
||||
_xError : BOOL;
|
||||
|
||||
// Alarm handlers
|
||||
_fbAlarmCardError : FB_TcAlarm;
|
||||
_fbAlarmUnderrange : FB_TcAlarm;
|
||||
_fbAlarmOverload : FB_TcAlarm;
|
||||
_fbAlarmConfigError : FB_TcAlarm;
|
||||
|
||||
_fbAlarmErrorLow : FB_TcAlarm;
|
||||
_fbAlarmWarningLow : FB_TcAlarm;
|
||||
_fbAlarmWarningHigh : FB_TcAlarm;
|
||||
_fbAlarmErrorHigh : FB_TcAlarm;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// =========
|
||||
// Prechecks
|
||||
// =========
|
||||
|
||||
// Calculate scaling factors,
|
||||
// scaling will be zero in case
|
||||
// of invalid scaling parameters.
|
||||
// Also checks if reference to config data is valid.
|
||||
CalcScalingFactors();
|
||||
|
||||
// Check error and warning levels config
|
||||
// Will later raise alarms if config is wrong
|
||||
CheckEWLevels();
|
||||
|
||||
|
||||
// ===========================
|
||||
// Config error alarm handling
|
||||
// ===========================
|
||||
|
||||
IF xReleaseErrors AND (_xConfigError OR (_xEWConfigError AND xReleaseLimitErrors)) THEN
|
||||
// Latch error
|
||||
_xError := TRUE;
|
||||
|
||||
// Raise alarm
|
||||
IF (NOT xInUnitTestMode) AND (NOT _fbAlarmConfigError.bRaised) THEN
|
||||
_fbAlarmConfigError.Raise(0);
|
||||
END_IF
|
||||
END_IF
|
||||
|
||||
// Clear alarm and confirm
|
||||
// Auto confirm because error can only be cleared
|
||||
// throught user action
|
||||
IF (NOT _xConfigError) AND (NOT _xEWConfigError) AND _fbAlarmConfigError.bRaised THEN
|
||||
_fbAlarmConfigError.Clear(0, TRUE);
|
||||
END_IF
|
||||
|
||||
|
||||
// ========================
|
||||
// Analog value calculation
|
||||
// ========================
|
||||
|
||||
// Clamp analogue input levels
|
||||
_iClampedAnalogValue := MAX(_iAIMin, iAnalogValue);
|
||||
_iClampedAnalogValue := MIN(_iAIMax, _iClampedAnalogValue);
|
||||
|
||||
// Calc scaled value
|
||||
_rScaledValue := _iClampedAnalogValue * _rConversionFactor + _rBaseOffset;
|
||||
|
||||
|
||||
// =========================
|
||||
// Underrange alarm handling
|
||||
// =========================
|
||||
|
||||
// Filter underrange error signal
|
||||
_fbSignalDelayUnderrangeError(
|
||||
xSignal:= xUnderrange,
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseHardwareErrors,
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOff);
|
||||
|
||||
// Latch error signal
|
||||
IF _fbSignalDelayUnderrangeError.xReleaseSignal THEN
|
||||
_xError := TRUE;
|
||||
END_IF
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayUnderrangeError.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmUnderrange.bRaised) THEN
|
||||
_fbAlarmUnderrange.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayUnderrangeError.xReleaseSignal) AND _fbAlarmUnderrange.bRaised THEN
|
||||
_fbAlarmUnderrange.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmUnderrange.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmUnderrange.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// =========================
|
||||
// Overload alarm handling
|
||||
// =========================
|
||||
|
||||
// Filter overload error signal
|
||||
_fbSignalDelayOverloadError(
|
||||
xSignal:= xOverrange,
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseHardwareErrors,
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOff);
|
||||
|
||||
// Latch error signal
|
||||
IF _fbSignalDelayOverloadError.xReleaseSignal THEN
|
||||
_xError := TRUE;
|
||||
END_IF
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayOverloadError.xReleaseSignal AND (NOT xInUnitTestMode) AND (_fbAlarmOverload.bRaised) THEN
|
||||
_fbAlarmOverload.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayOverloadError.xReleaseSignal) AND _fbAlarmOverload.bRaised THEN
|
||||
_fbAlarmOverload.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmOverload.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmOverload.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// =========================
|
||||
// Card alarm handling
|
||||
// =========================
|
||||
|
||||
// Filter overload error signal
|
||||
// EL30xx also sets this if an underrange or overrange error is present,
|
||||
// so we filter this out
|
||||
_fbSignalDelayCardError(
|
||||
xSignal:= xErrorCard AND (NOT xUnderrange) AND (NOT xOverrange),
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseHardwareErrors,
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timHardwareSignalLevelOff);
|
||||
|
||||
// Latch error signal
|
||||
IF _fbSignalDelayCardError.xReleaseSignal THEN
|
||||
_xError := TRUE;
|
||||
END_IF
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayCardError.xReleaseSignal AND (NOT xInUnitTestMode) AND (_fbAlarmCardError.bRaised) THEN
|
||||
_fbAlarmCardError.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayCardError.xReleaseSignal) AND _fbAlarmCardError.bRaised THEN
|
||||
_fbAlarmCardError.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmCardError.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmCardError.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// ===========================
|
||||
// Error high alarm handling
|
||||
// ===========================
|
||||
|
||||
_fbSignalDelayErrorHigh(
|
||||
xSignal:= (_rScaledValue >= _rMaxErrorLevel),
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseLimitErrors AND (NOT _xEWConfigError),
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timErrorHighOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timErrorHighOff);
|
||||
|
||||
_xErrorHigh := _fbSignalDelayErrorHigh.xReleaseSignal;
|
||||
|
||||
// Latch error
|
||||
IF _xErrorHigh THEN
|
||||
_xError := TRUE;
|
||||
END_IF
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayErrorHigh.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmErrorHigh.bRaised) THEN
|
||||
_fbAlarmErrorHigh.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayErrorHigh.xReleaseSignal) AND _fbAlarmErrorHigh.bRaised THEN
|
||||
_fbAlarmErrorHigh.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmErrorHigh.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmErrorHigh.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// ===========================
|
||||
// Error low alarm handling
|
||||
// ===========================
|
||||
|
||||
_fbSignalDelayErrorLow(
|
||||
xSignal:= (_rScaledValue <= _rMinErrorLevel),
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseLimitErrors AND (NOT _xEWConfigError),
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timErrorLowOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timErrorLowOff);
|
||||
|
||||
_xErrorLow := _fbSignalDelayErrorLow.xReleaseSignal;
|
||||
|
||||
// Latch error
|
||||
IF _xErrorLow THEN
|
||||
_xError := TRUE;
|
||||
END_IF
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayErrorLow.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmErrorLow.bRaised) THEN
|
||||
_fbAlarmErrorLow.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayErrorLow.xReleaseSignal) AND _fbAlarmErrorLow.bRaised THEN
|
||||
_fbAlarmErrorLow.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmErrorLow.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmErrorLow.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// ===========================
|
||||
// Warning high alarm handling
|
||||
// ===========================
|
||||
|
||||
_fbSignalDelayWarningHigh(
|
||||
xSignal:= (_rScaledValue >= _rMaxWarningLevel),
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseLimitErrors AND (NOT _xEWConfigError),
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timWarningHighOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timWarningHighOff);
|
||||
|
||||
_xWarningHigh := _fbSignalDelayWarningHigh.xReleaseSignal;
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayWarningHigh.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmWarningHigh.bRaised) THEN
|
||||
_fbAlarmWarningHigh.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayWarningHigh.xReleaseSignal) AND _fbAlarmWarningHigh.bRaised THEN
|
||||
_fbAlarmWarningHigh.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmWarningHigh.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmWarningHigh.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// ===========================
|
||||
// Warning low alarm handling
|
||||
// ===========================
|
||||
|
||||
_fbSignalDelayWarningLow(
|
||||
xSignal:= (_rScaledValue <= _rMinWarningLevel),
|
||||
xRelease:= stAnalogIOConfig.xUsed AND xReleaseErrors AND xReleaseLimitErrors AND (NOT _xEWConfigError),
|
||||
timOnDelay:= stAnalogEWConfig.stDelays.timWarningLowOn,
|
||||
timOffDelay:= stAnalogEWConfig.stDelays.timWarningLowOff);
|
||||
|
||||
_xWarningLow := _fbSignalDelayWarningLow.xReleaseSignal;
|
||||
|
||||
// Raise alarm
|
||||
IF _fbSignalDelayWarningLow.xReleaseSignal AND (NOT xInUnitTestMode) AND (NOT _fbAlarmWarningLow.bRaised) THEN
|
||||
_fbAlarmWarningLow.Raise(0);
|
||||
END_IF
|
||||
|
||||
// Clear alarm
|
||||
IF (NOT _fbSignalDelayWarningLow.xReleaseSignal) AND _fbAlarmWarningLow.bRaised THEN
|
||||
_fbAlarmWarningLow.Clear(0, FALSE);
|
||||
END_IF
|
||||
|
||||
// Confirm alarm
|
||||
IF xConfirmAlarms AND (_fbAlarmWarningLow.eConfirmationState = TcEventConfirmationState.WaitForConfirmation) THEN
|
||||
_fbAlarmWarningLow.Confirm(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// ============
|
||||
// Warning flag
|
||||
// ============
|
||||
|
||||
_xWarning := _xWarningLow OR _xWarningHigh;
|
||||
|
||||
|
||||
// ================
|
||||
// Reset error flag
|
||||
// ================
|
||||
|
||||
_xAlarmsActive := _fbAlarmConfigError.bActive
|
||||
OR _fbAlarmUnderrange.bActive
|
||||
OR _fbAlarmOverload.bActive
|
||||
OR _fbAlarmCardError.bActive
|
||||
OR _fbAlarmErrorHigh.bActive
|
||||
OR _fbAlarmErrorLow.bActive;
|
||||
|
||||
_xInputErrorsActive := _fbSignalDelayUnderrangeError.xReleaseSignal
|
||||
OR _fbSignalDelayOverloadError.xReleaseSignal
|
||||
OR _fbSignalDelayCardError.xReleaseSignal;
|
||||
|
||||
IF xConfirmAlarms AND _xError AND (NOT _xAlarmsActive) AND (NOT _xInputErrorsActive) AND (NOT _xConfigError) THEN
|
||||
_xError := FALSE;
|
||||
END_IF
|
||||
|
||||
// Copy internal signals to outputs
|
||||
xWarningLow := _xWarningLow;
|
||||
xWarningHigh := _xWarningHigh;
|
||||
xWarning := _xWarning;
|
||||
|
||||
xErrorLow := _xErrorLow;
|
||||
xErrorHigh := _xErrorHigh;
|
||||
xError := _xError;
|
||||
|
||||
rScaledValue := _rScaledValue;]]></ST>
|
||||
</Implementation>
|
||||
<Method Name="CalcScalingFactors" Id="{e88dfbcd-1a0d-45a0-9d50-5ad8be2479c9}">
|
||||
<Declaration><![CDATA[{attribute 'analysis' := '-56'}
|
||||
METHOD PRIVATE CalcScalingFactors
|
||||
VAR
|
||||
_rNum : REAL;
|
||||
_rDenom : REAL;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// _lrConversionFactor := (lrPVMax - lrPVMin)/(udiAIMax - udiAIMin) + (rPVMin - ((lrPVMax - lrPVMin)/(udiAIMax - udiAIMin)*udiAIMin))
|
||||
// Splitted in two calculations to catch division by zero
|
||||
_rNum := (stAnalogIOConfig.rPVMax - stAnalogIOConfig.rPVMin);
|
||||
_rDenom := INT_TO_REAL(stAnalogIOConfig.iAIMax - stAnalogIOConfig.iAIMin);
|
||||
|
||||
// Do not divide by 0 or a negative number
|
||||
IF _rDenom > 0.0 THEN
|
||||
_rConversionFactor := _rNum/_rDenom;
|
||||
_rBaseOffset := stAnalogIOConfig.rPVMin - (_rConversionFactor * INT_TO_REAL(stAnalogIOConfig.iAIMin));
|
||||
_iAIMax := stAnalogIOConfig.iAIMax;
|
||||
_iAIMin := stAnalogIOConfig.iAIMin;
|
||||
_xConfigError := FALSE;
|
||||
ELSE
|
||||
// Division by zero happened
|
||||
// Or denom was negative
|
||||
// Set scaling to zero
|
||||
_rConversionFactor := 0.0;
|
||||
_rBaseOffset := 0.0;
|
||||
_iAIMax := 0;
|
||||
_iAIMin := 0;
|
||||
_xConfigError := TRUE;
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="CheckEWLevels" Id="{6fcb5a6d-e37d-4efd-ad76-02026f476863}">
|
||||
<Declaration><![CDATA[METHOD PRIVATE CheckEWLevels
|
||||
VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Reset (E)rror (W)arning config error
|
||||
_xEWConfigError := FALSE;
|
||||
|
||||
// Check for EW config error
|
||||
IF stAnalogEWConfig.stLevels.rWarningMin <= stAnalogEWConfig.stLevels.rErrorMin THEN
|
||||
_xEWConfigError := TRUE;
|
||||
END_IF
|
||||
|
||||
IF stAnalogEWConfig.stLevels.rWarningMax >= stAnalogEWConfig.stLevels.rErrorMax THEN
|
||||
_xEWConfigError := TRUE;
|
||||
END_IF
|
||||
|
||||
IF stAnalogEWConfig.stLevels.rWarningMin >= stAnalogEWConfig.stLevels.rWarningMax THEN
|
||||
_xEWConfigError := TRUE;
|
||||
END_IF
|
||||
|
||||
|
||||
// Only write error and warning levels when there was no config error
|
||||
IF (NOT _xEWConfigError) THEN
|
||||
// Recreate alarm messages with the newly set limits
|
||||
// if values have been changed
|
||||
{analysis -54}
|
||||
IF (_rMinErrorLevel <> stAnalogEWConfig.stLevels.rErrorMin)
|
||||
OR (_rMinWarningLevel <> stAnalogEWConfig.stLevels.rWarningMin)
|
||||
OR (_rMaxWarningLevel <> stAnalogEWConfig.stLevels.rWarningMax)
|
||||
OR (_rMaxErrorLevel <> stAnalogEWConfig.stLevels.rErrorMax) THEN
|
||||
{analysis +54}
|
||||
CreateAlarmLimitsMSG();
|
||||
END_IF
|
||||
|
||||
// Set new values
|
||||
_rMinErrorLevel := stAnalogEWConfig.stLevels.rErrorMin;
|
||||
_rMinWarningLevel := stAnalogEWConfig.stLevels.rWarningMin;
|
||||
_rMaxWarningLevel := stAnalogEWConfig.stLevels.rWarningMax;
|
||||
_rMaxErrorLevel := stAnalogEWConfig.stLevels.rErrorMax;
|
||||
END_IF
|
||||
]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="CreateAlarmLimitsMSG" Id="{d38eb5a5-80eb-4ab2-8c50-97431707ca20}">
|
||||
<Declaration><![CDATA[{attribute 'analysis' := '-26'}
|
||||
METHOD PRIVATE CreateAlarmLimitsMSG
|
||||
VAR_INPUT
|
||||
END_VAR
|
||||
VAR
|
||||
_sTempUnit : STRING;
|
||||
_sTempErrorMin : STRING;
|
||||
_sTempWarningMin : STRING;
|
||||
_sTempWarningMax : STRING;
|
||||
_sTempErrorMax : STRING;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Check if analog value has unit
|
||||
IF stAnalogIOConfig.sUnit <> '' THEN
|
||||
_sTempUnit := CONCAT(' ', stAnalogIOConfig.sUnit);
|
||||
ELSE
|
||||
_sTempUnit := '';
|
||||
END_IF
|
||||
|
||||
// Create message parameter strings
|
||||
_sTempErrorMin := CONCAT(REAL_TO_STRING(stAnalogEWConfig.stLevels.rErrorMin), _sTempUnit);
|
||||
_sTempWarningMin := CONCAT(REAL_TO_STRING(stAnalogEWConfig.stLevels.rWarningMin), _sTempUnit);
|
||||
_sTempWarningMax := CONCAT(REAL_TO_STRING(stAnalogEWConfig.stLevels.rWarningMax), _sTempUnit);
|
||||
_sTempErrorMax := CONCAT(REAL_TO_STRING(stAnalogEWConfig.stLevels.rErrorMax), _sTempUnit);
|
||||
|
||||
{analysis -46}
|
||||
// Inser message parameters
|
||||
_fbAlarmErrorLow.ipArguments.Clear().AddString(_sName).AddString(_sTempErrorMin);
|
||||
_fbAlarmWarningLow.ipArguments.Clear().AddString(_sName).AddString(_sTempWarningMin);
|
||||
_fbAlarmWarningHigh.ipArguments.Clear().AddString(_sName).AddString(_sTempWarningMax);
|
||||
_fbAlarmErrorHigh.ipArguments.Clear().AddString(_sName).AddString(_sTempErrorMax);
|
||||
{analysis +46}]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="CreateAlarmMSG" Id="{e4d0fc74-1711-410b-9ec3-4af08afbc236}">
|
||||
<Declaration><![CDATA[METHOD PRIVATE CreateAlarmMSG
|
||||
VAR_INPUT
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[{analysis -46}
|
||||
_fbAlarmCardError.ipArguments.Clear().AddString(_sName);
|
||||
_fbAlarmUnderrange.ipArguments.Clear().AddString(_sName);
|
||||
_fbAlarmOverload.ipArguments.Clear().AddString(_sName);
|
||||
_fbAlarmConfigError.ipArguments.Clear().AddString(_sName);
|
||||
{analysis +46}]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="FB_init" Id="{27512538-cc2f-4100-8046-022de49f067a}">
|
||||
<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)
|
||||
|
||||
// Name of analogue io
|
||||
sName : STRING(80);
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Save io name
|
||||
_sName := sName;
|
||||
|
||||
// Create alarm messages
|
||||
CreateAlarmMSG();
|
||||
CreateAlarmLimitsMSG();]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Property Name="Name" Id="{103c7177-ef49-4a4b-98b1-06578d5fce31}">
|
||||
<Declaration><![CDATA[PROPERTY Name : STRING(80)]]></Declaration>
|
||||
<Get Name="Get" Id="{02e85b3f-9933-4282-a9d2-1ab27eb22499}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[Name := _sName;]]></ST>
|
||||
</Implementation>
|
||||
</Get>
|
||||
<Set Name="Set" Id="{4215abec-259f-45d7-a31e-437036d4e241}">
|
||||
<Declaration><![CDATA[VAR
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[_sName := Name;
|
||||
|
||||
// After a name change, all error messages have to be changed
|
||||
CreateAlarmMSG();]]></ST>
|
||||
</Implementation>
|
||||
</Set>
|
||||
</Property>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
65
PLC/POUs/Analog/FB_AnalogOutput.TcPOU
Normal file
65
PLC/POUs/Analog/FB_AnalogOutput.TcPOU
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_AnalogOutput" Id="{5ea9527b-d363-4c01-ba95-f8c298545979}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[FUNCTION_BLOCK FINAL FB_AnalogOutput
|
||||
VAR_INPUT
|
||||
// Setpoint
|
||||
rSetpoint : REAL;
|
||||
|
||||
// config data for analog output scaling
|
||||
stScalingConfig : ST_ANALOG_IO_CONFIG;
|
||||
|
||||
// Global switch to dissable all errors
|
||||
xReleaseErrors : BOOL := TRUE;
|
||||
|
||||
// Enables or dissables hardware errors
|
||||
xReleaseHardwareErrors : BOOL := TRUE;
|
||||
|
||||
// Input to confirm all errors
|
||||
xConfirmAlarms : BOOL;
|
||||
|
||||
// Input to tell the fb thats ist used inside a unit test
|
||||
// Fb will not throw error messages
|
||||
{attribute 'hide'}
|
||||
xInUnitTestMode : BOOL := FALSE;
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
iAnalogValue AT %Q* : INT;
|
||||
|
||||
// Error in function block
|
||||
xError : BOOL;
|
||||
END_VAR
|
||||
VAR
|
||||
// Setpoint
|
||||
_rSetpointInternal : REAL;
|
||||
|
||||
// Name of the function block
|
||||
_sName : STRING;
|
||||
|
||||
// Scaling factor for conversion
|
||||
_rConversionFactor : REAL;
|
||||
|
||||
// Base offset for scaling factor
|
||||
_rBaseOffset : REAL;
|
||||
|
||||
// Temporary calculated analog value
|
||||
_rTempAnalogValue : REAL;
|
||||
|
||||
// Config error
|
||||
_xConfigError : BOOL;
|
||||
|
||||
// Max process value
|
||||
_rPVMax : REAL;
|
||||
|
||||
// Min process value
|
||||
_rPVMin : REAL;
|
||||
|
||||
// Config error alarm
|
||||
_fbAlarmConfigError : FB_TcAlarm;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[]]></ST>
|
||||
</Implementation>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
12
PLC/POUs/Analog/Types/ST_ANALOG_EW_CONFIG.TcDUT
Normal file
12
PLC/POUs/Analog/Types/ST_ANALOG_EW_CONFIG.TcDUT
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="ST_ANALOG_EW_CONFIG" Id="{6f3ed88d-28a0-4a7f-a26a-6b822e47799e}">
|
||||
<Declaration><![CDATA[TYPE ST_ANALOG_EW_CONFIG :
|
||||
STRUCT
|
||||
stLevels : ST_ANALOG_EW_LEVELS;
|
||||
stDelays : ST_ANALOG_EW_DELAYS;
|
||||
END_STRUCT
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
31
PLC/POUs/Analog/Types/ST_ANALOG_EW_DELAYS.TcDUT
Normal file
31
PLC/POUs/Analog/Types/ST_ANALOG_EW_DELAYS.TcDUT
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="ST_ANALOG_EW_DELAYS" Id="{8b5ae408-253c-4618-ab64-5d8c4935716b}">
|
||||
<Declaration><![CDATA[TYPE ST_ANALOG_EW_DELAYS :
|
||||
STRUCT
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timHardwareSignalLevelOn : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timHardwareSignalLevelOff : TIME;
|
||||
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timErrorLowOn : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timErrorLowOff : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timWarningLowOn : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timWarningLowOff : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timWarningHighOn : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timWarningHighOff : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timErrorHighOn : TIME;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
timErrorHighOff : TIME;
|
||||
END_STRUCT
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
18
PLC/POUs/Analog/Types/ST_ANALOG_EW_LEVELS.TcDUT
Normal file
18
PLC/POUs/Analog/Types/ST_ANALOG_EW_LEVELS.TcDUT
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="ST_ANALOG_EW_LEVELS" Id="{40734543-a4f6-4336-bcfe-ac65f034a277}">
|
||||
<Declaration><![CDATA[TYPE ST_ANALOG_EW_LEVELS :
|
||||
STRUCT
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rErrorMin : REAL;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rWarningMin : REAL;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rWarningMax : REAL;
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rErrorMax : REAL;
|
||||
END_STRUCT
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
33
PLC/POUs/Analog/Types/ST_ANALOG_IO_CONFIG.TcDUT
Normal file
33
PLC/POUs/Analog/Types/ST_ANALOG_IO_CONFIG.TcDUT
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="ST_ANALOG_IO_CONFIG" Id="{ee57b40d-d65d-438f-80f9-912bc67bff84}">
|
||||
<Declaration><![CDATA[TYPE ST_ANALOG_IO_CONFIG :
|
||||
STRUCT
|
||||
// Maximum analog value
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
iAIMax : INT;
|
||||
|
||||
// Minimum analog value
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
iAIMin : INT;
|
||||
|
||||
// Maximum process value
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rPVMax : REAL;
|
||||
|
||||
// Minimum process value
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
rPVMin : REAL;
|
||||
|
||||
// Process unit (V, A, P, U/min, %, rpm etc)
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
sUnit : STRING;
|
||||
|
||||
// Analog IO is used
|
||||
{attribute 'OPC.UA.DA' := '1'}
|
||||
xUsed : BOOL := TRUE;
|
||||
END_STRUCT
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
334
PLC/POUs/EventListener/FB_EventListener.TcPOU
Normal file
334
PLC/POUs/EventListener/FB_EventListener.TcPOU
Normal file
@@ -0,0 +1,334 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="FB_EventListener" Id="{f2b95750-ccda-4cd6-a03a-c64e3d2c4751}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[{attribute 'no_assign'}
|
||||
FUNCTION_BLOCK FB_EventListener EXTENDS FB_ListenerBase2
|
||||
VAR_INPUT
|
||||
|
||||
END_VAR
|
||||
VAR_OUTPUT
|
||||
END_VAR
|
||||
VAR
|
||||
_fbEventLogger : FB_TcEventLogger;
|
||||
|
||||
_fbEventFilter : FB_TcEventFilter;
|
||||
|
||||
_fbMqttClient : FB_IotMqtt5Client;
|
||||
|
||||
_fbBuffer : FB_MemRingBuffer;
|
||||
_abAlarmBuffer : ARRAY[0..1000] OF BYTE;
|
||||
|
||||
_fbJson : FB_JsonSaxWriter;
|
||||
|
||||
_sTopic : STRING(255);
|
||||
_stBufferEventEntryToBuffer : ST_BufferEventEntry;
|
||||
_stBufferEventEntryFromBuffer : ST_BufferEventEntry;
|
||||
|
||||
{attribute 'TcEncoding':='UTF-8'}
|
||||
_sLastMessageText : STRING;
|
||||
|
||||
_udiCurrentEntries : UDINT;
|
||||
|
||||
_uiState : UINT := 0;
|
||||
|
||||
// Result from read buffer head
|
||||
_xSuccess : BOOL;
|
||||
|
||||
// Results from read event message
|
||||
_xGetTextDone : BOOL;
|
||||
_xGetTextError : BOOL;
|
||||
|
||||
// Internal signal to connect to mqtt broker
|
||||
_xConnect : BOOL := TRUE;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Needs to be called to get alarms and events
|
||||
SUPER^.Execute();
|
||||
|
||||
// Call mqtt client
|
||||
_fbMqttClient.Execute(bConnect := _xConnect);
|
||||
|
||||
// Check if we have alarms to send
|
||||
IF _udiCurrentEntries > 0 THEN
|
||||
{analysis -19}
|
||||
_fbBuffer.A_RemoveHead(pRead:= ADR(_stBufferEventEntryFromBuffer),
|
||||
cbRead:= SIZEOF(_stBufferEventEntryFromBuffer),
|
||||
pBuffer:= ADR(_abAlarmBuffer),
|
||||
cbBuffer:= SIZEOF(_abAlarmBuffer),
|
||||
bOk=> _xSuccess,
|
||||
nCount => _udiCurrentEntries);
|
||||
{analysis +19}
|
||||
IF _xSuccess THEN
|
||||
_uiState := 10;
|
||||
END_IF
|
||||
END_IF
|
||||
|
||||
CASE _uiState OF
|
||||
0: // Idle
|
||||
|
||||
10: // Get alarm text
|
||||
_xGetTextDone := _stBufferEventEntryFromBuffer.fbAlarm.RequestEventText(
|
||||
nLangId := 1033,
|
||||
sResult := _sLastMessageText,
|
||||
nResultSize := SIZEOF(_sLastMessageText),
|
||||
bError => _xGetTextError);
|
||||
|
||||
IF _xGetTextError THEN
|
||||
_sLastMessageText := '';
|
||||
_uiState := 20;
|
||||
ELSIF _xGetTextDone THEN
|
||||
_uiState := 20;
|
||||
END_IF
|
||||
|
||||
20: // Create mqtt message
|
||||
CreateMessage();
|
||||
_uiState := 0;
|
||||
|
||||
ELSE
|
||||
// Do nothing
|
||||
;
|
||||
END_CASE]]></ST>
|
||||
</Implementation>
|
||||
<Method Name="AddAlarmToQueue" Id="{21a4a6af-4b8a-455f-b344-9cb0224cbfab}">
|
||||
<Declaration><![CDATA[METHOD PRIVATE AddAlarmToQueue : BOOL
|
||||
VAR_INPUT
|
||||
END_VAR
|
||||
VAR
|
||||
_xOk : BOOL;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[{analysis -19}
|
||||
_fbBuffer.A_AddTail( pWrite:= ADR( _stBufferEventEntryToBuffer ),
|
||||
cbWrite:= SIZEOF( _stBufferEventEntryToBuffer ),
|
||||
pBuffer:= ADR( _abAlarmBuffer ),
|
||||
cbBuffer:= SIZEOF( _abAlarmBuffer ),
|
||||
bOk=> _xOk,
|
||||
nCount => _udiCurrentEntries);
|
||||
{analysis +19}
|
||||
|
||||
AddAlarmToQueue := _xOk;
|
||||
]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="CreateMessage" Id="{d6f40ec8-01e1-47a8-a5b0-10322e1b0d10}">
|
||||
<Declaration><![CDATA[METHOD PRIVATE CreateMessage
|
||||
VAR_INPUT
|
||||
END_VAR
|
||||
VAR
|
||||
_sTemp : STRING;
|
||||
_sJsonDocument : STRING(255);
|
||||
_fbArguments : I_TcArguments;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[_fbJson.ResetDocument();
|
||||
_fbJson.StartObject();
|
||||
|
||||
// id todo test hashing
|
||||
_fbJson.AddKey('id');
|
||||
_fbJson.AddUdint(_stBufferEventEntryFromBuffer.fbAlarm.nUniqueId);
|
||||
|
||||
// Skip parent
|
||||
|
||||
// ack
|
||||
_fbJson.AddKey('ack');
|
||||
CASE _stBufferEventEntryFromBuffer.fbAlarm.eConfirmationState OF
|
||||
TcEventConfirmationState.WaitForConfirmation:
|
||||
_fbJson.AddUdint(1);
|
||||
|
||||
TcEventConfirmationState.Confirmed:
|
||||
_fbJson.AddUdint(2);
|
||||
|
||||
ELSE
|
||||
_fbJson.AddUdint(0);
|
||||
END_CASE
|
||||
|
||||
|
||||
// state
|
||||
_fbJson.AddKey('state');
|
||||
IF _stBufferEventEntryFromBuffer.fbAlarm.bActive THEN
|
||||
_fbJson.AddUdint(1);
|
||||
ELSE
|
||||
_fbJson.AddUdint(0);
|
||||
END_IF
|
||||
|
||||
|
||||
// t0
|
||||
_fbJson.AddKey('t0');
|
||||
// In case of a reraise this will be updated!!!
|
||||
_fbJson.AddUlint(_stBufferEventEntryFromBuffer.fbAlarm.nTimeRaised);
|
||||
|
||||
|
||||
// t1
|
||||
_fbJson.AddKey('t1');
|
||||
|
||||
CASE _stBufferEventEntryFromBuffer.eEventType OF
|
||||
E_EventType.RAISED:
|
||||
_fbJson.AddUlint(_stBufferEventEntryFromBuffer.fbAlarm.nTimeRaised);
|
||||
|
||||
E_EventType.CLEARED:
|
||||
_fbJson.AddUlint(_stBufferEventEntryFromBuffer.fbAlarm.nTimeCleared);
|
||||
|
||||
E_EventType.CONFIRMED:
|
||||
_fbJson.AddUlint(_stBufferEventEntryFromBuffer.fbAlarm.nTimeConfirmed);
|
||||
|
||||
ELSE
|
||||
_fbJson.AddUlint(0);
|
||||
END_CASE
|
||||
|
||||
|
||||
// Skipp access rights
|
||||
|
||||
// Skipp origin id use origin name instead
|
||||
|
||||
// origin
|
||||
_fbJson.AddKey('origin');
|
||||
{analysis -46}
|
||||
_sTemp := _stBufferEventEntryFromBuffer.fbAlarm.ipSourceInfo.sName;
|
||||
{analysis +46}
|
||||
_fbJson.AddString(_sTemp);
|
||||
|
||||
// Skipp message id because there is no catalogue
|
||||
|
||||
// msg
|
||||
_fbJson.AddKey('msg');
|
||||
_fbJson.AddString(_sLastMessageText);
|
||||
|
||||
// s
|
||||
_fbJson.AddKey('s');
|
||||
CASE _stBufferEventEntryFromBuffer.fbAlarm.eSeverity OF
|
||||
TcEventSeverity.Info:
|
||||
_fbJson.AddUdint(96);
|
||||
|
||||
TcEventSeverity.Warning:
|
||||
_fbJson.AddUdint(160);
|
||||
|
||||
TcEventSeverity.Error:
|
||||
_fbJson.AddUdint(224);
|
||||
|
||||
TcEventSeverity.Critical:
|
||||
_fbJson.AddUdint(255);
|
||||
|
||||
ELSE
|
||||
_fbJson.AddUdint(32);
|
||||
END_CASE
|
||||
|
||||
// Skip message parameters
|
||||
|
||||
_fbArguments := _stBufferEventEntryFromBuffer.fbAlarm.ipArguments;
|
||||
_fbJson.EndObject();
|
||||
{analysis -26}
|
||||
_fbJson.CopyDocument(_sJsonDocument, SIZEOF(_sJsonDocument));
|
||||
{analysis +26}
|
||||
|
||||
// Send topic
|
||||
_fbMqttClient.Publish(
|
||||
sTopic:= 'SlmMachine/Notifications/NAMESPACE/Detail',
|
||||
pPayload:= ADR(_sTemp),
|
||||
nPayloadSize:= LEN2(ADR(_sTemp))+1,
|
||||
eQoS:= TcIotMqttQos.AtLeastOnceDelivery,
|
||||
bRetain:= FALSE,
|
||||
bQueue:= FALSE);]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="FB_Init" Id="{a946d52f-a0e6-4aac-9d4c-5dd8aba5f5d2}">
|
||||
<Declaration><![CDATA[//FB_Init is always available implicitly and it is used primarily for initialization.
|
||||
//The return value is not evaluated. For a specific influence, you can also declare the
|
||||
//methods explicitly and provide additional code there with the standard initialization
|
||||
//code. You can evaluate the return value.
|
||||
METHOD FB_Init: BOOL
|
||||
VAR_INPUT
|
||||
bInitRetains: BOOL; // TRUE: the retain variables are initialized (reset warm / reset cold)
|
||||
bInCopyCode: BOOL; // TRUE: the instance will be copied to the copy code afterward (online change)
|
||||
|
||||
sHostName : STRING := 'localhost';
|
||||
uiHostPort : UINT := 1883;
|
||||
sTopic : STRING(255);
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Register alarms and messages
|
||||
_fbEventFilter.Clear().IsAlarm().OR_OP().IsMessage();
|
||||
Subscribe2(ipEventFilter := _fbEventFilter);
|
||||
|
||||
// Setup mqtt client parameters
|
||||
_fbMqttClient.sHostName := sHostName;
|
||||
_fbMqttClient.nHostPort := uiHostPort;
|
||||
_sTopic := sTopic;
|
||||
|
||||
// Reset buffer
|
||||
_fbBuffer.A_Reset();]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="OnAlarmCleared" Id="{00aefa2e-a70c-4880-b7a7-760d0051e0ee}">
|
||||
<Declaration><![CDATA[METHOD OnAlarmCleared : Tc3_EventLogger.HRESULT
|
||||
VAR_INPUT
|
||||
{attribute 'naming' := 'off'}
|
||||
fbEvent : REFERENCE TO Tc3_EventLogger.FB_TcEvent;
|
||||
{attribute 'naming' := 'on'}
|
||||
END_VAR
|
||||
VAR
|
||||
_xSuccess : BOOL;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[IF __ISVALIDREF(fbEvent) THEN
|
||||
_fbEventLogger.GetAlarmEx(stEventEntry := fbEvent.stEventEntry, ipSourceInfo := fbEvent.ipSourceInfo, fbAlarm := _stBufferEventEntryToBuffer.fbAlarm);
|
||||
_stBufferEventEntryToBuffer.eEventType := E_EventType.CLEARED;
|
||||
_xSuccess := AddAlarmToQueue();
|
||||
END_IF
|
||||
|
||||
]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="OnAlarmConfirmed" Id="{4f33c838-6809-4051-9524-d88e2cf6713c}">
|
||||
<Declaration><![CDATA[METHOD OnAlarmConfirmed : Tc3_EventLogger.HRESULT
|
||||
VAR_INPUT
|
||||
{attribute 'naming' := 'off'}
|
||||
fbEvent : REFERENCE TO Tc3_EventLogger.FB_TcEvent;
|
||||
{attribute 'naming' := 'on'}
|
||||
END_VAR
|
||||
VAR
|
||||
_xSuccess : BOOL;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[IF __ISVALIDREF(fbEvent) THEN
|
||||
_fbEventLogger.GetAlarmEx(stEventEntry := fbEvent.stEventEntry, ipSourceInfo := fbEvent.ipSourceInfo, fbAlarm := _stBufferEventEntryToBuffer.fbAlarm);
|
||||
_stBufferEventEntryToBuffer.eEventType := E_EventType.CONFIRMED;
|
||||
_xSuccess := AddAlarmToQueue();
|
||||
END_IF]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="OnAlarmRaised" Id="{2454a94e-91c5-4b90-9762-eaee63119c3b}">
|
||||
<Declaration><![CDATA[METHOD OnAlarmRaised : Tc3_EventLogger.HRESULT
|
||||
VAR_INPUT
|
||||
{attribute 'naming' := 'off'}
|
||||
fbEvent : REFERENCE TO Tc3_EventLogger.FB_TcEvent;
|
||||
{attribute 'naming' := 'on'}
|
||||
END_VAR
|
||||
VAR
|
||||
_xSuccess : BOOL;
|
||||
END_VAR]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[IF __ISVALIDREF(fbEvent) THEN
|
||||
_fbEventLogger.GetAlarmEx(stEventEntry := fbEvent.stEventEntry, ipSourceInfo := fbEvent.ipSourceInfo, fbAlarm := _stBufferEventEntryToBuffer.fbAlarm);
|
||||
_stBufferEventEntryToBuffer.eEventType := E_EventType.RAISED;
|
||||
_xSuccess := AddAlarmToQueue();
|
||||
END_IF
|
||||
]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
<Method Name="OnMessageSent" Id="{13d5d489-4166-4664-bd09-265b3b8bc14f}">
|
||||
<Declaration><![CDATA[METHOD OnMessageSent : Tc3_EventLogger.HRESULT
|
||||
VAR_INPUT
|
||||
{attribute 'naming' := 'off'}
|
||||
fbEvent : REFERENCE TO Tc3_EventLogger.FB_TcEvent;
|
||||
{attribute 'naming' := 'on'}
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[]]></ST>
|
||||
</Implementation>
|
||||
</Method>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
17
PLC/POUs/EventListener/Types/E_EventType.TcDUT
Normal file
17
PLC/POUs/EventListener/Types/E_EventType.TcDUT
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="E_EventType" Id="{c41c8e8d-56af-4514-8482-2c521e403b96}">
|
||||
<Declaration><![CDATA[{attribute 'qualified_only'}
|
||||
{attribute 'strict'}
|
||||
{attribute 'to_string'}
|
||||
TYPE E_EventType :
|
||||
(
|
||||
RAISED := 0,
|
||||
CLEARED,
|
||||
CONFIRMED,
|
||||
MESSAGE
|
||||
);
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
12
PLC/POUs/EventListener/Types/ST_BufferEventEntry.TcDUT
Normal file
12
PLC/POUs/EventListener/Types/ST_BufferEventEntry.TcDUT
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<DUT Name="ST_BufferEventEntry" Id="{95daccce-6c97-4afa-b8a3-fb60fb3847c5}">
|
||||
<Declaration><![CDATA[TYPE ST_BufferEventEntry :
|
||||
STRUCT
|
||||
fbAlarm : FB_TcAlarm;
|
||||
eEventType : E_EventType;
|
||||
END_STRUCT
|
||||
END_TYPE
|
||||
]]></Declaration>
|
||||
</DUT>
|
||||
</TcPlcObject>
|
||||
17
PLC/POUs/PRG_MAIN.TcPOU
Normal file
17
PLC/POUs/PRG_MAIN.TcPOU
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TcPlcObject Version="1.1.0.1">
|
||||
<POU Name="PRG_MAIN" Id="{f325d0cd-99c8-4d5b-980f-1fc96ab1417c}" SpecialFunc="None">
|
||||
<Declaration><![CDATA[PROGRAM PRG_MAIN
|
||||
VAR
|
||||
{attribute 'analysis' := '-33'}
|
||||
// Analog I/O tests
|
||||
_fbAnalogInputTest : FB_AnalogInputTest;
|
||||
|
||||
_fbEventlistener : FB_EventListener(sHostName := '127.0.0.1', uiHostPort := 1883, sTopic := 'SlmMachine/Notifications/PLC/Detail');
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[TcUnit.RUN();]]></ST>
|
||||
</Implementation>
|
||||
</POU>
|
||||
</TcPlcObject>
|
||||
1636
PLC/POUs/Unittests/AITests/FB_AnalogInputTest.TcPOU
Normal file
1636
PLC/POUs/Unittests/AITests/FB_AnalogInputTest.TcPOU
Normal file
File diff suppressed because it is too large
Load Diff
44
PLC/POUs/Utilities/FB_ReleaseSignal.TcPOU
Normal file
44
PLC/POUs/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>
|
||||
Reference in New Issue
Block a user