Example SCPI Script
This script connects to an N6705C power analyzer using its alias. The defaultChannel
for the connection is set to 2
. By default, all the commands sent to the device are addressed to that channel.
The script then uses a repeat loop to set the voltage to different values and retrieves the actual measured voltages. At the end, it displays some information about the differences between the set and actual voltages.
The script uses a tell
block to enclose the portion of the script that communicates with the device. This means that all the device-related commands, like reset
and setValue
, are sent to the device.
SenseTalk commands within the tell
block continue to function normally. Technically, they are also sent to the powerAnalyzer
object, but since that object doesn’t implement a put
or insert
command, the commands are passed along to the engine as usual.
For a line-by-line description of the script, see the Example Script Analysis section.
Example Script
set powerAnalyzer to visaDevice ("N6705CPower")
set powerAnalyzer’s defaultChannel to 2
tell powerAnalyzer
reset
setValue output, on
repeat with testVoltage = 3300 millivolts to 4.4 volts stepping by 100 millivolts
setValue voltage, testVoltage
query "measure voltage"
put value(it) volts into measuredVolts
put ABS(measuredVolts - testVoltage) into difference
convert difference to microvolts
insert difference into allDifferences
put !"Set voltage to [[testVoltage]] Actual measured was [[measuredVolts]] (difference [[difference]])"
end repeat
setValue output, off
end tell
put
put "Differences: " & allDifferences sorted
put
put "Average: " & average of allDifferences
put "Median: " & median of allDifferences