%%%
  VERSION: 1
  LANGUAGE: ENGLISH
%%%
MODULE DPUSER (SYSMODULE)
!---------------------------------------
! DispenseWare User Module:
! Used to customize the dispensing functionality for a
! specific dispense equipment. 
!
! Module description: 
!        This is the general default version of the DPUSER module.
!        All data components are visible and divided in two data types (beaddata and
!        equipdata) as described in the user documentation.
!        The names for the data components and for internal used signals are
!        as described in the user documentation.
!
!---------------------------------------

!---------------------------------------
! D A T A  T Y P E S
!---------------------------------------

!
! Definition of datatypes for DispenseWare
!     
  RECORD beaddata
    string info;
    num flow1;
    num flow2;
    num flow1_type;
    num flow2_type;
    num equip_no;
    num gun_no;
  ENDRECORD      

  RECORD equipdata
    string info;
    num on_time;
    num off_time;
    num ref_speed;
    num acc_max;
    num decel_max;
    num fl1_on_time;
    num fl1_off_time;
    num fl1_inc_time;
    num fl1_dec_time;
    num fl1_delay;
    num fl1_corr;
    num fl2_on_time;
    num fl2_off_time;
    num fl2_inc_time;
    num fl2_dec_time;
    num fl2_delay;
    num fl2_corr;
  ENDRECORD
  
!---------------------------------------
! G L O B A L  D A T A
!--------------------------------------- 

  CONST string Version_DPUSER := "4.1.0";
! Description: 
! CONST string Version_XXXXXXXX := "1.2.3";
!
!          XXXXXXXX - Module name
!                 1 - version number  (changed of SEROP) 
!                 2 - revision number (changed of SEROP)
!                 3 - revision number (for external use)

CONST num dp_fl1_corr := 100;
CONST num dp_fl2_corr := 100;
CONST num dp_restart_type := 0;
CONST num dp_qstop_bwddist := 0;
CONST num dp_stop_bwddist := 0;
CONST num dp_rest_on_time := 0;
CONST num dp_rest_fl_time := 0.5;
CONST num dp_rest_flow1 := 50;
CONST num dp_rest_flow2 := 50;
CONST num dp_bwd_key := 0;
CONST num dp_bwd_speed := 20;
CONST bool dp_dry := FALSE;

PERS beaddata bead1 := ["",100,100,2,2,1,1];
! bead1 is used as default in the first programmed DispL (or DispC) instruction.


PERS equipdata equipd{4} := [["",0,0,1000,-1,-1,0,0,0,0,0,100,0,0,0,0,0,100],
                             ["",0,0,1000,-1,-1,0,0,0,0,0,100,0,0,0,0,0,100],
			     ["",0,0,1000,-1,-1,0,0,0,0,0,100,0,0,0,0,0,100],
                             ["",0,0,1000,-1,-1,0,0,0,0,0,100,0,0,0,0,0,100]];					 
					 
					 

!---------------------------------------
! I O  S E T U P  R O U T I N E 
!---------------------------------------

! dp_init_signals is used to connect user defined signal names to internal used names.
! dp_init_signals is automatically called from the Start event routine in task MAIN.
! This version is prepared for four equipments with signals as defined in the default
! IO cfg.

PROC dp_init_signals()

! connect signal names for equipment 1

  AliasIO aoEqu1F1,int_ao_f1{1};
  AliasIO aoEqu1F2,int_ao_f2{1};
  AliasIO goEqu1Guns,int_go_onoff{1};
  
! connect signal names for equipment 2

  AliasIO aoEqu2F1,int_ao_f1{2};
  AliasIO aoEqu2F2,int_ao_f2{2};
  AliasIO goEqu2Guns,int_go_onoff{2};  
  
! connect signal names for equipment 3 

  AliasIO aoEqu3F1,int_ao_f1{3};
  AliasIO aoEqu3F2,int_ao_f2{3};
  AliasIO goEqu3Guns,int_go_onoff{3};  
  
! connect signal names for equipment 4 

  AliasIO aoEqu4F1,int_ao_f1{4};
  AliasIO aoEqu4F2,int_ao_f2{4};
  AliasIO goEqu4Guns,int_go_onoff{4};
  
! connect signal names for common signals

  AliasIO doDPErr,int_do_err;
  AliasIO doDPOvrSpd,int_do_ovrspd;
  AliasIO doDPActive,int_do_active;  

! connect a signal name for the signal used for
! the "backward on path" function.

  AliasIO diBwdOnPath,int_di_bwdonpath;

ENDPROC  


!---------------------------------------
! D A T A  S E T U P  R O U T I N E 
!---------------------------------------

! dp_set_int_data is used to connect user defined data component names to internal used names.
! dp_set_int_data is called from DPBASE when a DispL or DispC instruction is executed.
! Not used data must be given a predefined default value e.g.:
!           int_dp_data.flow2:= default_dp_data.flow2;

