PLC main program frame
Programming Example
MCV HLI Interface
PROGRAM MAIN
VAR
Hli : MCV_HliInterface;
MessageOutput : R_TRIG;
HliInitialized : BOOL := FALSE; (* State of initialisation of the HLI *)
HliInitError : BOOL := FALSE; (* Error state while initialising the HLI *)
UserInitialisationDone : BOOL := FALSE; (* Result of application specific initialisation *)
ChHliIdx : UDINT; (* Index of a channel specific HLI area *)
AxHliIdx : UDINT; (* Index of an axis specific HLI area *)
Feedhold : BOOL := FALSE;
Override : UINT := 1000;
END_VAR
(* Request description of the HLI from the CNC *)
Hli(Start := TRUE);
(* Check if initialisation of HLI finished successfully and if
errors occurred during initialisation phase. *)
errors occurred during initialisation phase. *)
IF Hli.Initialised = TRUE AND Hli.Error = FALSE THEN
(* Do the initialisation we do once the PLC starts up. *)
IF UserInitialisationDone = FALSE THEN
(* Get the result of the user defined initialisation *)
UserInitialisationDone := UserInitialisations();
ADSLOGSTR( msgCtrlMask := ADSLOG_MSGTYPE_MSGBOX
OR ADSLOG_MSGTYPE_LOG,
msgFmtStr := 'High Level Interfaces initialised: s',
strArg := HLI_INTF_ISG_VERSION);
OR ADSLOG_MSGTYPE_LOG,
msgFmtStr := 'High Level Interfaces initialised: s',
strArg := HLI_INTF_ISG_VERSION);
END_IF
(* ------------------------------------------ *)
(* TODO: Add your application code right here *)
(* ------------------------------------------ *)
ELSE
MessageOutput(CLK := Hli.Error);
IF Hli.Error = TRUE THEN
(* Error occurred while initialising the HLI *)
(* ErrorId contains error code *)
IF MessageOutput.Q THEN
ADSLOGDINT( msgCtrlMask := ADSLOG_MSGTYPE_ERROR
OR ADSLOG_MSGTYPE_MSGBOX
OR ADSLOG_MSGTYPE_LOG,
msgFmtStr := 'Error initialising the
HLI interface error code: %d',
dintArg := Hli.ErrorId);
OR ADSLOG_MSGTYPE_MSGBOX
OR ADSLOG_MSGTYPE_LOG,
msgFmtStr := 'Error initialising the
HLI interface error code: %d',
dintArg := Hli.ErrorId);
END_IF
HliInitError := TRUE;
END_IF;