Common Scripting Use Cases

NI RF Signal Generator

Common Scripting Use Cases

Refer to scripting instructions for examples of using primary scripting instructions, including generate, repeat/end repeat, wait, and clear.

Single Waveform (one-shot/finite generation)

script singleWfmExample   generate wfm01
end script

This script generates wfm01 and then stops. When generation stops, the last sample of wfm01 is held at the output.

Generating Waveforms with Markers

script wfm01MarkersExample
  generate wfm01 marker0 (0, 20)
end script

This script generates the entire wfm01 waveform and generates a Marker event at samples 0 (the start of the waveform) and 20.

Sequence of Multiple Waveforms

script upWfm01DownExample
    generate countUp
    generate wfm01
    generate countDown
end script

Conditional Branching — If/Else

script branchingExample
    repeat forever
    generate wfm01
    if scripttrigger0 then
        generate wfm02
    else
        generate wfm03
    end else
    end repeat
end script

The following diagram illustrates the preceding script behavior:

Generating Waveform Subsets

script wfm01SubsetExample
  generate wfm01 subset (20, 60)
end script

This script generates 60 samples from wfm01, starting at sample 20.

 Note  The subset beginning sample number must be an integer multiple of 4. The subset number of samples must also be an integer multiple of 4.

Finite Repetition (N Times)

script up3Wfm01DownExample
    generate countUp
    repeat 3
        generate wfm01
    end repeat
    generate countDown
end script

Conditional Repetition — Repeat until Trigger

script upWfm01UntilTrigDownExample
    generate countUp
    repeat until scripttrigger0
        generate wfm01
    end repeat
generate countDown
end script

Continuous Generation — Repeat Forever

script upThenUpAndDownForeverExample
    generate countUp
    repeat forever
        generate countUpAndDown
    end repeat
end script

Waiting for Triggers

script upWaitWfm01DownExample
    generate countUp
    wait until scripttrigger0
    generate wfm01
    generate countDown
end script


The following diagrams illustrate the preceding script behavior:


or

script upWaitWfm01DownExample
    generate countUp
    clear scripttrigger0
    wait until scripttrigger0
    generate wfm01
    generate countDown
end script



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

Finite Wait

script upWait32DownExample
    generate countUp
    wait 32
    generate countDown
end script

Stepping Through Multiple Waveforms

script stepThroughUpAllZerosDownExample
    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 burstThroughUpDownThenZerosOnesExample
    repeat forever
        repeat until scripttrigger0
            generate countUp
            generate countDown
        end repeat

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