*-----------------------------------------------------------------------------
*  Toolchange Automatic Mode (single arm)
*-----------------------------------------------------------------------------
*  Module Description
*
*-----------------------------------------------------------------------------

#define /s    KL_absolute_with_software_limit_switch   K %010
#define /s    KL_absolute_without_software_limit_switch K %000

#define /s    KL_tool_without_pocket                   K -1
#define /s    KL_tool_with_pocket                      K +1
#define /s    KL_tool_in_spindle                       K +0
#define /s    KL_string_count                          K +3

#define /s    ML_2nd_TOOL_CALL_following               M
#define /s    ML_TOOL_CALL_old                         M
#define /s    ML_step_start                            M
#define /s    ML_TC_diagnosis                          M

#define /s    BL_TC_mag_axis_index                     B
#define /s    BL_WZ_mag_index                          B
#define /s    BL_string_index                          B
#define /s    BL_step_T_change                         B

#define /s    WL_line_dialog_file                      W

#include Mac_Lib.inc

EXTERN Absolute
GLOBAL TC_auto

;----------------------------
LBL TC_auto
;----------------------------

  LN     MG_TC_auto_active
  EMT

  L      PN_M4540_T_new_1st_if_pocket_fixed
  R      PN_M4540_T_new_1st_if_pocket_fixed

  L      NP_M4521_TOOL_CALL_T_0_programmed
  A      NP_M4520_TOOL_CALL_2nd_strobe
  A      NP_M4073_strobe_TOOL_CALL
  A      MG_TC_T0_auto_manu_necessary
  S      PN_error_TOOL_CALL_T0_necessary
  EMT

  L      NP_M4073_strobe_TOOL_CALL
  IFT
    L      NP_W262_tool_pocket_number
    >=     KL_tool_with_pocket
    AN     NP_M4175_control_in_operation_flashes
    AN     MG_TC_automatic
    S      MG_TC_automatic
    IFT
      L      NP_W262_tool_pocket_number
      =      WG_TC_pocket_number
      L      NP_W264_tool_number
      =      WG_TC_auto_tool_number
    ENDI
  ENDI

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_MP7261_TC_magazine_max_pocket
  >=     KL_tool_with_pocket
  A      MG_TC_manual
  A      NP_M4073_strobe_TOOL_CALL
  O      MG_TC_automatic
  A      MG_pulse_internal_stop
  S      MG_pocket_table_checking

  L      MG_pocket_table_selected
  A      MG_TC_standby_position
  AN     MG_TC_manual
  AN     MG_TC_automatic
  R      MG_pocket_table_checking

  L      MG_pocket_table_checking
  AN     MG_TC_manual
  AN     MG_TC_automatic
  AN     MG_TC_help
  A      MG_TC_standby_position
  =      PN_error_check_pocket_table

  L      MG_TC_automatic
  R      TS_TC_timeout
  S      TS_TC_timer_universal

  CASE   BG_step_toolchange
    CM     TC_auto_start               ;00
    CM     Tool_spindle_ok             ;01
    CM     T_mag_start                 ;02
    CM     Magazine_in_pos             ;03
    CM     Mag_full_empty              ;04
    CM     Spi_full_empty              ;05
    CM     Tool_lock_open              ;06
    CM     Z1_in_out_start             ;07
    CM     S_start                     ;08
    CM     Tool_lock_opened            ;09
    CM     Z1_posit_in_out             ;10
    CM     X_start                     ;11
    CM     S_in_TC_pos                 ;12
    CM     X_in_TC_Pos                 ;13
#if TC_magazine_is_moving_to_spindle = &active
    CM     Mag_to_spindle              ;14
    CM     Mag_in_spindle              ;15
#else
    CM     Y_start                     ;14
    CM     Y_in_TC_Pos                 ;15
#endif
    CM     Tool_unclamping             ;16
    CM     Tool_unclamped              ;17
    CM     Time_put_out                ;18
    CM     T0_Tnew_status              ;19
    CM     T_status_ok                 ;20
    CM     Z2_in_out_start             ;21
    CM     Z2_posit_in_out             ;22
    CM     Tool_Call_2nd               ;23
    CM     Tool_Call_wait              ;24
    CM     T_status_read               ;25
    CM     Jump_clamping               ;26 ---> (1)
    CM     T_mag_start                 ;27
    CM     Magazine_in_pos             ;28
    CM     Mag_full                    ;29
    CM     Z3_in_start                 ;30
    CM     Z3_posit_in                 ;31
    CM     Tool_clamping               ;32 <--- (1)
    CM     Tool_clamped                ;33
    CM     Tnew_in_status              ;34
    CM     T_status_ok                 ;35
