*-----------------------------------------------------------------------------
*  FN19 functions
*-----------------------------------------------------------------------------
*  Module Description
*    The module has been introduced to start special PLC functions which can
*    be modified by means of additional data.
*    With FN19 two double words are transferred to the PLC. In the PLC basic
*    program the first double word (D280) is used as identifier and the second
*    one (D284) for data. The functions available in each case are part of the
*    module description.
*      Function                        Identifier (D280)  Data (D284)
*        Axes clamping mode on           K+99990            axes bitcoded
*        Axes clamping mode off          K+99991            axes bitcoded
*                                                           1: spindle S2
*        Tuning mode                     K+99993            0: standard
*                                                           1: exact
*                                                           2: smooth
*                                                           3: routh
*        Free rotation                   K+99994            feed [°/min]
*        Preselection PLC preset (M79)   K+99999            line in Preset.tab
*
*-----------------------------------------------------------------------------

#define /s    ML_strobe_FN19                           M

#define /s    BL_FN19_PLC_function                     B

GLOBAL FN19

;----------------------------
LBL FN19
;----------------------------

  L      NP_M4075_strobe_transfer_FN19
  AN     ML_strobe_FN19
  IFT
    L      NP_D280_FN19_1st_value
    /      K+10000
    <=     K+99999
    A[
      L      NP_D280_FN19_1st_value
      /      K+10000
      >=     K+99990
    ]
    IFT
      L      NP_D280_FN19_1st_value
      /      K+10000
      -      K+99990
      =      BL_FN19_PLC_function
    ELSE
      L      NP_M4075_strobe_transfer_FN19
      S      PN_M4095_quit_transfer_FN19
    ENDI
  ENDI

  L      NP_M4075_strobe_transfer_FN19
  R      ML_strobe_FN19
  EMF

  CASE   BL_FN19_PLC_function
    CM     Clamping_mode_on            ;99990
    CM     Clamping_mode_off           ;99991
    CM     no_function                 ;99992
    CM     Tuning_mode                 ;99993
    CM     Free_rotation               ;99994
    CM     no_function                 ;99995
    CM     no_function                 ;99996
    CM     no_function                 ;99997
    CM     no_function                 ;99998
    CM     Preset_PLC                  ;99999
  ENDC

  L      NP_M4075_strobe_transfer_FN19
  =      ML_strobe_FN19

EM

;----------------------------
LBL no_function

  L      MG_marker_one
  S      PN_error_value_not_permissible

EM

;----------------------------
LBL Clamping_mode_on                   ;99990

* Evaluation in module axes.src

EM

;----------------------------
LBL Clamping_mode_off                  ;99991

* Evaluation in module axes.src

EM

;----------------------------
LBL Tuning_mode                        ;99993

  L      NP_D284_FN19_2st_value
  /      K+10000
  >      K+3
  S      PN_error_value_not_permissible

  L      NP_D284_FN19_2st_value
  /      K+10000
  <      K+0
  S      PN_error_value_not_permissible

  LN     PN_error_value_not_permissible
  IFT
    L      NP_D284_FN19_2st_value
    /      K+10000
    =      BG_tuning_mode

    L      NP_M4075_strobe_transfer_FN19
    S      PN_M4095_quit_transfer_FN19
  ELSE
    L      K+0
    =      BG_tuning_mode
  ENDI

EM

;----------------------------
LBL Free_rotation                      ;99994

  LN     MG_free_rotation_active
  A      NP_M4075_strobe_transfer_FN19
  S      PN_M4095_quit_transfer_FN19

  L      NP_D284_FN19_2st_value
  /      K+10000
  =      DG_turning_axis_feed

  L      DG_turning_axis_feed
  >      DG_MP1010_rapid_feed_turning_axis
  S      PN_error_value_not_permissible
  IFT
    L      DG_feed_PLC_X[KG_turning_rotary_axis_index]
    >      DG_MP1010_rapid_feed_turning_axis
    IFT
      L      DG_MP1010_rapid_feed_turning_axis
      =      DG_turning_axis_feed
    ELSE
      L      DG_feed_PLC_X[KG_turning_rotary_axis_index]
      =      DG_turning_axis_feed
    ENDI
  ENDI

EM

;----------------------------
LBL Preset_PLC                         ;99999

  L      NP_D284_FN19_2st_value
  /      K+10000
  >      K$7F
  S      PN_error_value_not_permissible

  L      NP_D284_FN19_2st_value
  /      K+10000
  <=     K+0
  S      PN_error_value_not_permissible

  LN     PN_error_value_not_permissible
  IFT
    L      NP_D284_FN19_2st_value
    /      K+10000
    =      BG_FN19_PLC_preset

    L      NP_M4075_strobe_transfer_FN19
    S      PN_M4095_quit_transfer_FN19
  ELSE
    L      K+0
    =      BG_FN19_PLC_preset
  ENDI

EM
