SCPI commander - Scripts

This is the demo scripts that accompany the iPhone App SCPI Commander. This page tries to explain how the scripts works. For a complete list of commands see Command reference or open help from the editor in the app.

To get the demo-scripts back you only need to delete the script you need back and force-quit the app and then restart it.


 
Variables
set a 78 set b "A string" + a 6 - a 4 * a 9 / a 5 disp @a disp @b
This example show how to define variables with the SET command, and how to work directly with the variables to change it's value.

To get the variables value/content use the character @ before the name.

There are some variables that always are present and is read only:

  • Index - Current loop index
  • CurrenRow - Current executing row
  • ScriptName - The name of the current script
  • Time - The current time
  • Date - The current date
  • Buffsize - The current buffer size (can be changed by BuffSize command)
  • TimeOut - The current time out (can be changed by TimeOut Command)
  • ErrorNo - The last error number
  • Average# - Current average on the statistical array
  • AVG# - Current average of the statistical array
  • MEAN# - Current mean of the statistical array
  • MAX# - Current max value of the statistical array
  • MIN# - Current min vakue of the statistical array
  • STAT# - Number of numbers in the statistical array
  • MEDAIN# - Current median value of the statistical array
  • MED# - Current median value of the statistical array
  • STDDEV# - Current standard deviation of of the statistical array



Instrument used: None

 
Loop Example
loop 100 5 disp @index next
An example of how to define loops in the script.

This will loop from 5 to 100 and print out the index.



Instrument used: None

 
Send Read
alertask ip "Adress" "Enter address" open @ip out *idn? in a disp @a close
Show how to send command to an connected instrument and read back the result.

Row 1 opens a dialog asking the user for the address to the instrument, and stores the answer in variable ip.

Row 2 connects to the instrument.

Row 3 send the command *idn? To the instrument. The out command can be removed and you can only write *idn?.

Ro4 4 reads back the result as an ascii string

Row 5 displays the result

