*-----------------------------------------------------------------------------
*  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    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                              M
#define /s    ML_TC_arm_has_been_spindle_pos           M
#define /s    ML_TC_arm_has_been_magazin_pos           M
#define /s    ML_TC_help_active                        M

#define /s /r ML_TC_arm_grippers_closed                M
#define /s /r ML_TC_arm_gripper_1_open                 M
#define /s /r ML_TC_arm_gripper_2_open                 M
#define /s /r ML_TC_arm_put_in                         M
#define /s /r ML_TC_arm_put_out                        M
#define /s /r ML_TC_arm_turn_ccw                       M
#define /s /r ML_TC_arm_turn_cw                        M
#define /s /r ML_tool_lock_open                        M
#define /s /r ML_tool_lock_close                       M

#define /s    BL_step_help                             B

#include Mac_Lib.inc

EXTERN Absolute
EXTERN TC_mag_cw_turn
EXTERN TC_mag_ccw_turn

GLOBAL TC_Help
GLOBAL Output_Restore
GLOBAL Output_Backup

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

  LN     MG_TC_auto_active
  EMT

  CM     Basic_position

#if CFG_TC_transport_carriage = "active"
  L      I_TC_arm_spindle_pos
  S      ML_TC_arm_has_been_spindle_pos
  R      ML_TC_arm_has_been_magazin_pos

  L      I_TC_arm_magazine_pos
  R      ML_TC_arm_has_been_spindle_pos
  S      ML_TC_arm_has_been_magazin_pos

  L      ML_TC_arm_has_been_spindle_pos
  O      ML_TC_arm_has_been_magazin_pos
  O      O_TC_arm_to_basic_position
  A      I_TC_arm_basic_pos
  R      ML_TC_arm_has_been_spindle_pos
  R      ML_TC_arm_has_been_magazin_pos
  R      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position
  R      O_TC_arm_to_basic_position

  L      O_TC_arm_to_basic_position
  A      ML_TC_arm_has_been_spindle_pos
  R      O_TC_arm_to_spindle_position
  S      O_TC_arm_to_magazine_position

  L      O_TC_arm_to_basic_position
  A      ML_TC_arm_has_been_magazin_pos
  S      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position
#endif

  L      PN_error_function_ok
  R      PN_error_function_ok

  L      NP_W270_help_file_line_number
  /      K+100
  ==     K+2
  =      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

#if CFG_TC_transport_carriage = "inactive"

  CASE   BL_step_help
    CM     EndOfModul                  ;00
    CM     S_TC_position               ;01
    CM     Z_TC_posit_start            ;02
    CM     Y_TC_posit_start            ;03
    CM     X_TC_posit_start            ;04
    CM     TC_tool_lock_open           ;05
    CM     TC_tool_lock_close          ;06
    CM     TC_gripper_close            ;07
    CM     TC_gripper_open             ;08
    CM     Tool_unclamping             ;09
    CM     Tool_clamping               ;10
    CM     TC_arm_put_out              ;11
    CM     TC_arm_put_in               ;12
    CM     TC_arm_cw                   ;13
    CM     TC_arm_ccw                  ;14
    CM     TC_magazine_cw              ;15
    CM     TC_magazine_ccw             ;16
    CM     TC_magazine_ref             ;17
    CM     T0_selection                ;18
  ENDC

#else

  CASE   BL_step_help
    CM     EndOfModul                  ;00
    CM     S_TC_position               ;01
    CM     Z_TC_posit_start            ;02
    CM     Y_TC_posit_start            ;03
    CM     X_TC_posit_start            ;04
    CM     TC_tool_lock_open           ;05
    CM     TC_tool_lock_close          ;06
    CM     T_gripper_spi_open          ;07
    CM     T_gripper_spi_close         ;08
    CM     T_gripper_mag_open          ;09
    CM     T_gripper_mag_close         ;10
    CM     Tool_unclamping             ;11
    CM     Tool_clamping               ;12
    CM     T_arm_to_spindle            ;13
    CM     T_arm_to_magazine           ;14
    CM     Arm_to_basic                ;15
    CM     TC_arm_put_out              ;16
    CM     TC_arm_put_in               ;17
    CM     TC_arm_cw                   ;18
    CM     TC_arm_ccw                  ;19
    CM     TC_magazine_cw              ;20
    CM     TC_magazine_ccw             ;21
    CM     TC_magazine_ref             ;22
    CM     T0_selection                ;23
  ENDC

