*-----------------------------------------------------------------------------
*  Toolchange Help - Service
*-----------------------------------------------------------------------------
*  Module Description
*    In manual mode it is possible to start several tool changer functions
*    by using a selected help file (SERVICE.HLP>.
*-----------------------------------------------------------------------------

#define /s    KL_absolute_with_software_limit_switch   K %010
#define /s    KL_absolute_without_software_limit_switch K %000
#define /s    KL_magazine_1                            K +1
#define /s    KL_number_pickup_position                K +3
#define /s    KL_pocket_table                          K +2
#define /s    KL_value_P1                              K +7
#define /s    KL_tool_number                           K +0
#define /s    KL_empty_pocket_T0                       K +0
#define /s    KL_line_0                                K +0
#define /s    KL_P0_pocket_spindle                     K +0

#define /s    ML_T0_selection_ok                       M
#define /s    ML_TC_pos_Z_put_out                      M
#define /s    ML_TC_pos_Z_put_in                       M
#define /s    ML_TC_pos_Y                              M
#define /s    ML_TC_pos_X_safe                         M
#define /s    ML_TC_pre_pos_X                          M
#define /s    ML_TC_pos_X                              M
#define /s    ML_T_pocket_table_read                   M
#define /s    ML_module_error                          M
#define /s    ML_empty_pocket_search                   M
#define /s    ML_TC_help_active                        M

#define /s /r ML_TC_arm_grippers_closed                M
#define /s /r ML_tool_lock_open                        M
#define /s /r ML_tool_lock_close                       M
#define /s /r ML_TC_pickup_put_out                     M
#define /s /r ML_TC_pickup_put_in                      M

#define /s    BL_step_help                             B
#define /s    BL_identifier                            B

#define /s    WL_stack_synchronize                     W

#include Mac_Lib.inc

EXTERN Absolute

GLOBAL TC_Help
GLOBAL Output_Restore
GLOBAL Output_Backup

;----------------------------
LBL TC_Help
;----------------------------

  LN     MG_TC_auto_active
  EMT

  CM     Basic_position

  L      PN_error_function_ok
  R      PN_error_function_ok

  L      NP_W270_help_file_line_number
  /      K+100
  ==     K+4
  =      ML_TC_help_active

  L      ML_TC_help_active
  XO     MG_TC_help
  CMT    Help_reset

  L      MG_manual_mode
  AN     MG_edit_mode
  O      MG_commissioning
  A      ML_TC_help_active
  =      MG_TC_help
  R      PN_error_TC_basic_position
  EMF

  L      NP_W270_help_file_line_number
  MOD    K+100
  <>     BL_step_help
  ON     MG_control_operational
  CMT    Help_reset

  L      NP_W270_help_file_line_number
  MOD    K+100
  =      BL_step_help

  LN     MG_control_operational
  EMT

  CASE   BL_step_help
    CM     EndOfModul                  ;00
    CM     S_TC_position               ;01
    CM     Z_posit_put_out             ;02
    CM     Z_posit_put_in              ;03
    CM     TC_tool_lock_open           ;04
    CM     TC_tool_lock_close          ;05
    CM     Pickup_put_out              ;06
    CM     Pickup_put_in               ;07
    CM     TC_unclamping               ;08
    CM     TC_clamping                 ;09
    CM     X_TC_pre_pos                ;10
    CM     X_TC_pos                    ;11
    CM     Y_P_spindle_T_pos           ;12
    CM     Y_Pn_plus_1_pos             ;13
    CM     Y_Pn_minus_1_pos            ;14
    CM     T0_selection                ;15
  ENDC

LBL EndOfModul

EM

;----------------------------
LBL S_TC_position                      ;01

  CM     Y_in_TC_Pos

  LN     ML_TC_pos_Y
  IFT
    CM     Z_in_posit_out

    LN     ML_TC_pos_Z_put_out
    =      MG_win_TC_pos_Z_put_out
  ENDI

  LN     MG_Sn_I_tool_clamped
  O      MG_Sn_I_tool_unclamped
  =      MG_win_tool_clamping

  L      MG_key_NC_start
  AN     MG_win_TC_pos_Z_put_out
  AN     MG_win_tool_clamping
  AN     MG_spindle_in_TC_position
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  A      MG_spindle_with_ROD
  S      MG_TC_spindle_orientation_on

  L      MG_spindle_in_TC_position
  ON     MG_spindle_with_ROD
  =      PN_error_function_ok

EM

;----------------------------
LBL Z_posit_put_out                    ;02

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  IFT
    LN     MG_Sn_I_tool_clamped
    O      MG_Sn_I_tool_unclamped
    =      MG_win_tool_clamping
    EMT
  ENDI

  CM     Z_in_posit_out

  L      ML_TC_pos_Z_put_out
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4122_strobe_PLC_posit_axis_Z
  EMT

  PS     KG_axis_Z
  PS     DG_TC_position_Z_put_out
  PS     DG_feed_PLC_Z
#if CFG_PLC_pos_Z_software_end_switch = "active"
  PS     KL_absolute_with_software_limit_switch
#else
  PS     KL_absolute_without_software_limit_switch
#endif
  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL Z_in_posit_out

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_Z_ref
  -      DG_TC_position_Z_put_out
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Z
  AN     PN_M4122_strobe_PLC_posit_axis_Z
  =      ML_TC_pos_Z_put_out

EM

;----------------------------
LBL Z_posit_put_in                     ;03

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  IFT
    LN     MG_Sn_I_tool_clamped
    O      MG_Sn_I_tool_unclamped
    =      MG_win_tool_clamping
    EMT
  ENDI

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  =      MG_win_TC_pos_S
  EMT

  CM     Z_in_posit_in

  L      ML_TC_pos_Z_put_in
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4122_strobe_PLC_posit_axis_Z
  EMT

  PS     KG_axis_Z
  PS     DG_TC_position_Z_put_in
  PS     DG_feed_PLC_Z
#if CFG_PLC_pos_Z_software_end_switch = "active"
  PS     KL_absolute_with_software_limit_switch
#else
  PS     KL_absolute_without_software_limit_switch
#endif
  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL Z_in_posit_in

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_Z_ref
  -      DG_TC_position_Z_put_in
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Z
  AN     PN_M4122_strobe_PLC_posit_axis_Z
  =      ML_TC_pos_Z_put_in

EM

;----------------------------
LBL TC_tool_lock_open                  ;04

#if CFG_magazine_tool_lock = "active"

  L      MG_key_NC_start
  S      O_tool_lock_open
  R      O_tool_lock_close

  L      MG_key_NC_start_n_pulse
  S      O_tool_lock_open
  S      O_tool_lock_close

  L      I_tool_lock_open
  AN     I_tool_lock_close
  S      O_tool_lock_open
  R      O_tool_lock_close
  =      PN_error_function_ok

#else

  L      MG_key_NC_start
  S      PN_error_function_not_active

#endif

EM

;----------------------------
LBL TC_tool_lock_close                 ;05

#if CFG_magazine_tool_lock = "active"

  CM     X_in_TC_pos_safe

  LN     ML_TC_pos_X_safe
  =      MG_win_TC_pre_pos_X

#if &O_TC_pickup_put_out < 1000
  L      I_TC_pickup_put_out
  ON     I_TC_pickup_put_in
  =      MG_win_pickup_put_in
#endif

  LN     MG_win_TC_pre_pos_X
  AN     MG_win_pickup_put_in
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  R      O_tool_lock_open
  S      O_tool_lock_close

  L      MG_key_NC_start_n_pulse
  S      O_tool_lock_open
  S      O_tool_lock_close

  LN     I_tool_lock_open
  A      I_tool_lock_close
  R      O_tool_lock_open
  S      O_tool_lock_close
  =      PN_error_function_ok

#else

  L      MG_key_NC_start
  S      PN_error_function_not_active

#endif

EM

;----------------------------
LBL Pickup_put_out                     ;06

#if &O_TC_pickup_put_out < 1000

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  =      MG_win_TC_pre_pos_X

#if CFG_magazine_tool_lock = "active"
  LN     I_tool_lock_open
  O      I_tool_lock_close
  =      MG_win_tool_lock_open
#endif

  LN     MG_win_tool_lock_open
  AN     MG_win_TC_pre_pos_X
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_pickup_put_out
  R      O_TC_pickup_put_in

  L      MG_key_NC_start_n_pulse
  S      O_TC_pickup_put_out
  S      O_TC_pickup_put_in

  L      I_TC_pickup_put_out
  AN     I_TC_pickup_put_in
  S      O_TC_pickup_put_out
  R      O_TC_pickup_put_in
  =      PN_error_function_ok

#else

  L      MG_key_NC_start
  S      PN_error_function_not_active

#endif

EM

;----------------------------
LBL Pickup_put_in                      ;07

#if &O_TC_pickup_put_out > 999

  L      MG_key_NC_start
  S      PN_error_function_not_active

#else

#if CFG_magazine_tool_lock = "active"
  LN     I_tool_lock_open
  O      I_tool_lock_close
  =      MG_win_tool_lock_open
#endif

  LN     MG_win_tool_lock_open
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  R      O_TC_pickup_put_out
  S      O_TC_pickup_put_in

  L      MG_key_NC_start_n_pulse
  S      O_TC_pickup_put_out
  S      O_TC_pickup_put_in

  LN     I_TC_pickup_put_out
  A      I_TC_pickup_put_in
  R      O_TC_pickup_put_out
  S      O_TC_pickup_put_in
  =      PN_error_function_ok

#endif

EM

;----------------------------
LBL TC_unclamping                      ;08

  L      MG_key_NC_start
  S      MG_Sn_O_tool_unclamping

  LN     MG_Sn_I_tool_clamped
  A      MG_Sn_I_tool_unclamped
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_clamping                        ;09

  L      MG_key_NC_start
  R      MG_Sn_O_tool_unclamping

  L      MG_Sn_I_tool_clamped
  AN     MG_Sn_I_tool_unclamped
  =      PN_error_function_ok

EM

;----------------------------
LBL X_TC_pre_pos                       ;10

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  CM     X_TC_in_pre_pos

  L      ML_TC_pre_pos_X
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4120_strobe_PLC_posit_axis_X
  EMT

  PS     KG_axis_X
  PS     DG_TC_pre_pos_X
  PS     DG_feed_PLC_X
#if CFG_PLC_pos_Y_software_end_switch = "active"
  PS     KL_absolute_with_software_limit_switch
#else
  PS     KL_absolute_without_software_limit_switch
#endif
  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL X_TC_in_pre_pos

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_X_ref
  -      DG_TC_pre_pos_X
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_X
  AN     PN_M4120_strobe_PLC_posit_axis_X
  =      ML_TC_pre_pos_X

EM

;----------------------------
LBL X_in_TC_pos_safe

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_X_ref
  -      DG_MP1030_pos_window_X
  <=     DG_TC_pre_pos_X
  AN     PN_M4120_strobe_PLC_posit_axis_X
  =      ML_TC_pos_X_safe

EM

;----------------------------
LBL Y_TC_pos

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Y
  =      PN_error_reference_necessary
  EMT

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  =      MG_win_TC_pos_S
  EMT

  CM     Z_in_posit_out
  CM     X_TC_in_pre_pos

  LN     ML_TC_pos_Z_put_out
  AN     ML_TC_pre_pos_X
  =      MG_win_TC_pos_Z_put_out
  EMT

  CM     Y_in_TC_Pos

  L      ML_TC_pos_Y
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4121_strobe_PLC_posit_axis_Y
  EMT

  PS     KG_axis_Y
  PS     DG_TC_pos_Y
  PS     DG_feed_PLC_Y
#if CFG_PLC_pos_Y_software_end_switch = "active"
  PS     KL_absolute_with_software_limit_switch
#else
  PS     KL_absolute_without_software_limit_switch
#endif
  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL Y_in_TC_Pos

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Y
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_Y_ref
  -      DG_TC_pos_Y
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Y
  AN     PN_M4121_strobe_PLC_posit_axis_Y
  =      ML_TC_pos_Y
  IFT
    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ENDI

EM

;----------------------------
LBL X_TC_pos                           ;11

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  =      MG_win_TC_pos_S
  EMT

  CM     Y_in_TC_Pos

  LN     ML_TC_pos_Y
  =      MG_win_TC_pos_Y
  EMT

  CM     X_in_TC_Pos

  L      ML_TC_pos_X
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4120_strobe_PLC_posit_axis_X
  EMT

  PS     KG_axis_X
  PS     DG_TC_position_X
  PS     DG_feed_PLC_X
#if CFG_PLC_pos_X_software_end_switch = "active"
  PS     KL_absolute_with_software_limit_switch
#else
  PS     KL_absolute_without_software_limit_switch
#endif
  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL X_in_TC_Pos

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  L      DG_position_axis_X_ref
  -      DG_TC_position_X
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_X
  AN     PN_M4120_strobe_PLC_posit_axis_X
  =      ML_TC_pos_X

EM

;----------------------------
LBL Y_P_spindle_T_pos                  ;12

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  IFT
    CM     Z_in_posit_out

    LN     ML_TC_pos_Z_put_out
    =      MG_win_TC_pos_Z_put_out
  ENDI

  LN     MG_win_TC_pos_Z_put_out
  A      MG_key_NC_start_p_pulse
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start_p_pulse
  ]
  IFT
    S      ML_empty_pocket_search

    CM     Pickup_values_read

  ENDI

  L      ML_T_pocket_table_read
  CMT    Y_TC_pos

  CM     Y_in_TC_Pos

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ==     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
  A      ML_TC_pos_Y
  R      ML_T_pocket_table_read
  =      PN_error_function_ok

