*-----------------------------------------------------------------------------
*  Coolant inside/outside M07/M08
*-----------------------------------------------------------------------------
*  Module Description
*
*-----------------------------------------------------------------------------

#define /s    KL_runtime_from_MP                       K -1

#define /s    ML_key_pressed                           M
#define /s    ML_wash_gun_auto_off_enable              M
#define /s    ML_coolant_wash_down                     M
#define /s    ML_coolant_wash_down_on                  M
#define /s    ML_coolant_wash_down_off                 M
#define /s    ML_coolant_skimmer                       M
#define /s    ML_coolant_skimmer_on                    M
#define /s    ML_coolant_skimmer_off                   M
#define /s    ML_CTS_pressure_delay_detect             M
#define /s    ML_paper_filter_not_full                 M
#define /s    ML_clean_tank_level_low                  M

GLOBAL Coolant

;----------------------------
LBL Coolant
;----------------------------

  CM     Coolant_M7_M8_annular
  CM     Coolant_wash_down
  CM     Coolant_oil_skimmer

  L      O_coolant_M08_on
#if (KG_Coolant_motor & %0000000000000001) = %0000000000000001
  O      O_coolant_annular_on
#endif
#if (KG_Coolant_motor & %0000000000000010) = %0000000000000010
  O      O_coolant_M17_on
#endif
#if (KG_Coolant_motor & %0000000000000100) = %0000000000000100
  O      O_coolant_wash_down_on
#endif
#if (KG_Coolant_motor & %0000000000001000) = %0000000000001000
  O      O_coolant_transfer_on
#endif
#if (KG_Coolant_motor & %0000000000100000) = %0000000000010000
  O      O_coolant_M07_on
#endif
  =      O_coolant_on

EM

;----------------------------
LBL Coolant_M7_M8_annular
;----------------------------

  L      MG_M07_coolant_inside_on
  O      MG_M08_coolant_on
  O      MG_M09_coolant_off
  O      MG_M12_coolant_annular_on
  O      MG_M17_coolant_additional
  S      PN_M4092_quit_M_function

  L      MG_key_coolant_M07
  AN     ML_key_pressed
  XO     PN_M4041_M07_MK_status
  =      PN_M4041_M07_MK_status

  L      MG_key_coolant_M08
  AN     ML_key_pressed
  XO     PN_M4042_M08_MK_status
  =      PN_M4042_M08_MK_status

  L      MG_key_coolant_M17
  AN     ML_key_pressed
  XO     MG_SK_M17_coolant_additional
  =      MG_SK_M17_coolant_additional

  L      MG_coolant_side_with_annular
  A      MG_key_coolant_M08
  AN     ML_key_pressed
  XO     MG_SK_coolant_annular
  =      MG_SK_coolant_annular

  L      MG_key_dry_run
  AN     ML_key_pressed
  XO     MG_SK_dry_run
  =      MG_SK_dry_run

  L      MG_key_coolant_M07
  O      MG_key_coolant_M08
  O      MG_key_coolant_M17
  O      MG_key_dry_run
  =      ML_key_pressed

  L      MG_M07_coolant_inside_on
  S      PN_M4041_M07_MK_status

  L      PN_M4041_M07_MK_status
  AN     MG_release_M07_coolant_inside_on
  R      PN_M4041_M07_MK_status
  S      PN_error_release_M07_T_inactive

  L      MG_coolant_side_with_annular
  IFT
    L      MG_M08_coolant_on
    O      MG_M13_Spindle_right_coolant_on
    O      MG_M14_Spindle_left_coolant_on
    S      PN_M4042_M08_MK_status
    S      MG_SK_coolant_annular
  ELSE
    L      MG_M08_coolant_on
    O      MG_M13_Spindle_right_coolant_on
    O      MG_M14_Spindle_left_coolant_on
    S      PN_M4042_M08_MK_status
  ENDI

  L      MG_M12_coolant_annular_on
  S      MG_SK_coolant_annular

  L      MG_M17_coolant_additional
  S      MG_SK_M17_coolant_additional

  L      MG_M09_coolant_off
  O      MG_M15_Spindle_off_coolant_off
  O      MG_pulse_END_PGM_M02_M30
  O      MG_auto_manu_mode_change
  O      NP_M4073_strobe_TOOL_CALL
  O      PN_error_coolant_level_low
  ON     MG_control_operational
  R      PN_M4041_M07_MK_status
  R      PN_M4042_M08_MK_status
  R      MG_SK_coolant_annular
  R      MG_SK_M17_coolant_additional

  L      MG_pulse_END_PGM_M02_M30
  ON     MG_control_operational
  R      MG_SK_dry_run

  L      NP_M4002_S_nominal_0
  O      PN_M4008_S_nominal_off_status_inverse
  AN     NP_M4030_tapping_cycle_active
  AN     MG_key_coolant_without_spindle_turning
  O      NP_M4158_mode_block_scan
  O      MG_TC_manual
  O      MG_TC_help                    ;*DC
  O      MG_TC_automatic               ;*DC
  ON     I_tool_lock_close             ;*DC
  ON     I_circuit_breaker_ok          ;*DC
  ON     I_ESB_servo_drive_release
  ON     MG_servo_drive_release_1st_axes_group
  O      MG_enable_alternating_table
  O      MG_SK_dry_run
  AN     PN_error_coolant_level_low
  AN     PN_error_guard_open
  =      PN_M4040_M07_M08_M09_MK_status_inverse
