Code example

//--------------------------------------------------------//

//Example User Program to use the G-Code import service

//--------------------------------------------------------//

(* Please note that in this example, the import (and any other action) is only executed once. E.g. to restart the import, toggle the variable GCodeImport.stIn.stProcess.xStartImport for one cycle. Inputs will be recognized only on a rising edge. The same needs to be done when changing the source directory or getting file names *)

//--------------------------------------------------------//

 

User_PRG (PRG):

GCodeImport:
SEW_MK_Robotics.SEW_RobGCode.GCodeImport;

 

User_PRG.Init:

// Link the robot to the G-Code import function block

xInitDone :=
(* xInitDone AND *)GCodeImport.LinkModule(MyRobot);

 

User_PRG.Main:

// CallMain() has to be called in every cycle of TaskMain()

GCodeImport.CallMain();

 

// Enable connection to server PC

IF NOT GCodeImport.stOut.stCommunication.xIsConnected

AND NOT GCodeImport.stOut.stProcess.xFileImported THEN

  GCodeImport.stIn.stCommunication.sServerIP :=
  '192.168.10.20';

  GCodeImport.stIn.stCommunication.xEnable := TRUE;

  RETURN;

END_IF

 

// If connected, import a G-code

IF GCodeImport.stOut.stCommunication.xIsConnected THEN

  // Set a source directory to list the files within

  IF NOT GCodeImport.stIn.stDirectory.xSetPath THEN

    GCodeImport.stIn.stDirectory.sPath :='C:\GCodeDirectory';

    GCodeImport.stIn.stDirectory.xSetPath := TRUE;

  END_IF

  // Get the names of the first 20 files in this directory

  IF NOT GCodeImport.stIn.stDirectory.xGetFileNames

  AND GCodeImport.stOut.stDirectory.xPathSet THEN

    GCodeImport.stIn.stDirectory.xGetFileNames := TRUE;

  END_IF

  // Start import of the first found file

  IF NOT GCodeImport.stIn.stProcess.xStartImport

  AND GCodeImport.stOut.stDirectory.xFileNamesReceived THEN

    GCodeImport.stIn.stProcess.uiProgramslot := 1;

    GCodeImport.stIn.stProcess.eGCodeDialect :=

     SEW_MK_Robotics.SEW_RobGCode.E_GCodeDialect.Norm;

    GCodeImport.stIn.stProcess.rScaleTranslation := 1.0;

    GCodeImport.stIn.stProcess.rScaleRotation := 1.0;

    GCodeImport.stIn.stProcess.rScaleSpeed := 1.0;

    GCodeImport.stIn.stProcess.uiInsertSrlCommmands :=

     SEW_MK_Robotics.SEW_RobGCode.

     E_GCodeInsertSRLCommand.Blending

    OR SEW_MK_Robotics.SEW_RobGCode.

     E_GCodeInsertSRLCommand.MotionSet;

    GCodeImport.stIn.stProcess.usiMotionSetIndex := 1;

    GCodeImport.stIn.stProcess.rBlendingDistance := 10.0;

    GCodeImport.stIn.stProcess.sFileName :=

     GCodeImport.stOut.stDirectory.asFileName[1];

    GCodeImport.stIn.stProcess.xStartImport := TRUE;

  END_IF

END_IF

// Optional disconnection after completed import

IF GCodeImport.stOut.stProcess.xFileImported THEN

  GCodeImport.stIn.stCommunication.xEnable := FALSE;

END_IF