EM

;----------------------------
LBL Y_Pn_plus_1_pos                    ;13

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  IFT
    CM     Z_in_posit_out

    LN     ML_TC_pos_Z_put_out
    =      MG_win_TC_pos_Z_put_out
  ENDI

  LN     MG_win_TC_pos_Z_put_out
  A      MG_key_NC_start_p_pulse
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start_p_pulse
  ]
  IFT
    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
    +      K+1
    =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket

    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    <=     K+0
    O[
      L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
      >      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_MP7261_TC_magazine_max_pocket
    ]
    IFT
      L      K+1
      =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    ENDI

    CM     Pickup_values_read

  ENDI

  L      ML_T_pocket_table_read
  CMT    Y_TC_pos

  CM     Y_in_TC_Pos

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ==     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
  A      ML_TC_pos_Y
  R      ML_T_pocket_table_read
  =      PN_error_function_ok

EM

;----------------------------
LBL Y_Pn_minus_1_pos                   ;14

  CM     X_TC_in_pre_pos

  LN     ML_TC_pre_pos_X
  IFT
    CM     Z_in_posit_out

    LN     ML_TC_pos_Z_put_out
    =      MG_win_TC_pos_Z_put_out
  ENDI

  LN     MG_win_TC_pos_Z_put_out
  A      MG_key_NC_start_p_pulse
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start_p_pulse
  ]
  IFT
    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
    -      K+1
    =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket

    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    <=     K+0
    O[
      L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
      >      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_MP7261_TC_magazine_max_pocket
    ]
    IFT
      L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_MP7261_TC_magazine_max_pocket
      =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    ENDI

    CM     Pickup_values_read

  ENDI

  L      ML_T_pocket_table_read
  CMT    Y_TC_pos

  CM     Y_in_TC_Pos

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ==     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
  A      ML_TC_pos_Y
  R      ML_T_pocket_table_read
  =      PN_error_function_ok