;----------------------------
  L      PN_M4041_M07_MK_status
  AN     PN_M4040_M07_M08_M09_MK_status_inverse
  =      O_coolant_M07_on
;----------------------------
  L      PN_M4042_M08_MK_status
  AN     PN_M4040_M07_M08_M09_MK_status_inverse
  =      O_coolant_M08_on
;----------------------------
  L      MG_SK_coolant_annular
  AN     PN_M4040_M07_M08_M09_MK_status_inverse
  =      O_coolant_annular_on
;----------------------------
  LN     MG_SK_M17_coolant_additional
  R      ML_wash_gun_auto_off_enable

  L      MG_SK_M17_coolant_additional
  AN     ML_wash_gun_auto_off_enable
  IFT
    PS     K&TR_coolant_wash_gun_auto_off
    PS     KL_runtime_from_MP
    CM     9006

    L      MG_marker_one
    S      ML_wash_gun_auto_off_enable
  ENDI

  L      ML_wash_gun_auto_off_enable
  AN     TR_coolant_wash_gun_auto_off
  O      MG_manu_auto_mode_change
  R      MG_SK_M17_coolant_additional
  R      ML_wash_gun_auto_off_enable

  L      MG_SK_M17_coolant_additional
  AN     PN_error_coolant_level_low
  =      O_coolant_M17_on
;----------------------------
  LN     PN_M4041_M07_MK_status
  AN     PN_M4042_M08_MK_status
  R      PN_M4040_M07_M08_M09_MK_status_inverse
;----------------------------
  L      PN_M4041_M07_MK_status
  A      PN_M4040_M07_M08_M09_MK_status_inverse
  A      MG_clock_1_s
  O      O_coolant_M07_on
  O      MG_test_lamps
  =      O_lamp_coolant_M07
;----------------------------
  L      PN_M4042_M08_MK_status
  A      PN_M4040_M07_M08_M09_MK_status_inverse
  A      MG_clock_1_s
  O      O_coolant_M08_on
  O      MG_test_lamps
  =      O_lamp_coolant_M08
;----------------------------
  L      MG_SK_M17_coolant_additional  ;20120926
  A      MG_clock_1_s
  O      O_coolant_M17_on
  O      MG_test_lamps
  =      O_lamp_coolant_M17
;----------------------------
  LN     I_coolant_level_ok
  S      PN_error_coolant_level_low