#endif

LBL EndOfModul

EM

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

  LN     MG_Sn_I_tool_clamped
  O      MG_Sn_I_tool_unclamped
  =      MG_win_tool_clamping

#if TC_gripper = &active
#if CFG_TC_transport_carriage = "inactive"
  LN     I_TC_arm_grippers_opened
  =      MG_win_TC_grippers_open
#else
  L      I_TC_arm_cw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    AN     I_TC_arm_gripper_2_opened
  ]
  AN     I_TC_arm_put_out
  =      MG_win_TC_gripper_spi_open
#endif
#endif

  L      MG_key_NC_start
  AN     MG_win_tool_clamping
  AN     MG_win_TC_grippers_open
  AN     MG_win_TC_gripper_spi_open
  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_TC_posit_start                   ;02

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  CM     Z_in_TC_Pos

  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_TC_Pos

  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 Y_TC_posit_start                   ;03

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Y
  =      PN_error_reference_necessary
  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

EM

;----------------------------
LBL X_TC_posit_start                   ;04

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  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 TC_tool_lock_open                  ;05

#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                 ;06

#if CFG_magazine_tool_lock = "active"

  L      I_TC_arm_put_out
  ON     I_TC_arm_put_in
  =      MG_win_TC_arm_put_in

  LN     I_TC_arm_cw
  XO     I_TC_arm_ccw
  =      MG_win_TC_arm_turn

  LN     MG_win_TC_arm_put_in
  AN     MG_win_TC_arm_turn
  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

#if CFG_TC_transport_carriage = "inactive"

;----------------------------
LBL TC_gripper_close                   ;07

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  =      MG_win_TC_pos_S

  L      MG_key_NC_start
  AN     MG_win_TC_pos_S
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_arm_grippers_close

  LN     I_TC_arm_grippers_opened
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_gripper_open                    ;08

  L      MG_key_NC_start
  R      O_TC_arm_grippers_close

  L      I_TC_arm_grippers_opened
  =      PN_error_function_ok

EM
#else

;----------------------------
LBL T_gripper_spi_open                 ;05

  L      MG_key_NC_start
  IFT
    L      I_TC_arm_cw
    S      O_TC_arm_gripper_1_open

    L      I_TC_arm_ccw
    S      O_TC_arm_gripper_2_open
  ENDI

  L      I_TC_arm_cw
  A      I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    A      I_TC_arm_gripper_2_opened
  ]
  =      PN_error_function_ok

EM

;----------------------------
LBL T_gripper_spi_close                ;06

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  A      I_TC_arm_spindle_pos
  =      MG_win_TC_pos_S

  LN     MG_win_TC_pos_S
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  IFT
    L      I_TC_arm_cw
    R      O_TC_arm_gripper_1_open

    L      I_TC_arm_ccw
    R      O_TC_arm_gripper_2_open
  ENDI

  L      I_TC_arm_cw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    AN     I_TC_arm_gripper_2_opened
  ]
  =      PN_error_function_ok

EM

;----------------------------
LBL T_gripper_mag_open                 ;07

  L      MG_key_NC_start
  IFT
    L      I_TC_arm_ccw
    S      O_TC_arm_gripper_1_open

    L      I_TC_arm_cw
    S      O_TC_arm_gripper_2_open
  ENDI

  L      I_TC_arm_ccw
  A      I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_cw
    A      I_TC_arm_gripper_2_opened
  ]
  =      PN_error_function_ok

EM

;----------------------------
LBL T_gripper_mag_close                ;08

  L      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  IFT
    L      I_TC_arm_ccw
    R      O_TC_arm_gripper_1_open

    L      I_TC_arm_cw
    R      O_TC_arm_gripper_2_open
  ENDI

  L      I_TC_arm_ccw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_cw
    AN     I_TC_arm_gripper_2_opened
  ]
  =      PN_error_function_ok