EM

;----------------------------
LBL T0_selection                       ;15

  L      ML_T0_selection_ok
  =      PN_error_function_ok

  LN     MG_key_NC_start_p_pulse
  EMT

  L      K+0
  =      NP_W264_tool_number
  =      WG_tool_in_spindle

  L      MG_marker_one
  S      PN_M4538_tool_selection_from_PLC_W264
  S      ML_T0_selection_ok
  S      MG_pocket_table_checking
  S      MG_tool_status_reading

EM

;----------------------------
LBL Pickup_values_read

  L      ML_T_pocket_table_read
  EMT

  RPLY   BL_identifier
  <>     K+0
  EMT

  SUBM   TC_pickup_position
  =      BL_identifier
  ==     K+0
  S      PN_error_submit_spawn_queue_full

EM

;----------------------------
LBL TC_pickup_position

  L      ML_empty_pocket_search
  R      ML_empty_pocket_search
  IFT
    PS     KL_pocket_table
    PS     KL_tool_number
    PS     KL_empty_pocket_T0
    PS     KL_line_0
    CM     9092
    PL     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    PL     WL_stack_synchronize

    M_display_module_error

    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    ==     KL_P0_pocket_spindle
    O      NP_M4203_error_module_9xxx
    S      PN_error_spindle_without_tool
    IFT
      L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
      =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
    ENDI
  ENDI

  L      K+0
  =X

  REPEAT
    PS     KL_pocket_table
    PS     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket

    LX
    +      KL_value_P1
    PSW

    CM     9093
    PL     DG_T_pocket_table_P1[X]
    PL     WL_stack_synchronize

    M_display_module_error

    L      NP_M4203_error_module_9xxx
    S      ML_module_error

    INCX

    LX
    >=     KL_number_pickup_position
  UNTILT

  L      DG_T_pocket_table_P1
  =      DG_TC_position_X

  L      DG_T_pocket_table_P2
  =      DG_TC_pos_Y

  L      DG_T_pocket_table_P3
  =      DG_TC_position_Z_put_in

  L      ML_module_error
  SN     ML_T_pocket_table_read
  IFT
    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
    =      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_nominal_pocket
  ENDI