#if TC_magazine_is_moving_to_spindle = &active
    CM     Mag_to_basic                ;36
    CM     Mag_on_basic                ;37
#else
    CM     Y_pre_start                 ;36
    CM     Y_in_pre_pos                ;37
#endif
    CM     Tool_lock_close             ;38
    CM     Tool_lock_closed            ;39
    CM     Spi_empty_full              ;40
    CM     TOOL_CALL_quit              ;41
    CM     TC_auto_end                 ;42
    CM     time                        ;reserviert
  ENDC

  PLL
  S      TS_TC_timeout
  =      ML_step_start
  IFT
    INC    BG_step_toolchange
  ENDI

  L      BG_step_toolchange
  <>     BL_step_T_change
  ON     ML_TC_diagnosis
  A      MG_TC_diagnosis
  IFT
    L      K +0
    =      BL_string_index

;$WS Call 60286
;    L      BG_Schritt_WZW
;    =X

    L      BG_step_toolchange
    =      BL_step_T_change
    REPEAT
      L      BL_step_T_change
      =X

      L      KF Diagnostic[X]
      =      WL_line_dialog_file
      =X

;      L      S#D0[WL_line_dialog_file]
      L      S#D0[X]
      =      SG_diagnostics_line_1[BL_string_index]

      INC    BL_step_T_change
      INC    BL_string_index
      INCX

      L      BL_string_index
      >=     KL_string_count
    UNTILT
  ENDI

  L      BG_step_toolchange
  =      BL_step_T_change

  L      MG_TC_diagnosis
  =      ML_TC_diagnosis

  LN     MG_TC_automatic
  EMT

  L      MG_NC_start_pulse
  R      MG_TC_interruption

  L      MG_key_NC_start
  O      MG_pulse_CE_key
  S      TS_TC_timeout

  LN     TR_TC_timeout
  AN     TS_TC_timeout
  =      PN_error_TC_timeout
  S      MG_TC_interruption

  L      MG_key_NC_stop
  O      MG_pulse_external_stop
  S      MG_TC_interruption

  L      MG_pulse_internal_stop
  O      MG_auto_manu_mode_change
  ON     MG_control_operational
*$WS Reset wenn Spindle abgeschaltet (Tür auf)
  CMT    TC_auto_reset

EM

;----------------------------
LBL Jump_clamping                      ;26

  PS     MG_marker_one

  LN     ML_2nd_TOOL_CALL_following
  O      NP_M4523_TOOL_CALL_without_pocket_number
  IFT
    L      BG_step_toolchange
    +      K+5
    =      BG_step_toolchange
  ENDI

EM

;----------------------------
LBL TC_auto_start                      ;00

  LN     MG_TC_standby_position
  A      MG_TC_automatic
  S      PN_error_TC_basic_position
  S      MG_TC_interruption

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start
  S      TS_TC_timeout

  L      MG_TC_automatic
  AN     MG_TC_manual
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start
  A      MG_TC_standby_position
  AN     MG_TC_interruption
  PSL

EM

;----------------------------
LBL Tool_spindle_ok                    ;01

  L      MG_key_NC_start_p_pulse
  A      MG_automatic_mode
  R      MG_TC_without_Tool_Call

  L      MG_TC_without_Tool_Call
  =      PN_error_tool_spindle_ok
  =      MG_win_window_yes_no
  S      TS_TC_timeout

  LN     MG_reference_axes_traversed
  S      PN_error_reference_necessary

  LN     MG_TC_without_Tool_Call
  AN     PN_error_reference_necessary
  AN     MG_TC_interruption
  PSL

  L      NP_M4175_control_in_operation_flashes
  JPT    TC_auto_reset

EM

;----------------------------
LBL Spi_full_empty                     ;05

  L      NP_M4521_TOOL_CALL_T_0_programmed
  CMT    Spi_full
  CMF    Spi_empty

EM

