<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
  <POU Name="FB_ValveAnalogMockup" Id="{e3712921-003e-473b-993e-6c5d40e0a0c0}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_ValveAnalogMockup
VAR_INPUT
	iAnalogSetpoint AT %I* : INT;
END_VAR
VAR_OUTPUT
	xOpenFeedback AT %Q* : BOOL;
	xCloseFeedback AT %Q* : BOOL;
	iAnalogProcessValue AT %Q* : INT;
END_VAR
VAR
	_fbRampGenerator : FB_RampGenerator;
	
	_fbValveAnalogInput : FB_AnalogInput('');
	_stAnalogScaling : ST_ANALOG_IO_CONFIG := (iAIMax := 32767, iAIMin := 0, rPVMax := 100, rPVMin := 0);
	_stAnalogEWConfig : ST_ANALOG_EW_LEVELS;
	_stAnalogEWDelays : ST_ANALOG_EW_DELAYS;
	
	_fbValveAnalogOutput : FB_AnalogOutput('');
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[// Calculate setpoint 0% - 100%
// from analog value
_fbValveAnalogInput(
	iAnalogValue:= iAnalogSetpoint, 
	stScalingConfig:= _stAnalogScaling, 
	stEWConfig:= _stAnalogEWConfig, 
	stEWDelayConfig:= _stAnalogEWDelays, 
	xUnderrange:= FALSE, 
	xOverrange:= FALSE, 
	xErrorCard:= FALSE, 
	xReleaseErrors:= FALSE, 
	xReleaseLimitErrors:= FALSE, 
	xReleaseHardwareErrors:= FALSE, 
	xConfirmAlarms:= , 
	xError=> , 
	xWarning=> , 
	rScaledValue=> , 
	xErrorLow=> , 
	xWarningLow=> , 
	xWarningHigh=> , 
	xErrorHigh=> );

// Ramp generator for position simulation
_fbRampGenerator(
	rTarget:= _fbValveAnalogInput.rScaledValue, 
	rTargetMin:= 0, 
	rTargetMax:= 100, 
	timRampUp:= T#5S, 
	timRampDown:= T#5S, 
	rSetpoint=> );

// Calculate analog output from ramp generator setpoint
_fbValveAnalogOutput(
	rSetpoint:= _fbRampGenerator.rSetpoint, 
	stScalingConfig:= _stAnalogScaling,
	xReleaseErrors:= FALSE, 
	xReleaseHardwareErrors:= FALSE, 
	xConfirmAlarms:= , 
	iAnalogValue=> iAnalogProcessValue, 
	xError=> );
	
// Simulate close feedback
IF _fbRampGenerator.rSetpoint < 5.0 THEN
	xCloseFeedback := TRUE;
ELSE
	xCloseFeedback := FALSE;
END_IF

// Simulate open feedback
IF _fbRampGenerator.rSetpoint > 95.0 THEN
	xOpenFeedback := TRUE;
ELSE
	xOpenFeedback := FALSE;
END_IF]]></ST>
    </Implementation>
    <LineIds Name="FB_ValveAnalogMockup">
      <LineId Id="603" Count="38" />
      <LineId Id="75" Count="0" />
      <LineId Id="642" Count="0" />
      <LineId Id="654" Count="0" />
      <LineId Id="643" Count="1" />
      <LineId Id="646" Count="1" />
      <LineId Id="645" Count="0" />
      <LineId Id="655" Count="0" />
      <LineId Id="649" Count="0" />
      <LineId Id="648" Count="0" />
      <LineId Id="650" Count="0" />
      <LineId Id="652" Count="1" />
      <LineId Id="651" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>