;----------------------------
  LN     O_coolant_M07_on
  R      ML_CTS_pressure_delay_detect

  L      O_coolant_M07_on
  AN     ML_CTS_pressure_delay_detect
  IFT
    PS     K&TR_CTS_pressure_delay_detect
    PS     KL_runtime_from_MP
    CM     9006

    L      MG_marker_one
    S      ML_CTS_pressure_delay_detect
  ENDI

  L      ML_CTS_pressure_delay_detect
  AN     TR_CTS_pressure_delay_detect
  IFT
    L      I_no_paper_tape_detect
    S      PN_warning_no_paper_tape

    L      I_CTS_pressure_hi
    A      O_coolant_M07_on
    R      O_coolant_M07_on
    R      PN_M4041_M07_MK_status
    S      PN_error_CTS_pressure_hi
#if CFG_Coolant_CTS = "inactive"
    LN     I_paper_filter_level_low
    A      O_coolant_M07_on
    R      O_coolant_M07_on
    R      PN_M4041_M07_MK_status
    S      PN_error_CTS_pressure_low
#endif
#if CFG_Coolant_CTS = "CTS_2"
    LN     I_CTS_pressure_detect
    A      O_coolant_M07_on
    R      O_coolant_M07_on
    R      PN_M4041_M07_MK_status
    S      PN_error_CTS_pressure_low
#endif
  ENDI

#if CFG_Coolant_CTS = "CTS_3"
  LN     I_paper_filter_ok
  S      PN_error_CTS_system_error

  LN     I_paper_filter_ok
  ON     MG_control_operational
  ON     I_circuit_breaker_ok
  R      O_coolant_M07_on
  R      PN_M4041_M07_MK_status
  R      O_coolant_transfer_on
#endif
;----------------------------
#if CFG_Coolant_CTS = "CTS_1"
  L      I_coolant_level_low
  AN     ML_coolant_level_low
  IFT
    PS     K&TR_coolant_level_low
    PS     KL_runtime_from_MP
    CM     9006

    L      MG_marker_one
    S      ML_coolant_level_low
  ENDI

  L      ML_coolant_level_low
  AN     TR_coolant_level_low
  A      ML_paper_filter_not_full
  O      I_coolant_level_hi
  S      O_coolant_transfer_on

  L      I_paper_filter_level_hi
  ON     I_coolant_level_low
  ON     I_control_operational
  R      O_coolant_transfer_on

  LN     I_paper_filter_level_low
  ON     I_paper_filter_no_water
  S      ML_paper_filter_not_full

  L      I_paper_filter_level_hi
  R      ML_paper_filter_not_full

  LN     I_coolant_level_low
  R      ML_coolant_level_low

  L      I_coolant_level_hi
  S      PN_error_coolant_level_hi

  LN     I_paper_filter_no_water
  S      PN_error_paper_filter_level_low
#endif
;----------------------------
#if CFG_Coolant_CTS = "CTS_2"
  LN     I_paper_filter_level_hi
  AN     ML_clean_tank_level_low
  IFT
    PS     K&TR_clean_tank_level_low
    PS     KL_runtime_from_MP
    CM     9006

    PS     K&TR_clean_tank_level_low_pump_stop
    PS     KL_runtime_from_MP
    CM     9006

    L      MG_marker_one
    S      ML_clean_tank_level_low
  ENDI

  L      ML_clean_tank_level_low
  AN     TR_clean_tank_level_low
  S      O_coolant_transfer_on

  L      I_paper_filter_level_hi
  R      O_coolant_transfer_on

  L      ML_clean_tank_level_low
  AN     TR_clean_tank_level_low_pump_stop
  O      I_paper_filter_level_low
  A      O_coolant_M07_on
  S      PN_error_coolant_level_low

  L      ML_clean_tank_level_low
  AN     TR_clean_tank_level_low_pump_stop
  O      PN_M4040_M07_M08_M09_MK_status_inverse
  O      I_paper_filter_level_low
  R      O_coolant_M07_on
  R      PN_M4041_M07_MK_status
  R      O_coolant_transfer_on

  L      I_paper_filter_level_hi
  R      ML_clean_tank_level_low