;----------------------------
LBL Spi_empty_full                     ;40

  L      NP_W262_tool_pocket_number
  ==     KL_tool_without_pocket
  O      NP_M4521_TOOL_CALL_T_0_programmed
  CMF    Spi_full
  CMT    Spi_empty

EM

;----------------------------
LBL Spi_full

  LN     MG_Sn_I_tool_located_in_spindle
  AN     MG_commissioning
  AN     MG_S1_tool_monitoring_inactive[BG_number_active_spindle]
  S      PN_error_spindle_without_tool

  LN     PN_error_spindle_without_tool
  PSL

  L      NP_M4175_control_in_operation_flashes
  JPT    TC_auto_reset

EM

;----------------------------
LBL Spi_empty

  L      MG_Sn_I_tool_located_in_spindle
  AN     MG_commissioning
  AN     MG_S1_tool_monitoring_inactive[BG_number_active_spindle]
  S      PN_error_spindle_not_empty

  LN     PN_error_spindle_not_empty
  PSL

  L      NP_M4175_control_in_operation_flashes
  JPT    TC_auto_reset

EM

;----------------------------
LBL Mag_full_empty                     ;04

  L      NP_M4521_TOOL_CALL_T_0_programmed
  CMT    Mag_empty
  CMF    Mag_full

EM

;----------------------------
LBL Mag_empty

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_I_TC_pocket_not_empty
  AN     MG_commissioning
  AN     MG_TC_mag_1_monitoring_inactive[BG_TC_mag_index_Tool_Call]
  S      PN_error_TC_pocket_not_empty

  LN     PN_error_TC_pocket_not_empty
  PSL

  L      NP_M4175_control_in_operation_flashes
  JPT    TC_auto_reset

EM

;----------------------------
LBL Mag_full                           ;29

  LN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_I_TC_pocket_not_empty
  AN     MG_commissioning
  AN     MG_TC_mag_1_monitoring_inactive[BG_TC_mag_index_Tool_Call]
  S      PN_error_TC_pocket_without_tool

  LN     PN_error_TC_pocket_without_tool
  PSL

  L      NP_M4175_control_in_operation_flashes
  JPT    TC_auto_reset

EM

;----------------------------
LBL T_mag_start                        ;02 ;27

  CM     Magazine_posit
  PLL
  =N     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TM_started_by_Tool_Call

  LN     MG_TC_interruption
  PSL

EM

;----------------------------
LBL Magazine_in_pos                    ;03 ;28

  CM     Magazine_posit

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start
  AN     MG_TC_interruption
  S      TS_TC_timeout

  PLL
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_TC_magazine_change_position

EM

#if Tool_magazine = &PLC_axis
;----------------------------
LBL Magazine_posit

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].BG_TC_magazine_axis_index
  =      BL_TC_mag_axis_index

  L      WG_TC_pocket_number
  X      STG_TC_mag[BG_TC_mag_index_Tool_Call].DG_TC_magazine_pocket_distance
  -      DG_position_axis_X_ref[BL_TC_mag_axis_index]
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_X[BL_TC_mag_axis_index]
  O[
    L      DG_position_axis_X_ref[BL_TC_mag_axis_index]
    <      DG_MP1030_pos_window_X[BL_TC_mag_axis_index]
    A[
      L      WG_TC_pocket_number
      ==     STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_MP7261_TC_magazine_max_pocket
    ]
  ]
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_status[KG_posit_active]
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TM_started_by_Tool_Call
  PSL

EM
#endif

#if Tool_magazine = &Pulse
;----------------------------
LBL Magazine_posit

  L      STG_TC_mag[BG_TC_mag_index_Tool_Call].WG_TC_magazine_actual_pocket
  ==     WG_TC_pocket_number
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_start
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TM_started_by_Tool_Call
  AN     STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TC_mag_reference_necessary
  PSL

EM
#endif

;----------------------------
LBL S_start                            ;08

  LN     MG_TC_interruption
  PSL
  EMF

  L      MG_spindle_with_ROD
  S      MG_TC_spindle_orientation_on

EM

;----------------------------
LBL S_in_TC_pos                        ;12

  LN     MG_spindle_with_ROD
  A      MG_spindle_off
  O      MG_spindle_in_TC_position
  AN     MG_TC_spindle_orientation_on
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_TC_pos_S

EM

;----------------------------
LBL Z1_in_out_start                    ;07

  L      NP_M4521_TOOL_CALL_T_0_programmed
  CMT    Z_in_start
  CMF    Z_out_start

