Section 6: Instrument programming
Models 707B and 708B Switching Matrix Reference Manual
6-20
707B-901-01 Rev. A / August 2010
Example 2
Code Notes
and
output
add_three = function(parameter1,
parameter2, parameter3)
return para para
parameter3
end
Creates a variable named
add_three
that has
a variable type of function.
print(add_three(3, 4, 5))
1.20001
Example 3
Code Notes
and
output
function sum_diff_ratio(parameter1,
parameter2)
psum = para parameter2
pdif = parameter1 - parameter2
prat = parameter1 / parameter2
return psum, pdif, prat
end
Returns multiple parameters (sum, difference,
and ratio of the two numbers passed to it).
sum, diff, ratio = sum_diff_ratio(2, 3)
print(sum)
print(diff)
print(ratio)
5.00000
-1.00000
6.666666667e-01
Create functions using scripts
You can use scripts to define functions. Scripts that define a function are like any other script: They
do not cause any action to be performed on the instrument until they are executed. The global
variable of the function does not exist until the script that created the function is executed.
A script can consist of one or more functions. Once a script has been run, the computer can call
functions that are in the script directly.
NOTE
The following steps use TSB Embedded. You can also use the
loadscript
and
endscript
commands to create the script. See
Create a script by sending commands over the remote interface
(on page 6-5).