Common Scripting Use Cases

NI Script Editor

Common Scripting Use Cases

Single Waveform

script upOnly   generate countUp
end script

Generating Waveform Subsets

script upOnlySubset
  generate countUp subset (10, 40)
end script

Note  This code snippet generates 40 samples from upOnly, starting at sample 10.

Generating Waveforms with Markers

script upOnlyWithMarkers
  generate countUp marker0 (0, 20)
end script

Note  This code snippet generates the entire countUp waveform and generates a Marker event at samples 0 (the start of the waveform) and 20.

Sequence of Multiple Waveforms

script upAllOnesDown
    generate countUp
    generate allOnes
    generate countDown
end script

Finite Repetition (N Times)

script up3AllOnesDown
    generate countUp
    repeat 3
        generate allOnes
    end repeat
    generate countDown
end script

Conditional Branching — If/Then Else

script upOnesOrDown
    generate countUp
    if scripttrigger0 then
        generate allOnes
    else
        generate countDown
    end else
end script

Conditional Repetition — Repeat until Trigger

script upAllOnesUntilTrigDown
    generate countUp
    repeat until scripttrigger0
        generate allOnes
    end repeat
generate countDown
end script

Continuous Generation — Repeat Forever

script upThenUpAndDownForever
    generate countUp
    repeat forever
        generate countUpAndDown
    end repeat
end script

Waiting for Triggers

script upWaitAllZerosDown
    generate countUp
    wait until scripttrigger0
    generate allZeros
    generate countDown
end script

or

script upWaitAllZerosDown
    generate countUp
    clear scripttrigger0
    wait until scripttrigger0
    generate allZeros
    generate countDown
end script

Note  These two scripts are similar, but a script received during generation of countUp causes the first script to move to allZeros after the smallest possible delay. By adding a clear instruction, you can ignore any triggers received before the wait instruction.

Finite Wait

script upWait32Down
    generate countUp
    wait 32
    generate countDown
end script

Stepping Through Multiple Waveforms

script stepThroughUpAllZerosDown
    repeat forever
        generate countUp
        clear scripttrigger0
        wait until scripttrigger0

        generate allZeros
        clear scripttrigger0
        wait until scripttrigger0

        generate countDown
        clear scripttrigger0
        wait until scripttrigger0

    end repeat
end script

Bursting through Multiple Waveforms

script burstThroughUpDownThenZerosOnes
    repeat forever
        repeat until scripttrigger0
            generate countUp
            generate countDown
        end repeat

        repeat until scripttrigger0
            generate allZeros
            generate allOnes
        end repeat
    end repeat
end script