EM

;----------------------------
LBL Z1_posit_in_out                    ;10

  L      NP_M4521_TOOL_CALL_T_0_programmed
  CMT    Z_posit_in
  CMF    Z_posit_out

EM

;----------------------------
LBL Z2_in_out_start                    ;21

  L      NP_M4522_TOOL_CALL_with_pocket_number
  CMT    Z_in_start
  CMF    Z_out_start

EM

;----------------------------
LBL Z2_posit_in_out                    ;22

  L      NP_M4522_TOOL_CALL_with_pocket_number
  CMT    Z_posit_in
  CMF    Z_posit_out

EM

;----------------------------
LBL Z3_in_start                        ;30

  CM     Z_in_start

EM

;----------------------------
LBL Z3_posit_in                        ;31

  CM     Z_posit_in

EM

;----------------------------
LBL Z_in_start

  L      MG_TC_interruption
  =      MG_win_TC_pos_Z_put_in
  IFT
    PS     MG_marker_zero
  ELSE
    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
    PLW
    ==     K+0
    PSL
    M_display_module_error
  ENDI

EM

;----------------------------
LBL Z_out_start

  L      MG_TC_interruption
  =      MG_win_TC_pos_Z_put_out
  IFT
    PS     MG_marker_zero
  ELSE
    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
    PLW
    ==     K+0
    PSL
    M_display_module_error
  ENDI

EM

;----------------------------
LBL Z_posit_in

  L      MG_TC_interruption
  =      MG_win_TC_pos_Z_put_in

#if TC_magazine_is_moving_to_spindle = &active
  L      I_TC_magazine_in_spindle_position
  S      O_spindle_blow_clean
#else
  L      DG_position_axis_Y_ref
  -      DG_TC_pos_Y
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Y
  S      O_spindle_blow_clean
#endif

  L      MG_TC_interruption
  R      O_spindle_blow_clean

  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
  AN     MG_TC_interruption
  R      O_spindle_blow_clean
  PSL

EM

;----------------------------
LBL Z_posit_out

  L      MG_TC_interruption
  =      MG_win_TC_pos_Z_put_out

#if TC_magazine_is_moving_to_spindle = &active
  L      I_TC_magazine_in_spindle_position
  S      O_spindle_blow_clean
#else
  L      DG_position_axis_Y_ref
  -      DG_TC_pos_Y
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Y
  S      O_spindle_blow_clean
#endif

  L      MG_TC_interruption
  R      O_spindle_blow_clean

  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
  AN     MG_TC_interruption
  R      O_spindle_blow_clean
  PSL

EM

;----------------------------
LBL X_start                            ;11

  L      MG_TC_interruption
  =      MG_win_TC_pos_X
  IFT
    PS     MG_marker_zero
  ELSE
    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
    PLW
    ==     K+0
    PSL
      M_display_module_error
  ENDI

EM

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

  L      MG_TC_interruption
  =      MG_win_TC_pos_X

  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
  AN     MG_TC_interruption
  PSL

EM

#if TC_magazine_is_moving_to_spindle = &active
;----------------------------
LBL Mag_to_spindle                     ;14

  L      MG_marker_one
  S      O_TC_magazine_to_spindle_position
  R      O_TC_magazine_to_basic_position
  PSL

EM

;----------------------------
LBL Mag_in_spindle                     ;15

  L      I_TC_magazine_in_spindle_position
  AN     I_TC_magazine_in_basic_position
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_TC_magazine_to_spindle_position

EM

;----------------------------
LBL Mag_to_basic                       ;36

  L      MG_marker_one
  R      O_TC_magazine_to_spindle_position
  S      O_TC_magazine_to_basic_position
  PSL

EM

;----------------------------
LBL Mag_on_basic                       ;37

  LN     I_TC_magazine_in_spindle_position
  A      I_TC_magazine_in_basic_position
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_TC_magazine_to_basic_position

EM
#else
;----------------------------
LBL Y_start                            ;14

  L      MG_TC_interruption
  =      MG_win_TC_pos_Y
  IFT
    PS     MG_marker_zero
  ELSE
    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
    PLW
    ==     K+0
    PSL
    M_display_module_error
  ENDI

EM

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

  L      MG_TC_interruption
  =      MG_win_TC_pos_Y

  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
  AN     MG_TC_interruption
  PSL

