*-----------------------------------------------------------------------------
*  Guard with and without safety guard locking
*-----------------------------------------------------------------------------
*  Module Description
*    use on guards without safety guard locking also the following inputs
*      - I_guard_1_closed_locked
*      - I_guard_1_closed
*      - I_guard_2_closed_locked
*      - I_guard_2_closed
*
*
*-----------------------------------------------------------------------------

#define /s    ML_key_pressed                           M
#define /s    ML_guard_1_has_been_opened               M
#define /s    ML_guard_2_has_been_opened               M
#define /s    ML_guard_test_ok                         M
#define /s    ML_END_PGM_M02_M30                       M
#define /s    ML_guard_1_closed                        M
#define /s    ML_guard_2_closed                        M
#define /s    ML_guard_close_open                      M
#define /s    ML_guard_open_close                      M

GLOBAL Guard

;----------------------------
LBL Guard
;----------------------------

  L      MG_guard_inactive
  ON     MG_machine_parameter_are_read
  EMT

  L      I_guard_1_closed_locked
  AN     ML_guard_open_close
  =      MG_guard_open_close_pulse
  S      ML_guard_open_close
  R      ML_guard_close_open

  LN     I_guard_1_closed_locked
  AN     ML_guard_close_open
  =      MG_guard_close_open_pulse
  S      ML_guard_close_open
  R      ML_guard_open_close

#if CFG_pallet_changer = "Alternat_table"
  LN     MG_guard_1_closed_locked
  ON     MG_guard_2_closed_locked
#else
  LN     I_guard_1_closed_locked
  ON     I_guard_2_closed_locked
#endif
  AN     O_power_on
  A      MG_control_operational
  O      O_guard_1_unlock
  =      PN_error_guard_open
  =      MG_guard_open

  L      MG_TC_manual
  O      I_HRxx0_key_permissive_mode
  R      PN_error_guard_open

;  L      I_guard_1_closed
;  AN     ML_guard_1_closed
;  R      O_guard_1_unlock
;  R      O_guard_2_unlock

  L      MG_guard_open_close_pulse
  R      O_guard_1_unlock
  R      O_guard_2_unlock

  L      I_guard_1_closed
  =      ML_guard_1_closed

;  L      I_guard_2_closed
;  AN     ML_guard_2_closed
;  R      O_guard_1_unlock
;  R      O_guard_2_unlock

  L      I_guard_2_closed
  =      ML_guard_2_closed

  L      O_guard_1_unlock
  O      O_guard_2_unlock
  A      MG_key_guard_unlock
  AN     ML_key_pressed
  R      O_guard_1_unlock
  R      O_guard_2_unlock

  L      MG_pulse_END_PGM_M02_M30
  A      MG_auto_guard_unlock_on_END_PGM
  S      ML_END_PGM_M02_M30

  L      MG_automatic_mode
  AN     MG_control_in_operation_on
  O      MG_manual_mode
  O      MG_TC_manual
  A      MG_key_guard_unlock
  O      PN_error_tool_unclamping
  O      ML_END_PGM_M02_M30
  AN     MG_spindle_reference_active
  A[
    L      MG_spindle_stand_still
    ON     MG_spindle_active
  ]
  AN     MG_axes_in_motion
  O[
    L      O_release_special_mode
    A      MG_key_guard_unlock
  ]
  AN     MG_emergency_stop_test_active
  R      ML_END_PGM_M02_M30
  S      O_guard_1_unlock
  S      O_guard_2_unlock

  L      O_guard_1_unlock              ;20120926
  O      O_guard_2_unlock
  A      MG_clock_1_s
  =      O_lamp_guard_1_unlock

#if CFG_pallet_changer = "Alternat_table"
#if CFG_Simulation = "inactive"
  L      MG_alternating_table_on
  A      MG_axis_limit_2
  AN     MG_new_workpiece_table_1
  S      O_guard_1_unlock

  L      MG_alternating_table_on
  A      MG_axis_limit_1
  AN     MG_new_workpiece_table_2
  S      O_guard_2_unlock
#endif
#endif

  L      MG_key_guard_unlock
  =      ML_key_pressed

  L      MG_SLS_operating_mode_2_set_up
  O      MG_SLS_operating_mode_3
  R      PN_error_guard_open

  L      MG_SLS_operating_mode_2_set_up
  O      MG_SLS_operating_mode_3
  A[
    L      I_HRxx0_key_permissive_mode
    A      NP_M4151_mode_electronic_handwheel
    O      MG_key_permissive_mode
  ]
  O      MG_SLS_operating_mode_4
  =      O_release_special_mode
  =      O_lamp_special_mode
  IFT
    LN     MG_TC_automatic
    AN     PN_M4041_M07_MK_status
    R      MG_guard_open
    R      PN_error_guard_open

    L      MG_TC_automatic
    R      O_release_special_mode

    L      PN_error_guard_open
    ON     MG_guard_open
    A      MG_clock_1_s
    R      O_lamp_special_mode
  ENDI

#if CFG_guard_test_powered_on_inactive = "inactive"
  L      ML_guard_test_ok
  EMT

  LN     I_guard_1_closed
  S      ML_guard_1_has_been_opened

  LN     ML_guard_1_has_been_opened
  S      O_guard_1_unlock

#if &I_guard_2_closed < 1000
  LN     I_guard_2_closed
  S      ML_guard_2_has_been_opened
#else
  LN     ML_guard_2_has_been_opened
  S      ML_guard_2_has_been_opened
#endif

  LN     ML_guard_2_has_been_opened
  S      O_guard_2_unlock

  L      I_guard_1_closed_locked
  A      I_guard_2_closed_locked
  A      ML_guard_1_has_been_opened
  A      ML_guard_2_has_been_opened
  S      ML_guard_test_ok
#endif

EM
