PLC-Hauptprogrammrahmen

Programmierbeispiel

MCV HLI-Interface

PROGRAM MAIN
VAR
  Hli                   : MCV_HliInterface;
  MessageOutput         : R_TRIG;
  HliInitialized        : BOOL := FALSE; (* State of initialization of the HLI *)
  HliInitError          : BOOL := FALSE; (* Error state while initializing the HLI *)
  UserInitialisationDone : BOOL := FALSE; (* Result of application specific initialization *)
  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 initialization of HLI finished successful and if
   errors occured during initialization phase. *)
IF Hli.Initialized = TRUE AND Hli.Error = FALSE THEN
  (* Do the initialization we do once the PLC starts up. *)
  IF UserInitialisationDone = FALSE THEN
    (* Get the result of the user defined initialization *)
    UserInitialisationDone := UserInitialisations();
    ADSLOGSTR( msgCtrlMask := ADSLOG_MSGTYPE_MSGBOX
                           OR ADSLOG_MSGTYPE_LOG,
               msgFmtStr   := 'High Level Interfaces initialized: 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 occured while initializing the HLI *)
    (* ErrorId contains error code *)
    IF MessageOutput.Q THEN
      ADSLOGDINT( msgCtrlMask := ADSLOG_MSGTYPE_ERROR
                              OR ADSLOG_MSGTYPE_MSGBOX
                              OR ADSLOG_MSGTYPE_LOG,
               msgFmtStr   := 'Fehler beim Initialisieren des
                               HLI-Interfaces Fehlercode: %d',
                   dintArg := Hli.ErrorId);
    END_IF
   HliInitError := TRUE;
END_IF;