EM

;----------------------------
LBL Y_pre_start                        ;36

  L      MG_TC_interruption
  =      MG_win_TC_pre_pos_Y
  IFT
    PS     MG_marker_zero
  ELSE
    PS     KG_axis_Y
    PS     DG_TC_pre_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
    PLW
    ==     K+0
    PSL
    M_display_module_error
  ENDI

EM

;----------------------------
LBL Y_in_pre_pos                       ;37

  L      MG_TC_interruption
  =      MG_win_TC_pre_pos_Y

  L      DG_position_axis_Y_ref
  -      DG_TC_pre_pos_Y
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Y
  AN     PN_M4121_strobe_PLC_posit_axis_Y
  AN     MG_TC_interruption
  PSL

EM
#endif

;----------------------------
LBL T_status_read                      ;25

  L      MG_marker_one
  S      MG_tool_status_reading
  PSL

EM

;----------------------------
LBL Tool_unclamping                    ;16

  L      MG_marker_one
  S      MG_Sn_O_tool_unclamping
  PSL

EM

;----------------------------
LBL Tool_clamping                      ;32

  L      MG_marker_one
  R      MG_Sn_O_tool_unclamping
  PSL

EM

;----------------------------
LBL Tool_unclamped                     ;17

  LN     MG_Sn_I_tool_clamped
  A      MG_Sn_I_tool_unclamped
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_tool_unclamping

EM

;----------------------------
LBL Tool_clamped                       ;33

  L      MG_Sn_I_tool_clamped
  AN     MG_Sn_I_tool_unclamped
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_tool_clamping

EM

;----------------------------
LBL Tool_lock_open                     ;06

  L      MG_marker_one
  S      O_tool_lock_open
  R      O_tool_lock_close
  PSL

EM

;----------------------------
LBL Tool_lock_close                    ;38

  L      MG_marker_one
  R      O_tool_lock_open
  S      O_tool_lock_close
  PSL

EM

;----------------------------
LBL Tool_lock_opened                   ;09

#if CFG_magazine_tool_lock = "active"
  L      I_tool_lock_open
  AN     I_tool_lock_close
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_tool_lock_open
#else
  PS     MG_marker_one
#endif

EM

;----------------------------
LBL Tool_lock_closed                   ;39

#if CFG_magazine_tool_lock = "active"
  LN     I_tool_lock_open
  A      I_tool_lock_close
  AN     MG_TC_interruption
  PSL

  L      MG_TC_interruption
  =      MG_win_tool_lock_close
#else
  PS     MG_marker_one
#endif

EM

;----------------------------
LBL T0_Tnew_status                     ;19

  LN     MG_TC_interruption
  S      PN_M4538_tool_selection_from_PLC_W264
  PSL

EM

;----------------------------
LBL Tnew_in_status                     ;34

  LN     MG_tool_status_reading
  AN     MG_TC_interruption
  PSL
  EMF

  L      NP_W262_tool_pocket_number
  >=     KL_tool_with_pocket
  S      PN_M4538_tool_selection_from_PLC_W264
  EMF

  L      NP_W264_tool_number
  =      WG_tool_in_spindle

EM

;----------------------------
LBL T_status_ok                        ;20 ;35

  LN     PN_M4538_tool_selection_from_PLC_W264
  PSL

EM

;----------------------------
LBL Tool_Call_2nd                      ;23

  LN     NP_M4520_TOOL_CALL_2nd_strobe
  ON     NP_M4073_strobe_TOOL_CALL
  PSL
  EMT

  L      NP_M4520_TOOL_CALL_2nd_strobe
  AN     MG_TC_interruption
  S      ML_2nd_TOOL_CALL_following
  S      PN_M4093_quit_TOOL_CALL

EM

;----------------------------
LBL Tool_Call_wait                     ;24

  L      NP_M4073_strobe_TOOL_CALL
  PSL
  EMF

  L      NP_W262_tool_pocket_number
  >=     KL_tool_with_pocket
  IFT
    L      NP_W262_tool_pocket_number
    =      WG_TC_pocket_number
    L      NP_W264_tool_number
    =      WG_TC_auto_tool_number
  ENDI

EM