EM


;----------------------------
LBL T_arm_to_spindle                   ;09

  LN     I_TC_arm_cw
  XO     I_TC_arm_ccw
  =      MG_win_TC_arm_turn

  L      I_TC_arm_cw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    AN     I_TC_arm_gripper_2_opened
  ]
  AN     I_TC_arm_put_out
  =      MG_win_TC_gripper_spi_open

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
  =      MG_win_TC_pos_S

  LN     MG_win_TC_arm_turn
  AN     MG_win_TC_gripper_spi_open
  AN     MG_win_TC_pos_S
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position
  R      O_TC_arm_to_basic_position

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position

  L      I_TC_arm_spindle_pos
  AN     I_TC_arm_magazine_pos
  AN     I_TC_arm_basic_pos
  S      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position
  =      PN_error_function_ok

EM

;----------------------------
LBL T_arm_to_magazine                  ;09

  LN     I_TC_arm_cw
  XO     I_TC_arm_ccw
  =      MG_win_TC_arm_turn

  L      I_TC_arm_ccw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_cw
    AN     I_TC_arm_gripper_2_opened
  ]
  AN     I_TC_arm_put_out
  =      MG_win_TC_gripper_mag_open

  LN     MG_win_TC_arm_turn
  AN     MG_win_TC_gripper_mag_open
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  R      O_TC_arm_to_spindle_position
  S      O_TC_arm_to_magazine_position
  R      O_TC_arm_to_basic_position

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position

  LN     I_TC_arm_spindle_pos
  A      I_TC_arm_magazine_pos
  AN     I_TC_arm_basic_pos
  R      O_TC_arm_to_spindle_position
  S      O_TC_arm_to_magazine_position
  =      PN_error_function_ok

EM

;----------------------------
LBL Arm_to_basic                       ;09

  LN     I_TC_arm_cw
  XO     I_TC_arm_ccw
  =      MG_win_TC_arm_turn

  L      I_TC_arm_cw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    AN     I_TC_arm_gripper_2_opened
  ]
  AN     I_TC_arm_put_out
  A      ML_TC_arm_has_been_spindle_pos
  =      MG_win_TC_gripper_spi_open

  L      I_TC_arm_ccw
  AN     I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_cw
    AN     I_TC_arm_gripper_2_opened
  ]
  AN     I_TC_arm_put_out
  A      ML_TC_arm_has_been_magazin_pos
  =      MG_win_TC_gripper_mag_open

  LN     MG_win_TC_arm_turn
  AN     MG_win_TC_gripper_spi_open
  AN     MG_win_TC_gripper_mag_open
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_arm_to_basic_position

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_to_basic_position
  R      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position

  LN     I_TC_arm_spindle_pos
  AN     I_TC_arm_magazine_pos
  A      I_TC_arm_basic_pos
  R      O_TC_arm_to_basic_position
  R      O_TC_arm_to_spindle_position
  R      O_TC_arm_to_magazine_position
  =      PN_error_function_ok

EM

#endif

;----------------------------
LBL Tool_unclamping                    ;09

  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 Tool_clamping                      ;10

  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 TC_arm_put_out                     ;11

  L      MG_key_NC_start
  R      O_TC_arm_put_in
  S      O_TC_arm_put_out

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_put_in
  R      O_TC_arm_put_out

  LN     I_TC_arm_put_in
  A      I_TC_arm_put_out
  R      O_TC_arm_put_in
  S      O_TC_arm_put_out
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_arm_put_in                      ;12

  LN     MG_spindle_in_TC_position
  A      MG_spindle_with_ROD
#if CFG_TC_transport_carriage = "active"
  AN     I_TC_arm_magazine_pos
  AN     I_TC_arm_basic_pos