#endif

EM

;----------------------------
LBL Coolant_wash_down
;----------------------------

  L      MG_M37_coolant_wash_down_on
  O      MG_M38_coolant_wash_down_off
  S      PN_M4092_quit_M_function

  L      MG_M37_coolant_wash_down_on
  S      MG_SK_coolant_wash_down

  L      MG_M38_coolant_wash_down_off
  O      MG_pulse_internal_stop
  O      MG_guard_close_open_pulse
  O      MG_pulse_END_PGM_M02_M30
  O      MG_auto_manu_mode_change
  ON     MG_control_operational
  R      MG_SK_coolant_wash_down

  L      NP_M4153_mode_program_run_single_block
  O      NP_M4154_mode_program_run_full_sequence
  A      NP_M4176_control_in_operation_on_or_flashes
  AN     NP_M4175_control_in_operation_flashes
  A      MG_wash_down_with_timer_on_off
  IFT
    LN     ML_coolant_wash_down_on
    IFT
      PS     K&TR_coolant_wash_down_on
      PS     KL_runtime_from_MP
      CM     9006

      L      MG_marker_one
      S      ML_coolant_wash_down_on
      S      ML_coolant_wash_down
    ENDI

    L      ML_coolant_wash_down_on
    AN     TR_coolant_wash_down_on
    AN     ML_coolant_wash_down_off
    IFT
      PS     K&TR_coolant_wash_down_off
      PS     KL_runtime_from_MP
      CM     9006

      L      MG_marker_one
      S      ML_coolant_wash_down_off
      R      ML_coolant_wash_down
    ENDI

    L      ML_coolant_wash_down_off
    AN     TR_coolant_wash_down_off
    R      ML_coolant_wash_down_on
    R      ML_coolant_wash_down_off
  ELSE
    L      MG_marker_one
    R      ML_coolant_wash_down
    R      ML_coolant_wash_down_on
    R      ML_coolant_wash_down_off
  ENDI

  L      MG_SK_coolant_wash_down
  O      ML_coolant_wash_down
  AN     MG_TC_manual
  AN     MG_TC_help
  AN     MG_TC_automatic
  A      I_tool_lock_close
  A      I_circuit_breaker_ok
  AN     PN_error_coolant_level_low
  =      O_coolant_wash_down_on
  =      O_coolant_wash_down_on_2

EM

;----------------------------
LBL Coolant_oil_skimmer
;----------------------------

  LN     MG_skimmer_without_timer_on_off
  IFT
    LN     ML_coolant_skimmer_on
    IFT
      PS     K&TR_coolant_skimmer_on   ;T224
      PS     KL_runtime_from_MP
      CM     9006

      L      MG_marker_one
      S      ML_coolant_skimmer_on
      S      ML_coolant_skimmer
    ENDI

    L      ML_coolant_skimmer_on
    AN     TR_coolant_skimmer_on
    AN     ML_coolant_skimmer_off
    IFT
      PS     K&TR_coolant_skimmer_off  ;T225
      PS     KL_runtime_from_MP
      CM     9006

      L      MG_marker_one
      S      ML_coolant_skimmer_off
      R      ML_coolant_skimmer
    ENDI

    L      ML_coolant_skimmer_off
    AN     TR_coolant_skimmer_off
    R      ML_coolant_skimmer_on
    R      ML_coolant_skimmer_off
  ENDI

  LN     MG_control_operational
  R      ML_coolant_skimmer
  R      ML_coolant_skimmer_on
  R      ML_coolant_skimmer_off

  L      MG_SK_oil_skimmer
  O      ML_coolant_skimmer
  A      MG_control_operational
  =      O_coolant_skimmer

EM
