Functions; Scripts That Create Functions - Keithley 2601 Reference Manual

System sourcemeter 2600 series (smu)
Hide thumbs Also See for 2601:
Table of Contents

Advertisement

Series 2600 System SourceMeter® Instruments Reference Manual
scripts can be made available simultaneously within the limits of the memory available to the run-
time environment.
Named scripts are stored as global variables in the run-time environment. Like all other global
variables, when the unit is powered off, they are lost. There is non-volatile storage on the instrument
that can be used to store downloaded scripts across power cycles. See
this section for more information.

Functions

As previously explained, named scripts behave just like TSL functions. Executing a script is just like
executing a function with the same name as the script. Scripts, like functions, may return values.
Unlike functions, scripts may not take any parameters. In order to pass parameters to a chunk, you
must make a TSL function.
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
above function can be executed by sending the following message:
MyFunction(value for parameter1, value for parameter2)
Where
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 they are 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
messages to do this is shown as follows:
loadscript MakeMyFunction
MyFunction = function (who)
end
endscript
After this sequence of messages is sent, the
global variable named
because we have not executed the
MakeMyFunction()
which then creates the
If we now send the message
function, which causes the instrument to generate a response message with the text "Hello world"
in it.
2600S-901-01 Rev. C / January 2008
is a TSP chunk that will be executed when the function is called. The
function body
value for parameterN
MyFunction
print("Hello " .. who)
MakeMyFunction
. That message instructs the instrument to run the
MyFunction
MyFunction("world")
Return to
represents the values to be passed to the function call for the
with a script named
--The .. operator concatenates two strings.
MakeMyFunction
. The
MyFunction
script. Let us now send the message
MakeMyFunction
global variable that happens to be a function.
, the instrument will execute the
Section Topics
Section 2: TSP Programming
"Saving a user
. The sequence of
MakeMyFunction
script exists on the instrument in a
function however does not yet exist
MakeMyFunction
script" later in
script
MyFunction
2-5

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

26362602261126122635

Table of Contents