#endif
  =      MG_win_TC_pos_S

  LN     MG_win_TC_pos_S
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_arm_put_in
  R      O_TC_arm_put_out

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_put_in
  R      O_TC_arm_put_out

  L      I_TC_arm_put_in
  AN     I_TC_arm_put_out
  S      O_TC_arm_put_in
  R      O_TC_arm_put_out
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_arm_cw                          ;13

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

  LN     I_TC_arm_put_out
  O      I_TC_arm_put_in
  =      MG_win_TC_arm_put_out

  LN     MG_win_TC_arm_put_out
  AN     MG_win_tool_lock_open
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  R      O_TC_arm_turn_ccw
  S      O_TC_arm_turn_cw

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_turn_ccw
  R      O_TC_arm_turn_cw

  LN     I_TC_arm_ccw
  A      I_TC_arm_cw
  R      O_TC_arm_turn_ccw
  S      O_TC_arm_turn_cw
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_arm_ccw                         ;14

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

  LN     I_TC_arm_put_out
  O      I_TC_arm_put_in
  =      MG_win_TC_arm_put_out

  LN     MG_win_TC_arm_put_out
  AN     MG_win_tool_lock_open
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_TC_arm_turn_ccw
  R      O_TC_arm_turn_cw

  L      MG_key_NC_start_n_pulse
  R      O_TC_arm_turn_ccw
  R      O_TC_arm_turn_cw

  L      I_TC_arm_ccw
  AN     I_TC_arm_cw
  S      O_TC_arm_turn_ccw
  R      O_TC_arm_turn_cw
  =      PN_error_function_ok

EM

;----------------------------
LBL TC_magazine_cw                     ;15

#if CFG_TC_transport_carriage = "inactive"
#if TC_gripper = &active
  LN     I_TC_arm_grippers_opened
  AN     I_TC_arm_middle_pos
  =      MG_win_TC_grippers_open
#endif
#else
  LN     I_TC_arm_spindle_pos
  AN     I_TC_arm_basic_pos
  =      MG_win_TC_arm_standby
#endif

  LN     I_TC_magazine_guard_closed
  =      MG_win_TC_magazine_close_guard

  LN     MG_win_TC_magazine_close_guard
  AN     MG_win_TC_grippers_open
  AN     MG_win_TC_arm_standby
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  CMT    TC_mag_cw_turn

EM

;----------------------------
LBL TC_magazine_ccw                    ;16

#if CFG_TC_transport_carriage = "inactive"
#if TC_gripper = &active
  LN     I_TC_arm_grippers_opened
  AN     I_TC_arm_middle_pos
  =      MG_win_TC_grippers_open
#endif
#else
  LN     I_TC_arm_spindle_pos
  AN     I_TC_arm_basic_pos
  =      MG_win_TC_arm_standby
#endif

  LN     I_TC_magazine_guard_closed
  =      MG_win_TC_magazine_close_guard

  LN     MG_win_TC_magazine_close_guard
  AN     MG_win_TC_grippers_open
  AN     MG_win_TC_arm_standby
  A      MG_key_NC_start
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  CMT    TC_mag_ccw_turn

EM

;----------------------------
LBL TC_magazine_ref                    ;17

#if Tool_magazine = &Pulse
#if TC_magazine_reference_sensor = &active
  LN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_reference_necessary
  =      PN_error_function_ok

  L      MG_key_NC_start_p_pulse
  S      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_reference_necessary
  S      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start

#else
  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ==     K+1
  A[
    L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_2_pocket
    ==     K+1
  ]
  =      PN_error_function_ok
  R      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_reference_necessary

  L      MG_key_NC_start_p_pulse
  =      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_I_WZ_Magazin_Referenz

#endif
#endif

#if Tool_magazine = &PLC_axis
*$WS Referenzaufnahme asynchrone Achse über Modul
#endif
EM

;----------------------------
LBL T0_selection                       ;18

  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 Basic_position

  L      MG_Sn_I_tool_clamped
  AN     MG_Sn_I_tool_unclamped
  AN     I_TC_arm_put_out
  A      I_TC_arm_put_in
  A[
    L      I_TC_arm_cw
    XO     I_TC_arm_ccw
  ]
#if CFG_magazine_tool_lock = "active"
  AN     I_tool_lock_open
  A      I_tool_lock_close
#endif
#if CFG_TC_transport_carriage = "inactive"
#if TC_gripper = &active
  A      I_TC_arm_grippers_opened