;----------------------------
LBL TOOL_CALL_quit                     ;41

  L      NP_W262_tool_pocket_number
  ==     KL_tool_without_pocket
  ON     NP_M4073_strobe_TOOL_CALL
  S      MG_standby_tool_status_reading
  PSL
  EMT

  L      NP_M4073_strobe_TOOL_CALL
  AN     MG_TC_interruption
  S      PN_M4093_quit_TOOL_CALL

EM

;----------------------------
LBL TC_auto_end                        ;42

  PS     MG_marker_zero

;----------------------------
LBL TC_auto_reset

  L      MG_marker_one
  R      O_spindle_blow_clean
  R      MG_TC_automatic
  R      MG_TC_interruption
  R      STG_TC_mag[BG_TC_mag_index_Tool_Call].MG_TM_started_by_Tool_Call
  R      MG_TC_spindle_orientation_on
  R      PN_error_tool_spindle_ok
  R      MG_win_window_yes_no
  R      ML_2nd_TOOL_CALL_following

  L      K+0
  =      BG_step_toolchange
  =      BL_WZ_mag_index

  REPEAT
    L      MG_marker_one
    R      STG_TC_mag[BL_WZ_mag_index].MG_TM_started_by_Tool_Call

    INC    BL_WZ_mag_index

    L      BL_WZ_mag_index
    >=     KG_TC_magazine_max_count
  UNTILT

  L      K+0
  =      BL_WZ_mag_index

EM

;----------------------------
LBL Time_put_out                       ;18

  L      NP_M4522_TOOL_CALL_with_pocket_number
  PSL
  EMT

  PLL
  CMF    time

EM

;----------------------------
LBL time

  LN     TR_TC_timer_universal
  =      TS_TC_timer_universal
  PSL

EM

;----------------------------
KFIELD Diagnostic                      ;Case
  KG_dia_TC_auto_single_arm            ;-1
  KG_dia_TC_auto_start                 ;00
  KG_dia_tool_spindle_ok               ;01
  KG_dia_T_mag_start                   ;02
  KG_dia_magazine_in_pos               ;03
  KG_dia_mag_full_empty                ;04
  KG_dia_spi_full_empty                ;05
  KG_dia_tool_lock_open                ;06
  KG_dia_Z1_in_out_start               ;07
  KG_dia_S_start                       ;08
  KG_dia_tool_lock_opened              ;09
  KG_dia_Z1_posit_in_out               ;10
  KG_dia_X_start                       ;11
  KG_dia_S_in_TC_posit                 ;12
  KG_dia_X_in_TC_posit                 ;13
#if TC_magazine_is_moving_to_spindle = &active
  KG_dia_mag_to_spindle                ;14
  KG_dia_mag_in_spindle                ;15
#else
  KG_dia_Y_start                       ;14
  KG_dia_Y_in_TC_pos                   ;15
#endif
  KG_dia_tool_unclamping               ;16
  KG_dia_tool_unclamped                ;17
  KG_dia_time_put_out                  ;18
  KG_dia_T0_Tnew_status                ;19
  KG_dia_T_status_ok                   ;20
  KG_dia_Z2_in_out_start               ;21
  KG_dia_Z2_posit_in_out               ;22
  KG_dia_Tool_Call_2nd                 ;23
  KG_dia_Tool_Call_wait                ;24
  KG_dia_T_status_read                 ;25
  KG_dia_jump_clamping                 ;26
  KG_dia_T_mag_start                   ;27
  KG_dia_magazine_in_pos               ;28
  KG_dia_mag_full                      ;29
  KG_dia_Z3_in_start                   ;30
  KG_dia_Z3_posit_in                   ;31
  KG_dia_tool_clamping                 ;32
  KG_dia_tool_clamped                  ;33
  KG_dia_Tnew_in_status                ;34
  KG_dia_T_status_ok                   ;35
#if TC_magazine_is_moving_to_spindle = &active
  KG_dia_mag_to_basic                  ;36
  KG_dia_mag_on_basic                  ;37
#else
  KG_dia_Y_TC_pre_pos                  ;36
  KG_dia_Y_in_TC_pre_pos               ;37
#endif
  KG_dia_tool_lock_close               ;38
  KG_dia_tool_lock_closed              ;39
  KG_dia_spi_empty_full                ;40
  KG_dia_TOOL_CALL_quit                ;41
  KG_dia_TC_auto_end                   ;42
  KG_dia_empty                         ;43
ENDK
