Keithley SourceMeter 2600 Series Reference Manual page 58

Table of Contents

Advertisement

2-6
TSP Programming Fundamentals
Functions are created with a message in one of the following forms:
MyFunction = function (parameter1, parameter2) function body end
or
function MyFunction(parameter1, parameter2) function body end
Where
called. The above function can be executed by sending the following message:
MyFunction(value for parameter1, value for parameter2)
Where
for the given parameters. Note that when a function is defined, it is just another
global variable in the run-time environment. Just like all global variables, functions
will persist until it is removed from the run-time environment, overwritten, or the
unit is turned off.
Scripts that create functions
It is inconvenient in most cases to define a function in one message. The solution
is to create a script that defines a function. The scripts will be like any other script.
It will not cause any action to be performed on the instrument until it is executed.
Remember that creating a function is just creating a global variable that is a
function. That global variable will not exist until the chunk that creates it is
executed. In this case the chunk that creates it is a script. Therefore, the function
will not exist until the script that creates it is executed. This is often confusing to
first time users.
Example: Create the function
The sequence of messages to do this is shown as follows:
loadscript MakeMyFunction
endscript
After this sequence of messages is sent, the
instrument in a global variable named
however does not yet exist because we have not executed the
script. Let us now send the message
the instrument to run the
MyFunction
If we now send the message
the
MyFunction
message with the text "Hello world" in it.
2600S-901-01 Rev. A / May 2006
is a TSP chunk that will be executed when the function is
function body
value for parameterN
MyFunction = function (who)
print("Hello " .. who)
end
MakeMyFunction
global variable that happens to be a function.
function, which causes the instrument to generate a response
Return to
Series 2600 System SourceMeters Reference Manual
are the values to be passed to the function call
with a script named
MyFunction
--The .. operator concatenates two strings.
MakeMyFunction
MakeMyFunction
MakeMyFunction()
script which then creates the
MyFunction("world")
Section 2 topics
MakeMyFunction
script exists on the
. The
function
MyFunction
MakeMyFunction
. That message instructs
, the instrument will execute
.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents