FUNCTION_BLOCK WP_SENSE

EVENT_INPUT
    SENSE WITH STYLE,REFSTYLE,POS,P0,P1;
      (* Input change notification *)
END_EVENT
EVENT_OUTPUT
    IND WITH PRESENT,MATCH;
      (* Output change indication *)
END_EVENT
VAR_INPUT
    POS : UINT; 
      (* Workpiece position on conveyor (0-100%) *)
    P0 : UINT;
      (* Position sensor lower limit *)
    P1 : UINT;
      (* Position sensor upper limit *)
    STYLE : VSTYLE;
      (* Workpiece style *)
    REFSTYLE : VSTYLE;
      (* Style to be sensed *)
END_VAR
VAR_OUTPUT
    PRESENT : BOOL;
      (* Workpiece is present between P0 and P1 *)
    MATCH : BOOL;
      (* Workpiece is present and STYLE matches REFSTYLE *)
END_VAR
VAR
    CHANGED : BOOL;
      (* PRESENT and/or MATCH value has changed *)
END_VAR

An instance of this function block type models the operation of a dual set of sensors which can sense both the presence of a workpiece at a position POS between the two positions P0 and P1 inclusive, and whether the type of the workpiece given by the STYLE input matches the reference style REFSTYLE (an instance of the VSTYLE data type) when the workpiece is present. It is typically used to position a sensor pair at a specified location along a conveyor modelled by an instance of the CNV_MDL type or its enclosing CNV_MDLL or CNVG_MDLL types, for instance as in the sortation/inspection testbed.

As modeled by the Execution Control Chart (ECC) and Algorithm shown below, the operation of the block is triggered by an event at the SENSE input and results in an event at the IND output when the value of either or both of the PRESENT and MATCH sensors changes.

ECC
ALGORITHM SENSE IN Java :
final boolean newpres
  = (POS.value>=P0.value)
    && (POS.value<=P1.value)
    && (STYLE.value != VSTYLE.NONE);
final boolean newmatch
  = newpres && (STYLE.equals(REFSTYLE));
CHANGED.value
   = (newpres != PRESENT.value)
      ||(newmatch != MATCH.value);
if(CHANGED.value){
  PRESENT.value = newpres;
  MATCH.value = newmatch;}
END_ALGORITHM