<?xml version="1.0" encoding="utf-8"?>

<ExportedUserProgram
    Version="1.0.0">
   <VariableTable>
   <Variable
       Offset="31"
       TagName="iCmdSeq"
       Format="DINT"
       DefaultValue="0"/>
   <Variable
       Offset="32"
       TagName="CmdSeq"
       Format="REAL"
       ArraySize="100"
       DefaultValue="1"
       Description="1 = moveto pos"
       ArrayDesc="Start of the cmd sequence."/>
   <Variable
       Offset="33"
       ArraySize="-1"
       DefaultValue="13.3"/>
   <Variable
       Offset="34"
       ArraySize="-2"
       DefaultValue="2"
       Description="2 = delay"/>
   <Variable
       Offset="35"
       ArraySize="-3"
       DefaultValue="0.5"/>
   <Variable
       Offset="36"
       ArraySize="-4"
       DefaultValue="2"
       Description="1 = move"/>
   <Variable
       Offset="37"
       ArraySize="-5"
       DefaultValue="5"/>
   <Variable
       Offset="38"
       ArraySize="-6"
       DefaultValue="2"
       Description="2 = delay"/>
   <Variable
       Offset="39"
       ArraySize="-7"
       DefaultValue="0.5"/>
   <Variable
       Offset="40"
       ArraySize="-8"
       DefaultValue="3"
       Description="3 = sine"/>
   <Variable
       Offset="41"
       ArraySize="-9"
       DefaultValue="0.5"
       Description="amp"/>
   <Variable
       Offset="42"
       ArraySize="-10"
       DefaultValue="3"
       Description="freq"/>
   <Variable
       Offset="43"
       ArraySize="-11"
       DefaultValue="3"
       Description="cycles"/>
</VariableTable>
   <DiscreteIO/>
   <UserProgram
    Name="DoCmdSequence"
    Type="STEP"
    Number="2"
    Desc="This program parses and executes commands in the variable table array called &quot;CmdSequence&quot;.&#13;&#10;The following commands are supported:&#13;&#10;&#13;&#10;1) Moves to a position&#13;&#10; &#32;&#32;&#32;parameter1: position&#13;&#10;&#13;&#10;2) Delay&#13;&#10; &#32;&#32;&#32;parameter1: delay time&#13;&#10;&#13;&#10;3) Sine wave for a certain number of cycles.&#13;&#10; &#32;&#32;&#32;parameter1: amplitude &#32;&#32;&#13;&#10; &#32;&#32;&#32;parameter2: frequency &#32;&#13;&#10; &#32;&#32;&#32;parameter3: number of cycles&#13;&#10;&#13;&#10;This program looks at the CmdSequence array and does the command. When the command is finished, it increments iCmdSeq the correct amount, and repeats until it reaches a zero command.&#13;&#10;&#13;&#10;This example can be modifed for different commands or sequences."
    SingleInstance="True"
    TaskMask="32767">
   <ProgramBlock
       Type="STEP">
      <Comment
          Comment="Set counter to zero to start at beginning of the command array."/>
      <Step>
         <Expression
             Src="iCmdSeq := 0;"/>
      </Step>
      <Transition>
         <Jump
             Type="NEXT"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP"
       Label="CmdSeqLoop">
      <Step/>
      <Transition>
         <CheckCondition
             Type="CASE"
             Condition="CmdSeq[iCmdSeq] = 1.0"
             True="PosCmd"/>
         <CheckCondition
             Type="CASE"
             Condition="CmdSeq[iCmdSeq] = 2.0"
             True="DelayCmd"/>
         <CheckCondition
             Type="CASE-ELSE"
             Condition="CmdSeq[iCmdSeq] = 3.0"
             True="SineCmd"
             False="EndCmdSeq"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP"
       Label="PosCmd">
      <Comment
          Comment="Move the axis to a position.&#13;&#10;&#13;&#10;Increment the counter by two because this command used two variables.&#13;&#10;The Expression command is last so that the counter is incremented after it is used."/>
      <Step>
         <Command
             Command="20"
             CmdAxes="1"
             CmdPrm1="CmdSeq[iCmdSeq + 1]"
             CmdPrm2="20.0"
             CmdPrm3="100.0"
             CmdPrm4="100.0"
             CmdPrm5="Nearest (0)"/>
         <Expression
             Src="iCmdSeq := iCmdSeq + 2;"/>
      </Step>
      <Transition>
         <CheckCondition
             Type="CASE-ELSE"
             Condition="_Axis[0].StatusBits.InPos"
             True="CmdSeqLoop"
             False="Wait"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP"
       Label="DelayCmd">
      <Comment
          Comment="Delay for a certain time.&#13;&#10;&#13;&#10;Increment the counter by two because this command used two variables.&#13;&#10;The Expression command is last so that the counter is incemented after it is used."/>
      <Step>
         <Expression
             Src="iCmdSeq := iCmdSeq + 2;&#13;&#10;LOG_EVENT(CmdSeq[iCmdSeq - 1]);"/>
      </Step>
      <Transition>
         <Delay
             Type="JUMP"
             Duration="CmdSeq[iCmdSeq - 1] &#32;//because we already incremented the counter ( +1 - 2 = -1)"
             Next="CmdSeqLoop"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP"
       Label="SineCmd">
      <Comment
          Comment="Does a sine wave.&#13;&#10;&#13;&#10;First parameter (iCmdSeq + 1) is amplitude.&#13;&#10;Second parameter (iCmdSeq + 2) is frequency.&#13;&#10;Third parameter (iCmdSeq + 3) is number of cycles.&#13;&#10;&#13;&#10;Increment the counter by two because this command used four variables."/>
      <Step>
         <Command
             Command="72"
             CmdAxes="1"
             CmdPrm1="_Axis[0].TarPos"
             CmdPrm2="CmdSeq[iCmdSeq + 1]"
             CmdPrm3="CmdSeq[iCmdSeq + 2]"
             CmdPrm4="CmdSeq[iCmdSeq + 3]"
             CmdPrm5="Auto (0)"
             CmdPrm6="&lt;None&gt;"/>
         <Expression
             Src="iCmdSeq := iCmdSeq + 4;"/>
      </Step>
      <Transition>
         <CheckCondition
             Type="CASE-ELSE"
             Condition="_Axis[0].StatusBits.TGDone"
             True="CmdSeqLoop"
             False="Wait"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP"
       Label="EndCmdSeq">
      <Step/>
      <Transition>
         <End/>
      </Transition>
   </ProgramBlock>
</UserProgram>
</ExportedUserProgram>
