Model 2651A High Power System SourceMeter® Instrument Reference Manual
Section 6: Instrument programming
2651A-901-01 Rev. A / March 2011
6-19
Where:
•
myFunction
: The name of the function
•
parameterX
: Parameter values. You can have multiple parameters. Change the value defined
by
X
for each parameter and use a comma to separate the values.
•
functionBody
is the code that is executed when the function is called
To execute a function, substitute appropriate values for
parameterX
and insert them into a message
formatted as:
myFunction
(
valueForParameterX
,
valueForParameterY
)
Where
valueForParameterX
and
valueForParameterY
represent the values to be passed to
the function call for the given parameters.
Example 1
function add_two(parameter1, parameter2)
return para parameter2
end
print(add_two(3, 4))
Creates a variable named
add_two
that
has a variable type of function.
Output:
7.00000
Example 2
add_three = function(parameter1,
parameter2, parameter3)
return para para
parameter3
end
print(add_three(3, 4, 5))
Creates a variable named
add_three
that has a variable type of function.
Output:
1.20001
Example 3
function sum_diff_ratio(parameter1,
parameter2)
psum = para parameter2
pdif = parameter1 - parameter2
prat = parameter1 / parameter2
return psum, pdif, prat
end
sum, diff, ratio = sum_diff_ratio(2, 3)
print(sum)
print(diff)
print(ratio)
Returns multiple parameters (sum,
difference, and ratio of the two numbers
passed to it).
Output:
5.00000
-1.00000
6.666666667e-01