Section 6: Instrument programming
Example 3
function sum_diff_ratio(first_value,
second_value)
psum = first_value + 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)
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.
The following steps use TSB Embedded. You can also use the loadscript and endscript
commands to create the script over the remote interface. See
over the remote interface
Steps to create a function using a script:
1. In TSB Embedded, enter a name into the TSP Script box. For example, type MakeMyFunction.
2. Enter the function as the body of the script. This example concatenates two strings:
MyFunction = function (who)
print ("Hello".. who)
end
3. Select Save Script.
4. MakeMyFunction is now on the instrument in a global variable with the same name as the script
(MakeMyFunction). However, the function defined in the script does not yet exist because the
script has not been executed.
5. Run the script as a function. For this example, send:
MakeMyFunction()
This instructs the instrument to run the script, which creates the MyFunction global variable.
This variable is of the type "function" (see
6-20
Model 2651A High Power System SourceMeter® Instrument Reference Manual
(on page 6-4).
Variable types
Returns multiple parameters (sum, difference, and
ratio of the two numbers passed to it).
Output:
5
-1
0.66666666666667
Load a script by sending commands
(on page 6-17)).
2651A-901-01 Rev. C October 2021
Need help?
Do you have a question about the Keithley 2651A and is the answer not in the manual?