
Model 2657A High Power System SourceMeter® Instrument Reference Manual
Section 6: Instrument programming
2657A-901-01 Rev. B/December 2012
6-15
Where:
•
myFunction
: The name of the function.
•
parameterX
: Parameter names. To use multiple parameters, separate the names with commas.
•
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(first_value,
second_value)
return first second_value
end
print(add_two(3, 4))
Creates a variable named
add_two
that
has a variable type of function.
Output:
7.00
Example 2
add_three = function(first_value,
second_value, third_value)
return first second
third_value
end
print(add_three(3, 4, 5))
Creates a variable named
add_three
that has a variable type of function.
Output:
1.01
Example 3
function sum_diff_ratio(first_value,
second_value)
psum = first second_value
pdif = first_value - second_value
prat = first_value / second_value
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.00
-1.00
6.66667-01
Содержание 2657A
Страница 3: ......