EM

;----------------------------
LBL Basic_position

  L      MG_Sn_I_tool_clamped
  AN     MG_Sn_I_tool_unclamped
#if CFG_magazine_tool_lock = "active"
  AN     I_tool_lock_open
  A      I_tool_lock_close
#endif
#if &O_TC_pickup_put_out < 1000
  AN     I_TC_pickup_put_out
  A      I_TC_pickup_put_in
#endif
  =      MG_TC_standby_position

  L      MG_TC_automatic
  O      MG_TC_manual
  O      MG_TC_help
  O      MG_SK_TC_mag_load_active
  EMT

  LN     MG_TC_standby_position
  A      MG_power_delayed_on
  S      PN_error_TC_basic_position

  LN     MG_Sn_I_tool_clamped
  O      MG_Sn_I_tool_unclamped
  =      MG_win_tool_clamping

#if CFG_magazine_tool_lock = "active"
  L      I_tool_lock_open
  ON     I_tool_lock_close
  =      MG_win_tool_lock_close
#endif

#if &O_TC_pickup_put_out < 1000
  L      I_TC_pickup_put_out
  ON     I_TC_pickup_put_in
  =      MG_win_pickup_put_in
#endif

EM

;----------------------------
LBL Help_reset

  L      MG_marker_one
  R      PN_M4120_strobe_PLC_posit_axis_X
  R      PN_M4121_strobe_PLC_posit_axis_Y
  R      PN_M4122_strobe_PLC_posit_axis_Z
  R      ML_T0_selection_ok
  R      ML_empty_pocket_search
  R      ML_T_pocket_table_read
  R      PN_error_function_ok
  R      MG_win_TC_pos_X
  R      MG_win_TC_pre_pos_X
  R      MG_win_TC_pos_Y
  R      MG_win_TC_pre_pos_Y
  R      MG_win_TC_pos_Z_put_out
  R      MG_win_TC_pos_Z_put_in
  R      MG_win_TC_pos_S
  R      MG_win_tool_clamping
  R      MG_win_tool_unclamping
  R      MG_win_TC_magazine_close_guard
  R      MG_win_tool_lock_open
  R      MG_win_tool_lock_close
  R      MG_win_pickup_put_out
  R      MG_win_pickup_put_in

