Table of Contents

AnalogInputInt

Namespace
ZEquipment
Extends
Inherited Properties
Inherited Methods
Implements
FUNCTION_BLOCK AnalogInputInt EXTENDS ZEquipment.Analog IMPLEMENTS ZEquipment.IAnalog, ZEquipment.IDigital, ZCore.ITrigger

Implementation of an analog input with the underlying datatype INT. The function block implements convenient methods to interact with a physical input or (by default) allows to simulate an analog input. for details refer to Analog

As an example we used a EL3162 (16Bit Analog Input 0-10V) and a pressure sensor with electrical output of 1-5V with a physical measurement range of 0-10Bar. These values are now entered in SetConversionParameters and all the conversion stuff is done by the function block itself.

PROGRAM MAIN
VAR
  AInput : ZEquipment.AnalogInputInt;
  PhysicalValue : LREAL;
  RawValue : INT;
  DateTime : ZAux.DateTimeUM;
  Logger : ZAux.LoggerFile7FFUM(datetime:=DateTime, filePath:='C:\temp\logfile.log', target:='');
  Step : Step(begin:=0, end:=100);
  Timer : ZAux.Timer;
END_VAR
---------------------------------
DateTime.Cyclic();
Logger.Cyclic();

CASE Step.Index OF
  0:
    AInput.SetName('Pressure');
    AInput.SetConversionParameters(terminalMin:=0,   // 0 Volt Terminal min value
                                   terminalMax:=10,  // 10 Volt Terminal max value
                                   elecMin:=1,       // 1 Volt Sensor electrical min value
                                   elecMax:=5,       // 5 Volt Sensor electrical max value
                                   physMin:=0,       // 0 Bar Sensor physical min value
                                   physMax:=10,      // 10 Bar Sensor physical max value
                                   physicalUnit:='bar');
    //Druck.SetConversionLinear(slope:=25, intercept:=-2.5, valueUnit:='bar');
    AInput.SetTerminalResolution(resolution:=16);
    AInput.SetSimulation(TRUE); // to be able to simulate its behavior
    AInput.SetLogger(Logger);
    Step.SetNext(10);

  10: // Waiting 1sec
    IF Step.OnEntry() THEN
      Timer.WaitAsync(1.0);
    END_IF
   
    IF Timer.Done THEN
      Step.SetNext(20);
    END_IF

  20: // Switch on output for 1sec
    IF Step.OnEntry() THEN
      AInput.WriteRaw(5698); // writing to an input is only possible when simulated
      Timer.WaitAsync(1.0);
    END_IF
   
    IF Timer.Done THEN
      Step.SetNext(30);
    END_IF

  30: // Switch off output
    PhysicalValue := AInput.Read();
    RawValue := AInput.ReadRaw();
    Step.SetNext(40);
   
  40: // Idling
    ;

END_CASE

A second example shows the use of a 12 Bit terminal from Beckhoff like the EL3061 (12Bit Analog Input 0-10V). The sensor is the same as above but scaled a little differently. However the parameterization with SetConversionParameters stays exactly the same.

PROGRAM MAIN
VAR
  AInput : ZEquipment.AnalogInputInt;
  PhysicalValue : LREAL;
  RawValue : INT;
  DateTime : ZAux.DateTimeUM;
  Logger : ZAux.LoggerFile7FFUM(datetime:=DateTime, filePath:='C:\temp\logfile.log', target:='');
  Step : Step(begin:=0, end:=100);
  Timer : ZAux.Timer;
END_VAR
---------------------------------
DateTime.Cyclic();
Logger.Cyclic();

CASE Step.Index OF
  0:
    AInput.SetName('Pressure');
    AInput.SetConversionParameters(terminalMin:=0,   // 0 Volt Terminal min value
                                   terminalMax:=10,  // 10 Volt Terminal max value
                                   elecMin:=1,       // 1 Volt Sensor electrical min value
                                   elecMax:=5,       // 5 Volt Sensor electrical max value
                                   physMin:=0,       // 0 Bar Sensor physical min value
                                   physMax:=10,      // 10 Bar Sensor physical max value
                                   physicalUnit:='bar');
    //Druck.SetConversionLinear(slope:=25, intercept:=-2.5, valueUnit:='bar');
    AInput.SetTerminalResolution(resolution:=12); // only resolution changes to 12 Bit
    AInput.SetSimulation(TRUE); // to be able to simulate its behavior
    AInput.SetLogger(Logger);
    Step.SetNext(10);

  10: // Waiting 1sec
    IF Step.OnEntry() THEN
      Timer.WaitAsync(1.0);
    END_IF
   
    IF Timer.Done THEN
      Step.SetNext(20);
    END_IF

  20: // Switch on output for 1sec
    IF Step.OnEntry() THEN
      AInput.WriteRaw(2356); // writing to an input is only possible when simulated
      Timer.WaitAsync(1.0);
    END_IF
   
    IF Timer.Done THEN
      Step.SetNext(30);
    END_IF

  30: // Switch off output
    PhysicalValue := AInput.Read();
    RawValue := AInput.ReadRaw();
    Step.SetNext(40);
   
  40: // Idling
    ;

END_CASE

Constructor

FB_init

METHOD FB_init (
 [input] bInitRetains : BOOL,
 [input] bInCopyCode : BOOL) : BOOL

Inputs

bInitRetains BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

Returns

BOOL

Properties

PROPERTY Link : INT

Returns the raw value of the actuator as it is written/read from the bus

Property Value

INT

Simulation

PROPERTY Simulation : BOOL

This property is used to enable or disable the simulation mode for the analog terminal. Internally the pointer to the variable that is written to or read from, respectively, is swapped by toggling this property. Simulated inputs behave different with respect to actual terminals with regard to the Write method. Phyisical terminals can not be written to, for simulated terminal this is totally fine though (and even needed most of the times).

Property Value

BOOL

Methods

ReadImpl

METHOD PROTECTED ReadImpl () : LREAL

This method reads a physical value from the terminal. The raw value that is read from the terminal is converted by applying a linear conversion that can be set by using the SetConversionLinear method. If no conversion is specified, the method returns a number between 0 and 1 (default linear conversion).

This method behaves the same for physical and simulated terminals (Simulation)

Returns

LREAL

ReadRaw

METHOD ReadRaw () : INT

This method returns the raw value that is given by the terminal. No linear conversion is applied.

This method behaves the same for physical and simulated terminals (Simulation)

Returns

INT

WriteImpl

METHOD PROTECTED WriteImpl (
 [input] value : LREAL)

This method writes a physical value from the terminal. The value that is passed as a parameter is converted to a value that is actually usable for the terminal. This is achieved by applying a linear conversion that has been set using the SetConversionLinear method. By default the conversion assumes that values are scaled between 0-1.

This method behaves differently for physical and simulated terminals (Simulation). Only simulated terminals can be written to. No action is taken when attempting to write to a physical analog terminal.

Inputs

value LREAL

WriteRaw

METHOD WriteRaw (
 [input] value : INT)

This method writes a raw value to the terminal. No linear conversion is applied.

This method behaves differently for physical and simulated terminals (Simulation). Only simulated terminals can be written to. No action is taken when attempting to write to a physical analog terminal.

Inputs

value INT