#endif
#else
#if TC_gripper = &active
  AN     I_TC_arm_gripper_1_opened
  AN     I_TC_arm_gripper_2_opened
#endif
  AN     I_TC_arm_spindle_pos
  AN     I_TC_arm_magazine_pos
  A      I_TC_arm_basic_pos
#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

  L      I_TC_arm_put_out
  ON     I_TC_arm_put_in
  =      MG_win_TC_arm_put_in

  LN     I_TC_arm_cw
  XO     I_TC_arm_ccw
  =      MG_win_TC_arm_turn


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

#if CFG_TC_transport_carriage = "inactive"
#if TC_gripper = &active
  LN     I_TC_arm_grippers_opened
  =      MG_win_TC_grippers_open
#endif
#else
#if TC_gripper = &active
  L      I_TC_arm_cw
  A      I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_ccw
    A      I_TC_arm_gripper_2_opened
  ]
  =      MG_win_TC_gripper_spi_close

  L      I_TC_arm_ccw
  A      I_TC_arm_gripper_1_opened
  O[
    L      I_TC_arm_cw
    A      I_TC_arm_gripper_2_opened
  ]
  =      MG_win_TC_gripper_mag_close
#endif

  L      I_TC_arm_spindle_pos
  O      I_TC_arm_magazine_pos
  ON     I_TC_arm_basic_pos
  =      MG_win_TC_arm_standby
#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      PN_error_function_ok
  R      MG_win_TC_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_TC_arm_turn
  R      MG_win_TC_arm_put_in
  R      MG_win_TC_arm_put_out
  R      MG_win_tool_lock_open
  R      MG_win_tool_lock_close
  R      MG_win_TC_grippers_open
  R      MG_win_TC_gripper_spi_open
  R      MG_win_TC_gripper_mag_open
  R      MG_win_TC_gripper_spi_close
  R      MG_win_TC_gripper_mag_close
  R      MG_win_TC_arm_standby

EM

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

#ifdef $iTNC530Prog$
  L      NP_M4172_1st_PLC_run_after_power_on
  R      ML_TC_arm_grippers_closed
  R      ML_TC_arm_gripper_1_open
  R      ML_TC_arm_gripper_2_open
  S      ML_TC_arm_put_in
  R      ML_TC_arm_put_out
  R      ML_tool_lock_open
  S      ML_tool_lock_close
#endif
  L      ML_TC_arm_grippers_closed
  =      O_TC_arm_grippers_close

  L      ML_TC_arm_gripper_1_open
  =      O_TC_arm_gripper_1_open

  L      ML_TC_arm_gripper_2_open
  =      O_TC_arm_gripper_2_open

  L      ML_TC_arm_put_in
  =      O_TC_arm_put_in

  L      ML_TC_arm_put_out
  =      O_TC_arm_put_out

  L      ML_TC_arm_turn_ccw
  =      O_TC_arm_turn_ccw

  L      ML_TC_arm_turn_cw
  =      O_TC_arm_turn_cw

#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

EM

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

  LN     I_ESA_control_operational
  R      O_TC_arm_grippers_close
  R      O_TC_arm_gripper_1_open
  R      O_TC_arm_gripper_2_open
  R      O_TC_arm_put_in
  R      O_TC_arm_put_out
  R      O_tool_lock_close
  R      O_TC_arm_turn_ccw
  R      O_TC_arm_turn_cw
  EMT

  L      O_TC_arm_grippers_close
  =      ML_TC_arm_grippers_closed

  L      O_TC_arm_gripper_1_open
  =      ML_TC_arm_gripper_1_open

  L      O_TC_arm_gripper_2_open
  =      ML_TC_arm_gripper_2_open

  L      O_TC_arm_put_in
  =      ML_TC_arm_put_in

  L      O_TC_arm_put_out
  =      ML_TC_arm_put_out

  L      O_TC_arm_turn_ccw
  =      ML_TC_arm_turn_ccw

  L      O_TC_arm_turn_cw
  =      ML_TC_arm_turn_cw

#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

EM
