The Script window allows execution of WaveForms scripts. The scripting language is JavaScript, based on the ECMA Script standard.
From the script code, objects behind the user interface can be accessed. This allows configuration using the interface and automating parts of it with script.
See Menu in Common Interfaces.
The control toolbar allows you to debug and execute the script.
The output window contains the print() messages and error log.
The instrument's object can be accessed from the script and has the most relevant child objects and parameters shown in the table below.
The instrument parameters are stored in objects with the following properties:
wait(seconds) |
Waits the specified time expressed in seconds. If the value is 0 or if the argument is missing, then the function is ignored. With negative value, it waits until stopped. Returns false when the script is stopped; otherwise returns false. | |
print(arg0,arg1,...) | Prints the arguments to the Output window. | |
Device | ||
.isConnected | is connected to a device | |
.name | device name | |
.SN | serial number | |
instrument# | common instrument object | |
.single() | single acquisition | |
.run() | run instrument | |
.stop() | stop instrument | |
.wait() | wait for the acquisition to be done or instrument stopped | |
.State | ||
.text | instrument states: Disabled, Ready, Done, Stop, Busy, Error, Config, Armed, Trig'd, Running, Auto, Scan, Wait | |
.running() | returns true when the instrument is in active state, >= Config | |
.Rate.value | refresh rate of the instrument, the device communication rate | |
.Time | ||
.Position.value | ||
.Base.value | ||
.Samples.value | ||
.Rate.value | ||
Scope# | ||
.measure(name) | global measurements | |
.Trigger | trigger configuration | |
.Mode.text | acquisition mode: Normal, Auto, None | |
.Run.text | run-scan mode: Repeated, Screen, Shift | |
.Type.text | trigger type: Edge, Pulse, Transition | |
.Source.text | trigger source | |
.Condition.text | condition: Rising, Falling or Positive, Negative | |
.Level.value | ||
.Hysteresis.value | ||
.LCondition.value | ||
.Length.value | ||
.HoldOff.value | ||
.Filter.text | sample type to use when looking for trigger condition: Decimate, Average | |
.BufferSize.value | PC buffer size | |
.Buffer.value | selected PC buffer index | |
.Digital.checked | enable or disable digital channels | |
.DigitalChannels | digital channels, same as Analyzer#.Channels | |
.DigitalTrigger | same as Analyzer#.Trigger | |
.channel# | the following properties are available for Math and Ref channels as well: | |
.checked | channel checked, visible | |
.data | get data array | |
.measure(name) | Channel measurements: Minimum, Maximum, Average, Peak2Peak, Low, High, Amplitude, Middle, ... | |
.Offset.value | ||
.Range.value | ||
.histogram | gets the histogram array | |
.HistogramIndex2Data(index) | returns the “voltage” value corresponding to the histogram array index | |
.Channel# | real channels | |
.Attenuation.value | ||
.Noise.checked | ||
.SampleMode.text | sampling mode: Decimate, Average, Min/Max | |
.Ref# | reference channels | |
.data | set data | |
.clone(channel) | clone with channel | |
.TimeRef | reference channel time | |
.Units.text | ||
.Noise.checked | ||
.Math# | mathematic channels | |
.Operation.text | simple mode operation | |
.A | simple mode channel A | |
.B | simple mode channel B | |
.Custom.checked | enable custom mode | |
.Function.text | custom function | |
.Units.text | ||
.Histogram | ||
.Autoscale.checked | ||
.Top.value | top of the scale to use when auto-scale is unchecked | |
.Wavegen# | ||
.Synchronization.text | synchronization mode: No synchronization, Independent, Synchronized, Auto synchronized | |
.States | common synchronization states settings | |
.Trigger.text | ||
.Wait.value | ||
.Run.value | ||
.Repeat.value | ||
.RepeatTrigger.checked | ||
.Channel# | ||
.Mode.text | configuration mode: Simple, Basic, ... | |
.Options | ||
.IdleOutput.text | idle output value: Offset, Initial, Disabled | |
.States | channel states configuration | |
.Simple | ||
.Type.text | waveform type: Sine, Square, ... | |
.Frequency, Offset, Amplitude, Symmetry, Phase | ||
.value | ||
.Basic | ||
.Type.text | ||
.Frequency, Offset, Amplitude, Symmetry, Phase | ||
.value | ||
.Min.value | ||
.Max.value | ||
.Custom | ||
.Type | ||
.text | ||
.set(name,array) | set custom waveform data (normalized to +-1) identified by name | |
.add(array) | add custom waveform, name of waveform is returned | |
.Frequency, Offset, Amplitude, Symmetry, Phase | ||
.value | ||
.Sweep | ||
.Type | ||
.text | ||
.set(name,array) | set custom waveform data (normalized to +-1) identified by name | |
.add(array) | add custom waveform, name of waveform is returned | |
.Offset, Symmetry, Phase | ||
.value | ||
.Frequency | ||
.checked | enable sweeping | |
.Start.value | start frequency | |
.Stop.value | stop frequency | |
.Time.value | sweep time | |
.Amplitude | ||
.checked | enable damping | |
.Start.value | start amplitude | |
.Stop.value | stop amplitude | |
.Time.value | damp time | |
.Analyzer# | ||
.Trigger | trigger configuration | |
.Mode.text | acquisition mode: Normal, Auto, None | |
.Clock.text | clock source: Internal, External | |
.Source.text | trigger source | |
.Run.text | run-scan mode: Repeated, Screen, Shift | |
.BufferSize.value | PC buffer size | |
.Buffer.value | selected PC buffer index | |
.Channels | ||
.channel | channel like: DIO1, Bus1, SPI1 | |
.name | channel name | |
.data | get data array | |
.DIO# | ||
.DIO.value | digital I/O pin index | |
.Trigger.text | trigger: Ignore, Rise, Fall, Edge, High, Low | |
.Bus# | ||
.Enable.DIO.value | enable pin | |
.Clock.DIO.value | clock pin | |
.Active.text | enable active level: Low, High | |
.Polarity.text | sampling clock edge: Rising, Falling | |
.Format.text | ||
.Endianness.text | ||
.MSB.text | ||
.LSB.text | ||
.Pin# | ||
.DIO.value | digital I/O pin index | |
.SPI# | ||
.Select, Clock, Data | ||
.DIO.value | digital I/O pin index | |
.Active.text | select active level: Low, High | |
.Sample.text | sampling clock edge: Rising, Falling | |
.First.text | data bit order: LSB, MSB | |
.Bits.value | word bits | |
.Format.text | ||
.Leading.value | skip leading bits | |
.Ending.value | skip ending bits | |
.I2C# | ||
.Clock, Data | ||
.DIO.value | digital I/O pin index | |
.UART# | ||
.Data | ||
.DIO.value | digital I/O pin index | |
.Bits.value | word bits | |
.Parity.text | parity setting: “None”, “Even”, “Odd”, “Mark (High)”, “Space (Low)” | |
.Rate.value | baud rate setting | |
.Patterns# | ||
.States | ||
.Trigger.text | ||
.Wait.value | ||
.Run.value | ||
.Repeat.value | ||
.RepeatTrigger.checked | ||
.Preview.text | preview mode: Manual, Auto | |
.Channels | ||
.channel | channel like: DIO1, Bus1, SPI1 | |
.name | channel name | |
.data | get data array | |
.DIO# | ||
.DIO.value | digital I/O pin index | |
.Bus# | ||
.Format.text | ||
.Endianness.text | ||
.MSB.text | ||
.LSB.text | ||
.Pin# | ||
.DIO.value | digital I/O pin index | |
.StaticIO | ||
.Channel# | groups of 8 signals | |
.Mode.text | select between: I/Os, Slider, Progress | |
.Input.value | input value | |
.DIO# | I/Os | |
.Input.checked | input value | |
.Mode.text | select between: LED, Button, Switch | |
.Button.text | select between: 0/1, 1/0, Z/1, 1/Z, Z/0, 0/Z | |
.Switch.text | select between: TS, PP, OS, OD | |
Supplies | ||
.MasterEnable.checked | ||
.Output | for Analog Discovery | |
.PositiveSupply.Enable.value | ||
.NegativeSupply.Enable.value | ||
.Output | for Electronics Explorer | |
.PositiveSupply, NegativeSupply | ||
.Enable.value | ||
.Voltage.value | ||
.Current.value | ||
.DigitalSupply, Refernce1, Reference2 | ||
.Enable.value | ||
.Voltage.value | ||
.Input | for Electronics Explorer same as Meter#.Input | |
Meter | ||
.Input | for Analog Discovery uses Scope inputs | |
.Channel# | ||
.DC, TrueRMS, ACRMS | ||
.value | ||
.Input | for Electronics Explorer | |
.PositiveSupply, NegativeSupply, DigitalSupply | ||
.Voltage.value | ||
.Current.value | ||
.Voltmeter# | ||
.Voltage.value | ||
.Meters | channels in history list | |
.History.value | ||
.Samples.value | ||
File(path-name) | file object constructor | |
.exists() | returns true if the file exists; otherwise returns false | |
.getName() | returns the file name | |
.getPath() | returns the file path | |
.getSize() | return file size in bytes | |
.isReadOnly() | return true if the file is read-only; otherwise returns false | |
.isHidden() | return true if the file is hidden; otherwise returns false | |
.getLastModified() | returns the date and time when the file was last modified | |
.getCreation() | returns the date and time when the file was created | |
.rename(name) | ||
.copy(path) | ||
.move(path) | ||
.deleteFile() | ||
.read() | read file content as string | |
.read(size) | reads up to size bytes from the file as string | |
.readArray() |
reads the entire file as string array, expects values split by comma, white space, or new line | |
.write(string) | write argument as string to file | |
.writeLine(string) | write argument as string to file followed by a new line | |
.append(string) | appends argument as string to file | |
.appendLine(string) | appends argument as string to file | |
.readInteger() |
read file content as integer (32-bit) array | |
.writeInteger([]) | write array argument as integer array | |
.appendInteger(number) | appends argument as integer to file | |
.readFloat() |
read file content as floating point number (32-bit) array | |
.writeFloat([]) | write array argument as floating point number array | |
.appendInteger(number) | appends argument as floating point number to file | |
.readDouble() |
read file content as double precision floating point number (64-bit) array | |
.writeDouble([]) | write array argument as double precision floating point number array | |
.appendDouble(number) | appends argument as double precision floating point number to file | |
Tool | helper functions | |
.question(text) | ||
Opens a Yes or No question message box with the given text. Returns true when Yes pressed; otherwise returns false. | ||
.getText(label, text) | ||
Get a string from the user. | ||
.getNumber(label, value, minimum, maximum, decimal places) | ||
Gets a floating point input from the user. | ||
.getInteger(label, value, minimum, maximum) | ||
Gets an integer input from the user. | ||
.getItem(label, value, items array, current index, editable) | ||
Lets the user select an item from a list. Returns the selected text. | ||
.start(program, argument array, work directory) | ||
Starts the program with the given arguments. Returns true on success; otherwise returns false. |
The following code starts the waveform generator instrument, performs an oscilloscope acquisition, then computes and prints the average value.
Wavegen1.run()
Scope1.single()
Scope1.wait()
var average = 0
var data = Scope1.Channel1.data
data.forEach(function(sample){
average += sample
})
average /= data.length
print("Average: "+average+"V")
The following code saves the acquisition sample array to a file.
File("C:/temp/acquisition.csv").write(Scope1.Channel1.data)
The following code sets the trigger source and level of oscilloscope instrument based on user input.
Scope1.Trigger.Source.text = Tool.getItem("Source", Scope1.Trigger.Source.preset, Scope1.Trigger.Source.value)
Scope1.Trigger.Level.value = Tool.getNumber("Level", Scope1.Trigger.Level.value)
The following code creates a custom waveform and sets it to be further used.
wave = Array()
for(var i = 0; i < 10; i++){
wave.push(0)
wave.push(i/10)
}
Wavegen1.Channel1.Mode.text = "Custom"
Wavegen1.Channel1.Custom.Type.set("MyWave", wave)
Wavegen1.Channel1.Custom.Type.text = "MyWave"
The following code increases the offset level.
Wavegen1.Channel1.Mode.text = "Simple"
Wavegen1.start()
while(!Tool.question("Are we there yet?")){
Wavegen1.Channel1.Simple.Offset.value += 0.1
print("Offset: "+ Wavegen1.Channel1.Simple.Offset.text)
}
The following code sets the slider for one Static I/O and increments the value twice a second.
StaticIO.Channel0.Mode.text = "Slider"
for(var i = 0; wait(0.5); i++, i%=256){
StaticIO.Channel0.Slider.value = i
}
StaticIO.Channel0.Mode.text = "Progress"