*-----------------------------------------------------------------------------
*  NC Start NC Stop
*-----------------------------------------------------------------------------
*  Module Description
*
*-----------------------------------------------------------------------------

#define /s    ML_key_pressed                           M

#include Mac_Lib.inc

GLOBAL NC_start_stop

;----------------------------
LBL NC_start_stop
;----------------------------

  L      MG_key_NC_start
  AN     ML_key_pressed
  =      MG_key_NC_start_p_pulse

  LN     MG_key_NC_start
  A      ML_key_pressed
  =      MG_key_NC_start_n_pulse

  L      MG_key_NC_stop
  A      PN_M4560_NC_stop_0_active
  =      MG_key_NC_stop_p_pulse

*$WS check pulse
  L      MG_key_NC_start_p_pulse
  O      MG_NC_start_from_reference
  O      NC_start_from_autostart
  O      MG_energy_opt_warmup_pgm_on
  A      MG_power_delayed_on
  AN     MG_TC_help
  AN     MG_PC_help
  AN     MG_test_run_mode
  =      PN_M4564_NC_start

  L      DG_keys_inhibit
  <>     K+0
  O      MG_guard_open
  O      MG_start_blocked_lubrication
  O      MG_start_blocked_emergency_stop_test
  A      MG_automatic_mode
  O      MG_start_blocked_reference
  O      MG_start_blocked_emergency_stop_test
  O[
    L      NP_M4153_mode_program_run_single_block
    A      MG_NC_block_read_interlock
  ]
  R      PN_M4564_NC_start

  L      MG_key_NC_stop
  =N     PN_M4560_NC_stop_0_active

  L      MG_key_NC_start
  =      ML_key_pressed

  L      MG_M00_programmed_stop
  O      MG_M01_conditional_stop
  O      MG_M02_END_program
  O      MG_M30_END_program
  S      PN_M4092_quit_M_function

  L      MG_M00_programmed_stop
  AN     NP_M4158_mode_block_scan
  S      MG_programmed_stop_M00_active

  L      MG_M01_conditional_stop
  AN     NP_M4158_mode_block_scan
  S      MG_conditional_stop_M01_active

  L      MG_key_NC_start_p_pulse
  AN     MG_guard_open
  O      MG_auto_manu_mode_change
  O      MG_pulse_internal_stop
  O      MG_pulse_CE_key
  ON     MG_control_operational
  R      MG_programmed_stop_M00_active
  R      MG_conditional_stop_M01_active

  L      MG_programmed_stop_M00_active
  AN     MG_guard_open
  =      PN_error_M00_programmed_stop

  L      MG_conditional_stop_M01_active
  AN     MG_guard_open
  =      PN_error_M01_conditional_stop

  LN     MG_TC_interruption
  ON     MG_interrupt_alternating_table
  A      MG_control_in_operation_on
  O[
    L      MG_manual_mode
    A      MG_axes_in_motion
  ]
  O      MG_test_lamps
  O      MG_key_NC_start
  =      O_lamp_NC_start

  LN     O_lamp_NC_start
  O      MG_test_lamps
  O      MG_key_NC_stop
  =      O_lamp_NC_stop

  L      NP_M4175_control_in_operation_flashes
  A      MG_clock_1_s
  A      MG_automatic_mode
  S      O_lamp_NC_start

;Auto start

  L      NP_M4183_time_auto_start_expired
  IFT
    LN     I_ESA_control_operational
    =      MG_power_on_AUTOSTART_on

    L      NP_M4178_external_emergency_stop_active
    A      I_ESA_control_operational
    IFT
      PS     KG_key_CE
      CM     9180
      PLX

   M_display_module_error
    ENDI

    L      MG_power_delayed_on
    AN     MG_control_in_operation_on
    =      NC_start_from_autostart

    L      MG_control_in_operation_on
    ON     MG_automatic_mode
    R      NP_M4183_time_auto_start_expired
  ENDI

EM