PROC dp_set_int_data(beaddata current_bead)

    int_dp_data.flow1:= 	current_bead.flow1;
    int_dp_data.flow2:= 	current_bead.flow2;
    int_dp_data.flow1_type:= 	current_bead.flow1_type;
    int_dp_data.flow2_type:= 	current_bead.flow2_type;
    int_dp_data.equip_no:= 	current_bead.equip_no;
    int_dp_data.gun_no:= 	current_bead.gun_no;
    
    IF int_dp_data.equip_no > 0  AND int_dp_data.equip_no <= 4 THEN
      int_dp_data.on_time:= 		equipd{int_dp_data.equip_no}.on_time;
      int_dp_data.off_time:= 		equipd{int_dp_data.equip_no}.off_time;
      int_dp_data.ref_speed:= 		equipd{int_dp_data.equip_no}.ref_speed;
      int_dp_data.acc_max:= 		equipd{int_dp_data.equip_no}.acc_max;
      int_dp_data.decel_max:= 		equipd{int_dp_data.equip_no}.decel_max;      
      int_dp_data.fl1_on_time:= 	equipd{int_dp_data.equip_no}.fl1_on_time;
      int_dp_data.fl1_off_time:= 	equipd{int_dp_data.equip_no}.fl1_off_time;
      int_dp_data.fl1_inc_time:= 	equipd{int_dp_data.equip_no}.fl1_inc_time;
      int_dp_data.fl1_dec_time:= 	equipd{int_dp_data.equip_no}.fl1_dec_time;
      int_dp_data.fl1_delay:= 		equipd{int_dp_data.equip_no}.fl1_delay;
      int_dp_data.fl1_corr:= 		equipd{int_dp_data.equip_no}.fl1_corr;
      int_dp_data.fl2_on_time:= 	equipd{int_dp_data.equip_no}.fl2_on_time;
      int_dp_data.fl2_off_time:= 	equipd{int_dp_data.equip_no}.fl2_off_time;
      int_dp_data.fl2_inc_time:= 	equipd{int_dp_data.equip_no}.fl2_inc_time;
      int_dp_data.fl2_dec_time:= 	equipd{int_dp_data.equip_no}.fl2_dec_time;
      int_dp_data.fl2_delay:= 		equipd{int_dp_data.equip_no}.fl2_delay;
      int_dp_data.fl2_corr:= 		equipd{int_dp_data.equip_no}.fl2_corr;
    ENDIF

ENDPROC

!-------------------------------------------------
! F L O W  C A L C U L A T I O N  R O U T I N E S
!------------------------------------------------- 

!* Function dp_calcf1_type1 *

FUNC num dp_calcf1_type1()
  VAR num flow_value;

  flow_value := curr_dp_data.flow1*curr_dp_data.fl1_corr*dp_fl1_corr/10000;

  RETURN flow_value;
ENDFUNC


!* Function dp_calcf1_type2 *

FUNC num dp_calcf1_type2()
  VAR num flow_value;

  flow_value := curr_dp_data.flow1*curr_dp_data.fl1_corr*dp_fl1_corr/10000/curr_dp_data.ref_speed;

  RETURN flow_value;
ENDFUNC


!* Function dp_calcf2_type1 *

FUNC num dp_calcf2_type1()
  VAR num flow_value;

  flow_value := curr_dp_data.flow2*curr_dp_data.fl2_corr*dp_fl2_corr/10000;

  RETURN flow_value;
ENDFUNC


!* Function dp_calcf2_type2 *

FUNC num dp_calcf2_type2()
  VAR num flow_value;

  flow_value := curr_dp_data.flow2*curr_dp_data.fl2_corr*dp_fl2_corr/10000/curr_dp_data.ref_speed;

  RETURN flow_value;
ENDFUNC


!---------------------------------------
! U S E R   E V E N T   R O U T I N E S
!--------------------------------------- 

!* Procedure dp_predisp *

PROC dp_predisp()
! User defined code:
ENDPROC

!* Procedure dp_postdisp *

PROC dp_postdisp()
! User defined code:
ENDPROC

!* Procedure dp_err_actions *

PROC dp_err_actions()
! User defined code:
ENDPROC

!* Procedure dp_power_on *

PROC dp_power_on()
! User defined code:
ENDPROC

!* Procedure dp_start *

PROC dp_start()
! User defined code:
ENDPROC

!* Procedure dp_restart *

PROC dp_restart()
! User defined code:
ENDPROC

!* Procedure dp_restart_proc *
!This routine is executed just before the process
!signals are activatred and the motion is restarted.

PROC dp_restart_proc()
! User defined code:
ENDPROC

!* Procedure dp_stop *

PROC dp_stop()
! User defined code:
ENDPROC 

!* Procedure dp_qstop *

PROC dp_qstop()
! User defined code:
ENDPROC

ENDMODULE
