File: helloWorld.st

    1   (*
    2    *
    3    * File: helloWorld.st
    4    *
    5    * IEC 61131-3 Structured Text (ST) code generated for subsystem "helloWorld/Valve2"
    6    *
    7    * Model name                      : helloWorld
    8    * Model version                   : 1.5
    9    * Model creator                   : JL
   10    * Model last modified by          : JL
   11    * Model last modified on          : Fri Dec 16 08:26:52 2022
   12    * Model sample time               : 0.5s
   13    * Subsystem name                  : helloWorld/Valve2
   14    * Subsystem sample time           : 0.5s
   15    * Simulink PLC Coder version      : 3.7 (R2022b) 13-May-2022
   16    * ST code generated on            : Fri Dec 16 08:56:38 2022
   17    *
   18    * Target IDE selection            : Generic
   19    * Test Bench included             : No
   20    *
   21    *)
   22   FUNCTION_BLOCK Valve2
   23   VAR_INPUT
   24       ssMethodType: SINT;
   25       iClosed: BOOL;
   26       iOpened: BOOL;
   27       iReqClose: BOOL;
   28       iReqOpen: BOOL;
   29   END_VAR
   30   VAR_OUTPUT
   31       oPower: BOOL;
   32   END_VAR
   33   VAR
   34       temporalCounter_i1: USINT;
   35       is_active_c3_Valve2: USINT;
   36       is_c3_Valve2: USINT;
   37   END_VAR
   38   CASE ssMethodType OF
   39       0: 
   40           (* SystemInitialize for Chart: '<Root>/Valve2' incorporates:
   41            *  Outport: '<Root>/oPower' *)
   42           temporalCounter_i1 := 0;
   43           is_active_c3_Valve2 := 0;
   44           is_c3_Valve2 := 0;
   45           oPower := FALSE;
   46       1: 
   47           (* Chart: '<Root>/Valve2' incorporates:
   48            *  Outport: '<Root>/oPower' *)
   49           IF temporalCounter_i1 < 31 THEN 
   50               temporalCounter_i1 := temporalCounter_i1 + 1;
   51           END_IF;
   52           (* Gateway: Valve2 *)
   53           (* During: Valve2 *)
   54           IF is_active_c3_Valve2 = 0 THEN 
   55               (* Entry: Valve2 *)
   56               is_active_c3_Valve2 := 1;
   57               (* Entry Internal: Valve2 *)
   58               (* Transition: '<S1>:16' *)
   59               (* '<S1>:15:1' sf_internal_predicateOutput = iClosed&& ~iOpened; *)
   60               IF iClosed AND ( NOT iOpened) THEN 
   61                   (* Transition: '<S1>:15' *)
   62                   is_c3_Valve2 := 3;
   63               ELSE 
   64                   (* '<S1>:17:1' sf_internal_predicateOutput = ~iClosed && iOpened; *)
   65                   IF ( NOT iClosed) AND iOpened THEN 
   66                       (* Transition: '<S1>:17' *)
   67                       (* Transition: '<S1>:21' *)
   68                       (* Transition: '<S1>:23' *)
   69                       is_c3_Valve2 := 4;
   70                   ELSE 
   71                       (* Transition: '<S1>:19' *)
   72                       is_c3_Valve2 := 1;
   73                   END_IF;
   74               END_IF;
   75           ELSE 
   76               CASE is_c3_Valve2 OF
   77                   1: 
   78                       (* During 'Alarm': '<S1>:18' *)
   79                       (* '<S1>:26:1' sf_internal_predicateOutput = iReqOpen; *)
   80                       IF iReqOpen THEN 
   81                           (* Transition: '<S1>:26' *)
   82                           (* Transition: '<S1>:27' *)
   83                           (* Transition: '<S1>:28' *)
   84                           is_c3_Valve2 := 5;
   85                           temporalCounter_i1 := 0;
   86                           (* Entry 'Opening': '<S1>:3' *)
   87                       ELSE 
   88                           (* '<S1>:30:1' sf_internal_predicateOutput = iReqClose; *)
   89                           IF iReqClose THEN 
   90                               (* Transition: '<S1>:30' *)
   91                               (* Transition: '<S1>:31' *)
   92                               is_c3_Valve2 := 2;
   93                               temporalCounter_i1 := 0;
   94                               (* Entry 'Closing': '<S1>:7' *)
   95                           END_IF;
   96                       END_IF;
   97                   2: 
   98                       (* During 'Closing': '<S1>:7' *)
   99                       (* '<S1>:11:1' sf_internal_predicateOutput = iClosed; *)
  100                       IF iClosed THEN 
  101                           (* Transition: '<S1>:11' *)
  102                           is_c3_Valve2 := 3;
  103                       ELSE 
  104                           (* '<S1>:37:1' sf_internal_predicateOutput = after(10,sec); *)
  105                           IF temporalCounter_i1 >= 20 THEN 
  106                               (* Transition: '<S1>:37' *)
  107                               is_c3_Valve2 := 1;
  108                           ELSE 
  109                               (* '<S1>:7:3' oPower = false; *)
  110                               oPower := FALSE;
  111                           END_IF;
  112                       END_IF;
  113                   3: 
  114                       (* During 'Off': '<S1>:1' *)
  115                       (* '<S1>:4:1' sf_internal_predicateOutput = iReqOpen; *)
  116                       IF iReqOpen THEN 
  117                           (* Transition: '<S1>:4' *)
  118                           is_c3_Valve2 := 5;
  119                           temporalCounter_i1 := 0;
  120                           (* Entry 'Opening': '<S1>:3' *)
  121                       END_IF;
  122                   4: 
  123                       (* During 'On': '<S1>:8' *)
  124                       (* '<S1>:10:1' sf_internal_predicateOutput = iReqClose; *)
  125                       IF iReqClose THEN 
  126                           (* Transition: '<S1>:10' *)
  127                           is_c3_Valve2 := 2;
  128                           temporalCounter_i1 := 0;
  129                           (* Entry 'Closing': '<S1>:7' *)
  130                       END_IF;
  131                   ELSE
  132                       (* During 'Opening': '<S1>:3' *)
  133                       (* '<S1>:9:1' sf_internal_predicateOutput = iOpened; *)
  134                       IF iOpened THEN 
  135                           (* Transition: '<S1>:9' *)
  136                           is_c3_Valve2 := 4;
  137                       ELSE 
  138                           (* '<S1>:35:1' sf_internal_predicateOutput = after(10,sec); *)
  139                           IF temporalCounter_i1 >= 20 THEN 
  140                               (* Transition: '<S1>:35' *)
  141                               is_c3_Valve2 := 1;
  142                           ELSE 
  143                               (* '<S1>:3:3' oPower = true; *)
  144                               oPower := TRUE;
  145                           END_IF;
  146                       END_IF;
  147               END_CASE;
  148           END_IF;
  149           (* End of Chart: '<Root>/Valve2' *)
  150   END_CASE;
  151   END_FUNCTION_BLOCK
  152