_IF _NOT __SYSVA_FIRST_SCAN _GOTO __LAB1 
SHUTDOWN_TIME := __SYSVA_CYCLEDATE 
DEVICE_STATUS := __TMPM1 
RESTART_COMMAND := FALSE 
RESTART_ALLOWED := FALSE 
RUN_PERMISSIVE := FALSE 
START_PERMISSIVE := FALSE 
VFD_READ := TRUE 
_GOTO __LAB2 
__LAB1 : 
__LAB2 : 
_IF _NOT HMI_SELECT_HAND _GOTO __LAB3 
HMI_HOA := __CSINT00000001 
_GOTO __LAB4 
__LAB3 : 
_IF _NOT HMI_SELECT_OFF _GOTO __LAB5 
HMI_HOA := __SINT_NULL 
_GOTO __LAB4 
__LAB5 : 
_IF _NOT HMI_SELECT_AUTO _GOTO __LAB6 
HMI_HOA := __CSINT00000002 
_GOTO __LAB4 
__LAB6 : 
__LAB4 : 
_PUSH_PAR HMI_HOA 
__TMPI1 := _CALL ANY_TO_SINT 
__TMPB1 := __TMPI1 <> __DINT_NULL 
_IF __TMPB1 _GOTO __LAB8 
AUTO_MODE := FALSE 
HAND_MODE := FALSE 
OFF_MODE := TRUE 
_GOTO __LAB7 
__LAB8 : 
__TMPB1 := __TMPI1 <> __CDINT00000001 
_IF __TMPB1 _GOTO __LAB9 
AUTO_MODE := FALSE 
HAND_MODE := TRUE 
OFF_MODE := FALSE 
_GOTO __LAB7 
__LAB9 : 
__TMPB1 := __TMPI1 <> __CDINT00000002 
_IF __TMPB1 _GOTO __LABa 
AUTO_MODE := TRUE 
HAND_MODE := FALSE 
OFF_MODE := FALSE 
_GOTO __LAB7 
__LABa : 
__LAB7 : 
_IF _NOT HMI_VFD_WRITE _GOTO __LABb 
VFD_WRITE := TRUE 
_GOTO __LABc 
__LABb : 
__LABc : 
_IF _NOT HMI_VFD_READ _GOTO __LABd 
VFD_READ := TRUE 
_GOTO __LABe 
__LABd : 
__LABe : 
_IF _NOT DOWNHOLE_TOOL_ENABLED _GOTO __LABf 
__TMPI1 := __CDINT00000002 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
_PUSH_PAR __TMPUIN1 
__TMPR1 := _CALL ANY_TO_UINT 
__TMPR1 := __TMPR1 / __TMPR2 
DH_INTAKETEMPERATURE := __TMPR1 
__TMPI1 := __CDINT00000003 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
_PUSH_PAR __TMPUIN1 
__TMPR1 := _CALL ANY_TO_UINT 
DH_INTAKEPRESSURE := __TMPR1 
__TMPI1 := __CDINT0000000A - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
DH_NUMCHANNELS := __TMPUIN1 
__TMPI1 := __CDINT0000000B - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
DH_TOOLVOLTAGE := __TMPUIN1 
__TMPI1 := __CDINT00000028 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
_PUSH_PAR __TMPUIN1 
__TMPR1 := _CALL ANY_TO_UINT 
__TMPR1 := __TMPR1 / __TMPR2 
DH_MAXINTAKETEMPERATURE_STARTUP := __TMPR1 
__TMPI1 := __CDINT00000029 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
DH_MAXINTAKEPRESSURE_STARTUP := __TMPUIN1 
__TMPI1 := __CDINT00000063 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
DH_DOWNHOLESTATUS_INT := __TMPUIN1 
__TMPR1 := DH_INTAKEPRESSURE - __TMPR3 
__TMPR6 := __TMPR4 / __TMPR5 
__TMPR1 := __TMPR1 * __TMPR6 
DH_FLUID_LEVEL := __TMPR1 
__TMPI1 := __CDINT00000063 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ0 [ __TMPI1 ]
_PUSH_PAR __TMPUIN1 
__TMPI2 := _CALL ANY_TO_UINT 
__TMPB1 := __TMPI2 <> __DINT_NULL 
_IF __TMPB1 _GOTO __LAB11 
DH_DOWNHOLESTATUS := __TMPM2 
_GOTO __LAB10 
__LAB11 : 
__TMPB1 := __TMPI2 <> __CDINT00000001 
_IF __TMPB1 _GOTO __LAB12 
DH_DOWNHOLESTATUS := __TMPM3 
_GOTO __LAB10 
__LAB12 : 
__TMPB1 := __TMPI2 <> __CDINT00000002 
_IF __TMPB1 _GOTO __LAB13 
DH_DOWNHOLESTATUS := __TMPM4 
_GOTO __LAB10 
__LAB13 : 
__TMPB1 := __TMPI2 <> __CDINT00000003 
_IF __TMPB1 _GOTO __LAB14 
DH_DOWNHOLESTATUS := __TMPM5 
_GOTO __LAB10 
__LAB14 : 
__TMPB1 := __TMPI2 <> __CDINT00000004 
_IF __TMPB1 _GOTO __LAB15 
DH_DOWNHOLESTATUS := __TMPM6 
_GOTO __LAB10 
__LAB15 : 
DH_DOWNHOLESTATUS := __TMPM7 
__LAB10 : 
__TMPI1 := __CDINT00000005 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ1000 [ __TMPI1 ]
DH_TOOLTYPE := __TMPUIN1 
__TMPI1 := __CDINT00000007 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ1000 [ __TMPI1 ]
__TMPUIN1 := __TMPUIN1 * __CUINT000003E8 
DH_PSIRATING := __TMPUIN1 
__TMPI1 := __CDINT00000008 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ1000 [ __TMPI1 ]
_PUSH_PAR __TMPUIN1 
__TMPR1 := _CALL ANY_TO_UINT 
__TMPR1 := __TMPR1 / __TMPR2 
DH_MAXINTAKETEMPERATURE_FOREVER := __TMPR1 
__TMPI1 := __CDINT00000009 - __CDINT00000001 
__TMPI1 := __TMPI1 * __CDINT00000002 
__TMPUIN1 := MODBUS_READ1000 [ __TMPI1 ]
DH_MAXINTAKEPRESSURE_FOREVER := __TMPUIN1 
_GOTO __LAB16 
__LABf : 
DH_DOWNHOLESTATUS := __TMPM8 
DH_PRESSURE_SHUTDOWN_ENABLED := FALSE 
DH_PRESSURE_STARTUP_ENABLED := FALSE 
DH_TEMP_SHUTDOWN_ENABLED := FALSE 
DH_TEMP_STARTUP_ENABLED := FALSE 
__LAB16 : 
__TMPB1 := _NOT TEST_MODE 
_IF _NOT __TMPB1 _GOTO __LAB17 
_PUSH_PAR _IO_EM_AI_00 
__TMPR1 := _CALL ANY_TO_UINT 
__TMPR__LINEARSCALE__RAW_INP := __TMPR1 
__FBL_RET := _PUSHCALLFB LINEARSCALE  LINEARSCALE_PRESSURE 
__TMPR1 := LINEARSCALE_PRESSURE [ __CDINT0000000C ]
TUBINGPRESSURE_IN := __TMPR1 
VFD_DISABLED := FALSE 
_GOTO __LAB18 
__LAB17 : 
VFD_DISABLED := TRUE 
_PUSH_PAR __CDINT0000000A 
__TMPI1 := _CALL RAND 
_PUSH_PAR __TMPI1 
__TMPR1 := _CALL ANY_TO_DINT 
__TMPR1 := __TMPR1 / __TMPR2 
__TMPR6 := __TMPR9 + __TMPR1 
VFD_DCBUSVOLTAGE := __TMPR6 
_IF _NOT VFD_START _GOTO __LAB19 
VFD_CMDSPEED := VFD_SPEEDREF 
VFD_SPEEDFDBK := VFD_SPEEDREF 
_PUSH_PAR __CDINT0000000A 
__TMPI1 := _CALL RAND 
_PUSH_PAR __TMPI1 
__TMPR1 := _CALL ANY_TO_DINT 
__TMPR1 := __TMPR1 / __TMPR2 
__TMPR6 := __TMPR10 + __TMPR1 
VFD_OUTPUTCURRENT := __TMPR6 
_GOTO __LAB1a 
__LAB19 : 
__LAB1a : 
_IF _NOT VFD_STOP _GOTO __LAB1b 
VFD_CMDSPEED := __TMPR11 
VFD_SPEEDFDBK := __TMPR11 
VFD_OUTPUTCURRENT := __TMPR11 
VFD_OUTPUTVOLTAGE := __TMPR11 
_GOTO __LAB1c 
__LAB1b : 
__LAB1c : 
__LAB18 : 
__TMPB1 := TUBINGPRESSURE_TRANSDUCER_ENABLED _AND VFD_RUN_CMD 
_PUSH_PAR RUN_TIME 
__TMPI1 := _CALL ANY_TO_TIME 
__TMPI2 := TUBINGPRESSURE_ALARM_STARTUP_DELAY * __CDINT000003E8 
__TMPB2 := __TMPI1 > __TMPI2 
__TMPB1 := __TMPB1 _AND __TMPB2 
_IF _NOT __TMPB1 _GOTO __LAB1d 
__TMPB3 := TUBINGPRESSURE_IN >= TUBINGPRESSURE_HI_SP 
_IF _NOT __TMPB3 _GOTO __LAB1e 
TUBINGPRESSURE_HI := TRUE 
TUBINGPRESSURE_LO := FALSE 
_GOTO __LAB1f 
__LAB1e : 
__TMPB1 := TUBINGPRESSURE_IN <= TUBINGPRESSURE_LO_SP 
_IF _NOT __TMPB1 _GOTO __LAB20 
TUBINGPRESSURE_HI := FALSE 
TUBINGPRESSURE_LO := TRUE 
_GOTO __LAB1f 
__LAB20 : 
TUBINGPRESSURE_HI := FALSE 
TUBINGPRESSURE_LO := FALSE 
__LAB1f : 
__TMPB1 := _NOT TUBINGPRESSURE_HI 
__TMPB2 := _NOT TUBINGPRESSURE_LO 
__TMPB1 := __TMPB1 _AND __TMPB2 
_IF _NOT __TMPB1 _GOTO __LAB21 
TUBINGPRESSURE_OK := TRUE 
TUBINGPRESSURE_OOT_SCANS := __UDINT_NULL 
TUBINGPRESSURE_OOT_SECONDS := __UDINT_NULL 
_GOTO __LAB22 
__LAB21 : 
__TMPUDI1 := TUBINGPRESSURE_OOT_SCANS + __CUDINT00000001 
TUBINGPRESSURE_OOT_SCANS := __TMPUDI1 
_PUSH_PAR __SYSVA_TCYCURRENT 
__TMPUDI1 := _CALL ANY_TO_TIME 
__TMPUDI2 := TUBINGPRESSURE_OOT_SCANS * __TMPUDI1 
__TMPUDI2 := __TMPUDI2 / __CUDINT000003E8 
TUBINGPRESSURE_OOT_SECONDS := __TMPUDI2 
__LAB22 : 
__TMPB1 := TUBINGPRESSURE_OOT_SECONDS > TUBINGPRESSURE_ALARM_DELAY 
_IF _NOT __TMPB1 _GOTO __LAB23 
TUBINGPRESSURE_OK := FALSE 
_GOTO __LAB24 
__LAB23 : 
__LAB24 : 
_GOTO __LAB25 
__LAB1d : 
TUBINGPRESSURE_OK := TRUE 
__LAB25 : 
_IF _NOT DH_PRESSURE_STARTUP_ENABLED _GOTO __LAB26 
__TMPB1 := DH_INTAKEPRESSURE > DH_PRESSURE_STARTUP 
_IF _NOT __TMPB1 _GOTO __LAB27 
SP_PRESSURE := TRUE 
_GOTO __LAB28 
__LAB27 : 
SP_PRESSURE := FALSE 
__LAB28 : 
_GOTO __LAB29 
__LAB26 : 
SP_PRESSURE := TRUE 
__LAB29 : 
_IF _NOT DH_TEMP_STARTUP_ENABLED _GOTO __LAB2a 
__TMPB1 := DH_INTAKETEMPERATURE < DH_TEMP_STARTUP 
_IF _NOT __TMPB1 _GOTO __LAB2b 
SP_TEMPERATURE := TRUE 
_GOTO __LAB2c 
__LAB2b : 
SP_TEMPERATURE := FALSE 
__LAB2c : 
_GOTO __LAB2d 
__LAB2a : 
SP_TEMPERATURE := TRUE 
__LAB2d : 
__TMPB1 := HAND_MODE _OR AUTO_MODE 
__TMPB1 := __TMPB1 _OR TEST_MODE 
_IF _NOT __TMPB1 _GOTO __LAB2e 
SP_MODE := TRUE 
_GOTO __LAB2f 
__LAB2e : 
SP_MODE := FALSE 
__LAB2f : 
__TMPB1 := _NOT REMOTE_SHUTDOWN_DISABLED 
_IF _NOT __TMPB1 _GOTO __LAB30 
_IF _NOT _IO_EM_DI_00 _GOTO __LAB31 
SP_REMOTE := TRUE 
_GOTO __LAB32 
__LAB31 : 
SP_REMOTE := FALSE 
__LAB32 : 
_GOTO __LAB33 
__LAB30 : 
SP_REMOTE := TRUE 
__LAB33 : 
SP_VFD := VFD_READY 
__TMPB1 := SP_PRESSURE _AND SP_TEMPERATURE 
__TMPB1 := __TMPB1 _AND SP_MODE 
__TMPB1 := __TMPB1 _AND SP_VFD 
__TMPB1 := __TMPB1 _AND SP_REMOTE 
_IF _NOT __TMPB1 _GOTO __LAB34 
START_PERMISSIVE := TRUE 
_GOTO __LAB35 
__LAB34 : 
START_PERMISSIVE := FALSE 
DEVICE_STATUS := __TMPM9 
__LAB35 : 
_IF _NOT DH_PRESSURE_SHUTDOWN_ENABLED _GOTO __LAB36 
__TMPB1 := DH_INTAKEPRESSURE > DH_PRESSURE_SHUTDOWN 
_IF _NOT __TMPB1 _GOTO __LAB37 
RP_PRESSURE := TRUE 
_GOTO __LAB38 
__LAB37 : 
RP_PRESSURE := FALSE 
__LAB38 : 
_GOTO __LAB39 
__LAB36 : 
RP_PRESSURE := TRUE 
__LAB39 : 
_IF _NOT DH_TEMP_SHUTDOWN_ENABLED _GOTO __LAB3a 
__TMPB1 := DH_INTAKETEMPERATURE < DH_TEMP_SHUTDOWN 
_IF _NOT __TMPB1 _GOTO __LAB3b 
RP_TEMPERATURE := TRUE 
_GOTO __LAB3c 
__LAB3b : 
RP_TEMPERATURE := FALSE 
__LAB3c : 
_GOTO __LAB3d 
__LAB3a : 
RP_TEMPERATURE := TRUE 
__LAB3d : 
__TMPB1 := HAND_MODE _OR AUTO_MODE 
__TMPB1 := __TMPB1 _OR TEST_MODE 
_IF _NOT __TMPB1 _GOTO __LAB3e 
RP_MODE := TRUE 
_GOTO __LAB3f 
__LAB3e : 
RP_MODE := FALSE 
__LAB3f : 
__TMPB1 := _NOT REMOTE_SHUTDOWN_DISABLED 
_IF _NOT __TMPB1 _GOTO __LAB40 
_IF _NOT _IO_EM_DI_00 _GOTO __LAB41 
RP_REMOTE := TRUE 
_GOTO __LAB42 
__LAB41 : 
RP_REMOTE := FALSE 
__LAB42 : 
_GOTO __LAB43 
__LAB40 : 
RP_REMOTE := TRUE 
__LAB43 : 
RP_VFD := VFD_READY 
RP_TUBINGPRESSURE := TUBINGPRESSURE_OK 
__TMPB1 := RP_PRESSURE _AND RP_TEMPERATURE 
__TMPB1 := __TMPB1 _AND RP_MODE 
__TMPB1 := __TMPB1 _AND RP_VFD 
__TMPB1 := __TMPB1 _AND RP_TUBINGPRESSURE 
__TMPB1 := __TMPB1 _AND RP_REMOTE 
_IF _NOT __TMPB1 _GOTO __LAB44 
RUN_PERMISSIVE := TRUE 
_GOTO __LAB45 
__LAB44 : 
RUN_PERMISSIVE := FALSE 
__LAB45 : 
__TMPB1 := _NOT RUN_PERMISSIVE 
__TMPB1 := __TMPB1 _AND VFD_RUN_CMD 
_IF _NOT __TMPB1 _GOTO __LAB46 
DEVICE_STATUS := __TMPM10 
SHUTDOWN_TIME := __SYSVA_CYCLEDATE 
__TMPB1 := _NOT RP_MODE 
_IF _NOT __TMPB1 _GOTO __LAB47 
ALARM_MODE := TRUE 
_GOTO __LAB48 
__LAB47 : 
__TMPB1 := _NOT RP_PRESSURE 
_IF _NOT __TMPB1 _GOTO __LAB49 
ALARM_PRESSURE := TRUE 
_GOTO __LAB48 
__LAB49 : 
__TMPB1 := _NOT RP_TEMPERATURE 
_IF _NOT __TMPB1 _GOTO __LAB4a 
ALARM_TEMPERATURE := TRUE 
_GOTO __LAB48 
__LAB4a : 
__TMPB1 := _NOT RP_TUBINGPRESSURE 
_IF _NOT __TMPB1 _GOTO __LAB4b 
ALARM_TUBINGPRESSURE := TRUE 
_GOTO __LAB48 
__LAB4b : 
__TMPB1 := _NOT RP_VFD 
_IF _NOT __TMPB1 _GOTO __LAB4c 
ALARM_VFD := TRUE 
_GOTO __LAB48 
__LAB4c : 
__LAB48 : 
VFD_START := FALSE 
_GOTO __LAB4d 
__LAB46 : 
__LAB4d : 
_IF _NOT RUN_PERMISSIVE _GOTO __LAB4e 
ALARM_MODE := FALSE 
ALARM_PRESSURE := FALSE 
ALARM_TEMPERATURE := FALSE 
ALARM_VFD := FALSE 
_GOTO __LAB4f 
__LAB4e : 
__LAB4f : 
__TMPB1 := START_BUTTON _OR START_COMMAND 
__TMPB2 := RESTART_ALLOWED _AND RESTART_COMMAND 
__TMPB1 := __TMPB1 _OR __TMPB2 
__TMPB1 := __TMPB1 _AND START_PERMISSIVE 
__TMPB1 := __TMPB1 _OR VFD_RUN_CMD 
__TMPB3 := _NOT STOP_COMMAND 
__TMPB1 := __TMPB1 _AND __TMPB3 
__TMPB1 := __TMPB1 _AND RUN_PERMISSIVE 
_IF _NOT __TMPB1 _GOTO __LAB50 
VFD_RUN_CMD := TRUE 
RESTART_COMMAND := FALSE 
START_COMMAND := FALSE 
__TMPB1 := _NOT START_TIME_SET 
_IF _NOT __TMPB1 _GOTO __LAB51 
START_TIME := __SYSVA_CYCLEDATE 
START_TIME_SET := TRUE 
_GOTO __LAB52 
__LAB51 : 
__LAB52 : 
_IF _NOT VFD_RUN_CMD _GOTO __LAB53 
DEVICE_STATUS := __TMPM11 
__TMPT1 := __SYSVA_CYCLEDATE - START_TIME 
RUN_TIME := __TMPT1 
VFD_START := TRUE 
_GOTO __LAB54 
__LAB53 : 
__LAB54 : 
_GOTO __LAB55 
__LAB50 : 
__LAB55 : 
__TMPB1 := _NOT VFD_FAULT 
__TMPB2 := AUTO_MODE _AND __TMPB1 
__TMPB3 := _NOT VFD_RUN_CMD 
__TMPB2 := __TMPB2 _AND __TMPB3 
__TMPB2 := __TMPB2 _AND RESTART_ALLOWED 
_IF _NOT __TMPB2 _GOTO __LAB56 
__TMPT1 := __SYSVA_CYCLEDATE - SHUTDOWN_TIME 
__TMPB4 := __TMPT1 > DOWNTIME_TIME_PARAMETER 
_IF _NOT __TMPB4 _GOTO __LAB57 
__TMPB5 := _NOT RESTART_COMMAND 
_IF _NOT __TMPB5 _GOTO __LAB58 
VFD_CLEARFAULT := TRUE 
RESTART_COMMAND := TRUE 
_GOTO __LAB59 
__LAB58 : 
__LAB59 : 
_GOTO __LAB5a 
__LAB57 : 
RESTART_COMMAND := FALSE 
__TMPT1 := __SYSVA_CYCLEDATE - SHUTDOWN_TIME 
__TMPT2 := DOWNTIME_TIME_PARAMETER - __TMPT1 
TIME_UNTIL_STARTUP := __TMPT2 
_PUSH_PAR TIME_UNTIL_STARTUP 
__TMPM12 := _CALL ANY_TO_TIME 
TIME_UNTIL_STARTUP_STRING := __TMPM12 
_IF _NOT AUTO_MODE _GOTO __LAB5b 
__TMPM12 := __TMPM13 + TIME_UNTIL_STARTUP_STRING 
DEVICE_STATUS := __TMPM12 
_GOTO __LAB5c 
__LAB5b : 
__LAB5c : 
__LAB5a : 
_GOTO __LAB5d 
__LAB56 : 
__LAB5d : 
__TMPB1 := _NOT AUTO_MODE 
_IF _NOT __TMPB1 _GOTO __LAB5e 
RESTART_COMMAND := FALSE 
RESTART_ALLOWED := FALSE 
_GOTO __LAB5f 
__LAB5e : 
__LAB5f : 
__TMPB1 := START_COMMAND _OR START_BUTTON 
__TMPB1 := __TMPB1 _AND START_PERMISSIVE 
_IF _NOT __TMPB1 _GOTO __LAB60 
RESTART_ALLOWED := TRUE 
_GOTO __LAB61 
__LAB60 : 
__LAB61 : 
_IF _NOT STOP_COMMAND _GOTO __LAB62 
RESTART_ALLOWED := FALSE 
DEVICE_STATUS := __TMPM14 
VFD_RUN_CMD := FALSE 
_GOTO __LAB63 
__LAB62 : 
__LAB63 : 
__TMPB1 := _NOT VFD_RUN_CMD 
_IF _NOT __TMPB1 _GOTO __LAB64 
START_TIME_SET := FALSE 
VFD_START := FALSE 
_GOTO __LAB65 
__LAB64 : 
__LAB65 : 