EM

;----------------------------
LBL Output_Restore

#ifdef $iTNC530Prog$
  L      NP_M4172_1st_PLC_run_after_power_on
  S      ML_TC_arm_gripper_close
  R      ML_tool_lock_open
  S      ML_tool_lock_close
  R      ML_TC_pickup_put_out
  S      ML_TC_pickup_put_in
#endif

  L      ML_TC_arm_grippers_closed
  =      O_TC_arm_grippers_close

#if CFG_magazine_tool_lock = "active"
  L      ML_tool_lock_open
  =      O_tool_lock_open

  L      ML_tool_lock_close
  =      O_tool_lock_close
#endif

#if &O_TC_pickup_put_out < 1000
  L      ML_TC_pickup_put_out
  =      O_TC_pickup_put_out

  L      ML_TC_pickup_put_in
  =      O_TC_pickup_put_in
#endif

EM

;----------------------------
LBL Output_Backup

  LN     I_ESA_control_operational
  R      O_TC_arm_grippers_close
  R      O_tool_lock_close
  R      O_TC_pickup_put_in
  EMT

  L      O_TC_arm_grippers_close
  =      ML_TC_arm_grippers_closed

#if CFG_magazine_tool_lock = "active"
  L      O_tool_lock_open
  =      ML_tool_lock_open

  L      O_tool_lock_close
  =      ML_tool_lock_close
#endif

#if &O_TC_pickup_put_out < 1000
  L      O_TC_pickup_put_out
  =      ML_TC_pickup_put_out

  L      O_TC_pickup_put_in
  =      ML_TC_pickup_put_in
#endif

EM