Row 6 closes the connection (not needed since when the script stops execution it automatically closes the connection.

NOTE!

When it comes to sending command and the command includes a space you need to encapsulate the command with i"



Instrument used: Any SCPI enabled instrument

 
Instrument Info
speed 10 alertask ip ”Address” ”Enter address” open @ip *idn? in idn manuf man @idn model mod @idn serial ser @idn fw fw @idn ? "IDN String:\n\n" @idn "\n" ? "Model: " @mod ? ”Manufacturer: " @man ? "Serial: " @ser ? "FW: " @fw
This script asks the instrument for it's identity string and then extracts the information and displays it.

Row 1 increases the speed of the script.

Row 4 sends the *idn? to the instrument since that's not a script command.

Row 6 to 9 extract information from the identityi string and store the value into variables.

Row 10 show how to construct a string with variables.



Instrument used: Any SCPI enabled instrument

 
DAQ970A Temp Stat
// Ask for the address alertask ip "Address" "Enter address" open @ip *rst // Reset the instrument to default setting // Initiate the statistical array statinit // Measure 10 temperatures with 1 second between loop 10 1 ":meas:temp:tc? K,(@105)" // type-K termocouple at channel 105 in temp round temp stat+ @temp ? @temp wait 1000 next // Display the statistical ? "\nAverage:" @avg# ? "Median: " @med# ? "Standard deviation:" @stddev# // Save all statistical data savestat stat.csv 2
An examples script that uses the statistical commands to calculate the temperature statistics using an DAQ970A to measure the temperature.

Row 7 Initiates the statistical array, is needed before doing any statistical calculations.

Row 13 rounds the measured temperature to 2 decimals

Row 14 adds the temperature to the statistical array.

Row 20 to 22 uses the build-in variables to show the statistics

Row 25 Saves the statistics value to a CSV file. The last command tells what is saved:

0 - Raw, all values is saved without any processing
1 - Raw sorted, all values are sorted
2 - Sorted width frequency, all values is sorted and the frequency or each value



Instrument used: Keysight DAQ970A + DAQM900A
 
DAQ970A Temp Stat 2
// Ask for the address alertask ip "Address" "Enter address" open @ip *rst // Reset the instrument to default setting // Initiate the statistical array statinit // Measure 10 temperatures with 1 second between loop 10 1 ":meas:temp:tc? K,(@105)" // type-K in temp round temp stat+ @temp & plotvar @temp "," plotcsv @plotvar ”Temperature” ? @temp wait 1000 next // Display the statistical ? "\nAverage:" @avg# ? "Median: " @med# ? "Standard deviation:" @stddev# // Save all statistical data savestat stat.csv 2
An examples script almost identical to the above script "DAQ970A Temp Stat 2". The difference is this one also plots the temperature during the measurement.

We do not use the statistical data to do the plot since the data is sorted after frequency and not all values are stored. Instead we use a variable and and values as CSV (Comma Separated Values)

Row 7 Initiates the statistical array, is needed before doing any statistical calculations.

Row 13 rounds the measured temperature to 2 decimals

Row 14 adds the temperature to the statistical array.

Row 15 appends the measured temperature to the plot-variable followed by a comma

Row 16 plots all measured temperatures so far

Row 22 to 24 uses the build-in variables to show the statistics

Row 25 Saves the statistics value to a CSV file. The last command tells what is saved:

0 - Raw, all values is saved without any processing
1 - Raw sorted, all values are sorted
2 - Sorted width frequency, all values is sorted and the frequency or each value



Instrument used: Keysight DAQ970A + DAQM900A

 
DMM Temp Stat
// Ask for the address alertask ip "Address" "Enter address" open @ip *rst // Reset the instrument to default setting // Initiate the statistical array statinit // Measure 10 temperatures with 1 second between loop 10 1 ":meas:temp? tc,k" // type-K termocouple in temp round temp stat+ @temp ? "Reading " @index ": " @temp " degree C" wait 1000 next // Display the statistical ? "\nAverage:" @avg# ? "Median: " @med# ? "Standard deviation:" @stddev# // Save all statistical data savestat stat.csv 2
An examples script that uses the statistical commands to calculate the temperature statistics using an DMM to measure the temperature.

Row 7 Initiates the statistical array, is needed before doing any statistical calculations.

Row 13 rounds the measured temperature to 2 decimals

Row 14 adds the temperature to the statistical array.

Row 20 to 22 uses the build-in variables to show the statistics

Row 25 Saves the statistics value to a CSV file. The last command tells what is saved:

0 - Raw, all values is saved without any processing
1 - Raw sorted, all values are sorted
2 - Sorted width frequency, all values is sorted and the frequency or each value



Instrument used: Keysight 34465A

 
Infiniivision Get Waveform
// Ask for address and connect alertask ip "Address" "Enter address" open @ip // Setup to get the waveform ":wav;uns 1" ":wav:byt lsbf" ":wav:form word" ":wav:data?" // Get the waveform inb wf // Display the data ?b @wf // Save the waveform as bin file savebin @wf waveform.bin
This script will get the waveform from an Infiniivsion Oscilloscope as a binary block and save so it can be used in another app or software.

You can use the files app on the iPhone to move the saved file to another device.

Row 7 - tells the instrument we want the binary block with the least significant byte first (LSBF), the default is Most Significant Byte First (MSBF). Only valid if the data-size is word.

Row 8 - We want the data-size to be word (16 bites), other choices can be byte or ascii.

Row 12 - Reads back as a binary block

Row 15 - Displays the binary block. If a second argument is given then it will display that number of rows, default is 10 rows

Row 17 - Saves the binary block



Instrument used: Keysight Infiniivsion Oscilloscope

 
Infiniivision Waveform To CSV
speed 10 alertask ip ”Address” ”Enter address” open @ip ”:wav:form ascii” ”:wav:poin 10” :wav:data? in b ? @b newcsv waveform.csv addvarcsv @b closecsv
This script will get the waveform from an Infiniivsion Oscilloscope as a binary block in ascii format and save it as a csv file.

The three last rows creates a csv file, add the waveform data to it and the close it.



Instrument used: Keysight Infiniivsion Oscilloscope

 
Infiniivision Getscreen
alertask ip "Address" "Enter address" open @ip *idn? in idn ":HARD:INK OFF" ":DISP:DATA? PNG, COLOR" wait 3000 inb b ?b @b 100 showpic @b @idn
An example script that show how simple it is to get a screenshot from instrument (if the instrument supports screenshots).

Row 5 and 6 tells the instrument to send back a binary block that contains picture data.

Row 7, wait enough time for the instrument to finish making he binary block.

Row 10, uses the built-in picture viewer to display the picture.



Instrument used: Keysight Infiniivsion Oscilloscope

 
ENA Getscreen
alertask ip "Address" "Enter address" open @ip *idn? in id ":HCOP:SDUM:DATA:FORM JPG" :HCOP:SDUM:DATA? wait 3000 inb pic ?b @pic showpic @pic @id
This script is almost identical with the previous script (Infiniivisio Getscreen), it only row 5 and 6 that have different commands that are sent to the instrument.



Instrument used: Keysight ENA Vector Network Analyzer

 
Plot Waveform Infiniivision Ascii
speed 10 // increase execution speed // Ask for the address alertask ip "Address" "Enter address" open @ip // Get the binary block of waveform data ”:wav:form ascii” ”:wav:poin 500” :wav:data? wait 1000 inb binblock ?b @binblock // Draw the waveform plotcsvbin @binblock ”Waveform”
A script that will read back the waveform as a binary block with data as ascii and then plot it.

Row 8 to 10 ask the instrument for the waveform data as binary block and data as ascii, and 500 points.

Row 11 - wait 1 s to make sure the bin block is ready

Row 16 - Plot the binary block


Instrument used: Keysight Infiniivsion Oscilloscope

 
Plot Waveform Infiniivision Bin B
speed 10 // increase execution speed // Ask for the address alertask ip "Address" "Enter address" open @ip // Get the binary block of waveform data ”:wav:form byte” ”:wav:poin 900” :wav:data? wait 1000 inb binblock ?b @binblock // Get the Preample information so we can plot ”:wav:pre?” in pa ? @pa // Extract the values we need getcsvvalue yinc 7 @pa getcsvvalue yori 8 @pa getcsvvalue yref 9 @pa getcsvvalue datasize 0 @pa // Draw the waveform plotbin @binblock ”Waveform” @yori @yinc @yref @datasize
A script that will read back the waveform as a binary block with data as byte and then plot it.

Row 8 to 10 ask the instrument for the waveform data as binary block and data as byte, and 900 points.

Row 11 - wait 1 s to make sure the bin block is ready

Row 16 - To be able to plot a byte binary block we need some more information that is not in the binary block:

Y-origin
Y-increment
Y-reference

Row 21-23 extracts the required values from a comma separated string.

Row 24 is not 100% necessary but here we extract the data size

Row 27 plots the waveform



Instrument used: Keysight Infiniivsion Oscilloscope

 
Plot Waveform Infiniivision Bin W
// This script show how to use byte order, by // asking for the word data size and LSBF speed 10 // increase execution speed // Ask for the address alertask ip "Address" "Enter address" open @ip // Get the binary block of waveform data ”:wav:form word” ”:wav:poin 900” // Ask for LSBF ":wav:byt lsbf" :wav:data? wait 1000 inb binblock ?b @binblock // Get the Preample information so we can plot ”:wav:pre?” in pa // Extract the values we need getcsvvalue yinc 7 @pa getcsvvalue yori 8 @pa getcsvvalue yref 9 @pa getcsvvalue datasize 0 @pa // Get the byteorder for word binary block ":wav:byt?" in bo byteorder @bo // Draw the waveform plotbin @binblock ”Waveform” @yori @yinc @yref @datasize
A script that will read back the waveform as a binary block with data as byte and then plot it.

Row 10 andd 11 ask the instrument for the waveform data as binary block and data as word, and 900 points.

Row 13 show how to ask for LSBF (Least Significant Byte First), if this row is deleted the data will be with MSBF (Most significant Byte First) as this is the default.

Row 11 - wait 1 s to make sure the bin block is ready

Row 20 - To be able to plot a byte binary block we need some more information that is not in the binary block:

Y-origin
Y-increment
Y-reference

Row 24-26 extracts the required values from a comma separated string.

Row 27 is not 100% necessary but here we extract the data size, since we know what kind of data we asked for.

Row 29 we asked for the byte order. If we know it's MSBF this row is not necessary.

Row 35 Plots the waveform



Instrument used: Keysight Infiniivsion Oscilloscope

 
Plot Waveform Infiniivision Bin X-Axis
speed 10 // increase execution speed // Ask for the address alertask ip "Address" "Enter address" open @ip // Get the binary block of waveform data ”:wav:form byte” ”:wav:poin 900” :wav:data? wait 1000 inb binblock ?b @binblock // Get the Preample information so we can plot ”:wav:pre?” in pa ? @pa // Extract the values we need getcsvvalue yinc 7 @pa getcsvvalue yori 8 @pa getcsvvalue yref 9 @pa getcsvvalue datasize 0 @pa // Get values for scaling X-axis getcsvvalue xori 5 @pa getcsvvalue xinc 4 @pa getcsvvalue xref 6 @pa // We want to scale the x-axis, use us xaxis# @xori @xinc @xref 1000000 // Draw the waveform plotbin @binblock ”Waveform” @yori @yinc @yref @datasize
Almost the same as the script "Plot waveform Infiniivision Bin B". The change is that the X-axis is also scaled.

Row 26-29 Get's all the required data from the instrument to be able to scale the X-axis

Row 32: Tells SCPI-commander how to scale the X-axis. The last parameter is to make sure we get the scale in micro-seconds (the instrument manual should tell you what the X-values is scaled to)


Instrument used: Keysight Infiniivsion Oscilloscope

 
Statistical Plot
speed 10 // increase execution speed statinit // Initiate statistical array // Generate some statistical data loop 100 1 rnd a * a 10 int a stat+ @a next // Plot as a Bar Chart plotstatbar "Example Bar Chart" wait 5000 // wait 5 seconds // Plot as a Line Chart plotstatline "Example Line Chart"
This script shows how to use the two different plot graphs available - Bra Graph and Line Graph.

Row 2 - Initiate the statistical array

Row 5 to 10 generate 100 random values and add to statistical array.

Row 6 - Generate a random number between 0 and 1

Row 7 - make it between 0 and 9

Row 8 - Make the number an integer between 0 and 9

Row 9 - add to statistical array

Row 13 - Plot as a Bar Chart

Row 18 - Plot as a Line Chart


Instrument used: None
 
Statistical Plot V2
speed 10 // increase execution speed statinit // Initiate statistical array clearchart // make sure we start with an empty chart // Generate some statistical data loop 100 1 rnd a * a 10 int a stat+ @a next // Plot as a Bar Chart plotstatbar "Example Bar Chart" wait 2000 // wait 2 seconds clearchart // Clear the current chart wait 2000 // Plot as a Line Chart plotstatline "Example Line Chart"
This script works almost like the above script "Statistical plot" except we use the command clear chart to clear the chart before plotting the Bar chart and also before displaying the line chart.

Instrument used: None

 
Guess the Number
// Guess the number your phone thinks about // between 0 and 100 speed 0 set count 1 rnd number * number 100 int number label ask alertask guess "Guess" "Between 0 & 100" if= @guess @number Correct if< @guess @number Smal banner s e "Wrong!" alertok "Your guess" "Too Big!" + count 1 jmp Ask label Correct int count banner s s "Correct!" alertok "Your Guess" "Correct!!!\n\n" @count " Guesses" stop label Smal banner s e "Too Smal!" alertok "Your Guess" "To Smal!" + count 1 jmp Ask
An example of a script that doesn't use any instrument but instead is a simple game where you try to guess what number the app is thinking of.

It shows how comparison and jump with a script is used.

Row 15 - it compares to see if it's equal and if it is, it jumps to the label Correct




Instrument used: None

 
OnError Example
// OnError Example ? ”Get the idenity” *idn? in idn ? @idn OnError ? ”Error occured” ? ”Error no” @errorno
An example of how the OnError works. All code after OnError is ONLY executed when an error occurs in the main script. And error aft OnError will be handled as a normal error.

Row 5 - Will trigger an error since we are not connected to an instrument.

Row 9 - This and the following rows will be executed after an error occurs.




Instrument used: None

 
Timestamp
speed 10 // Get the star timestamp set startt @timestamp // Display numbers 1 to 100 loop 100 1 ? @index next // Get the end timestamp set stopt @timestamp // Calculate how many seconds the loop took - stopt @startt ? \n @stopt ” - Seconds”
This example show how to use the timestamp variable to calculate how long time a code-block takes to execute.

Row 4: - Get the start time.

Row 6-9 The code block we want measure spend time on

Row 12: Get the end time

Row 15: Calculate the number of seconds it took.



Note: Timestamp returns the number of seconds since jan 1, 2001 00:00:00



Instrument used: None


© 2018-2020 Michael Augustsson Contact Me

improve your online experience. Take a look at the Cookie Privacy to learn more and also my Privacy Policy. By pressing Dismiss I assume you are happy to allow the use of these cookies.