%%%
  VERSION:1
  LANGUAGE:ENGLISH
%%%

MODULE EXT_MMI (SYSMODULE)
  !######################################################
  !# PalletWare module EXT_MMI				#
  !# This module holds the MMI communication routines	#
  !# for an external MMI.				#
  !# It communicates with PAL_MAIN, PAL_ERR, PAL_CFG.	#
  !# 							#
  !######################################################
  CONST string ext_mmi_rev:="$Revision: 1.1 $";
  !######################################################
  !#							#
  !# 		P U B L I C   R O U T I N E S  		#
  !#							#
  !######################################################
  
  !------------------------------------------------------
  !	name:	PalInitDlgText
  !	descr:	Initiates dialog text resource file.
  !	arg:	none
  !------------------------------------------------------ 
  PROC PalInitDlgText()
    !
  ERROR
    RAISE;
  ENDPROC
  
  !------------------------------------------------------
  !	name:	GetCxtToEdit
  !	descr:	This func communicates with the MMI to
  !		get the context number to edit.
  !		
  !	arg:	none
  !	ret:	context of type num
  !------------------------------------------------------
  FUNC num GetCxtToEdit()
    
    VAR num context;
    
    !Send "Select context to edit"
    SendMsgToMmi MSG_SEL_CONTEXT;
    !Read choice 1 to 5
    ReadMsgFromMmi context;
    RETURN context;
  ERROR
    RAISE;
  ENDFUNC
  
  !------------------------------------------------------
  !	name:	GetEditChoice
  !	descr:	This func communicates with the MMI to
  !		get the edit option of following:
  !		1 - Empty line and change pallet type
  !		2 - Finish current pallet and change pallet type
  !		3 - Change pallet type immediately
  !		4 - Evacuate current pallet
  !		5 - Continue
  !	arg:	context of type num	
  !	ret:	choice of type num
  !------------------------------------------------------
  FUNC num GetEditChoice(num context)
  
    VAR num choice;
    
    !Send "Select request option"
    SendMsgToMmi MSG_SEL_REQ_OPT;
    !Read choice 1 to 5
    ReadMsgFromMmi choice;
    RETURN choice;
  ERROR
    RAISE;
  ENDFUNC
  
    
  !------------------------------------------------------
  !	name:	ChkEditMoreCxt
  !	descr:	This func communicates with the MMI to
  !		get the choice of what to do after edit
  !		a context. The alternatives to return are:
  !		TRUE if choice is 4
  !		FALSE otherwise
  !	arg:	context of type num	
  !	ret:	choice of type bool
  !------------------------------------------------------
  FUNC bool ChkEditMoreCxt()
    
    VAR num choice;
    
    !Edit more or start
    SendMsgToMmi MSG_EDIT_MORE;
    !Read choice 4 (edit) or 5 (start)
    ReadMsgFromMmi choice;
    IF choice=4 THEN
      RETURN TRUE;
    ELSE
      RETURN FALSE;
    ENDIF
  ERROR
    RAISE;
  ENDFUNC
  
  !------------------------------------------------------
  !	name:	PalGetErrChoice
  !	descr:	This func communicates with the MMI to
  !		get the operator error choice of the
  !		following alternatives. 
  !		1 - Repeat PPC
  !		2 - Take next PPC
  !		3 - Take next pallet
  !		4 - Attend after current PPC
  !		5 - Continue
  !	arg:	none
  !	ret:	answer of type num
  !------------------------------------------------------
  FUNC num PalGetErrChoice()
    
    VAR num answer;
    
    !Send "Select option"
    SendMsgToMmi MSG_SEL_ERR_OPT;
    !Read answer 1 to 5
    ReadMsgFromMmi answer;
    RETURN answer;
  ERROR
    RAISE;
  ENDFUNC
  
  !------------------------------------------------------
  !	name:	PalGetAckChoice
  !	descr:	This func display ack dialog text on
  !		the TPU. 
  !		It uses a text file to retrieve the text.
  !		The text to display is:
  !		Select choice when ready
  !	arg:	none
  !	ret:	choice of type num	
  !------------------------------------------------------
  FUNC num PalGetAckChoice()
  
    VAR num choice;
    
    !Send "Select option stop or cont."
    SendMsgToMmi MSG_SEL_ACK_OPT;
    !Read answer 4 or 5
    ReadMsgFromMmi choice;
    RETURN choice;
  ERROR
    RAISE;
  ENDFUNC
  
  !------------------------------------------------------
  !	name:	ChgPpcExtMMI
  !	descr:	This proc communicates with an external 
  !		MMI in order to display information 
  !		on the screen.
  !		The proc sends a request for a pallet 
  !		cycle number and reads the answer.
  !			 
  !	arg:	context of type num.
  !		current pallet cycle number of type num.
  !	ret:	new pallet cycle number of type num	
  !------------------------------------------------------					   
  FUNC num GetNewPalCycNo(
    num context,
    num palcyc_no)
  
    !Send "Select pallet cycle"
    SendMsgToMmi MSG_SEL_PALCYC;
    !Read pallet cycle number
    ReadMsgFromMmi palcyc_no;
    !Setup pallet cycle to run
    PalcycleDefault context\name:=PalCyc_names{palcyc_no}
            \palStation:=CfgCxtToPalStat{context}\feeder:=CfgCxtToFeeder{context};
    RETURN palcyc_no;
  ERROR
    RAISE;
  ENDFUNC
  
  !------------------------------------------------------
  !	name:	ChkGripToolEmpty
  !	descr:	This proc sends a message in order
  !		to get an acknowledge from the operator.
  !		The text to be displayed is:
  !		Check that gripper is empty
  !	arg:	none	
  !------------------------------------------------------
  PROC ChkGripToolEmpty()
    
    VAR num ack;
    
    !Send "Check gripper empty"
    SendMsgToMmi MSG_CHK_TOOL;
    !Wait for ack from operator
    ReadMsgFromMmi ack;
    !Check that the answer is equal to 5
    IF ack<>5 THEN
      PalReportError ERR_DLG_ANSWER \PAL_FATAL_ERROR;
    ENDIF
  ERROR
    RAISE;
  ENDPROC
  
ENDMODULE
