Script

The Script window allows execution of WaveForms scripts. The scripting language is JavaScript, based on the ECMAScript, ECMA-262 standard.

From the script objects behind the user interface can be accessed. This allows configuration using the interface and automating parts of it with script.
The Script tool is intended to automate some operations to extend the GUI features. There is no need to setup all the interface from Script as the Script is saved together with other instruments in workspace. What can be done in the GUI, is easier to do there, like: setup channels, naming, static configuration. Then, use the Script to adjust parameters that need to be changed, such as changing PWM duty based on some scope measurements.

The script access to various properties and functions is shown as status tool tip.

 

1. Menu

See Menu in Common Interfaces.

 

2. Control

The control toolbar allows you to debug and execute the script.

 

3. Output

The output window contains the print() messages and error log. When this window is closed the prints are directed to the standard output.

 

4. Code

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 Ctrl+Space (or Ctrl+Shift+Space under MacOS) can be used for code completion, to reveal child objects, functions and properties.

The instrument parameters are stored in objects with the following properties:

For path separator slash "/" should be used, eventually "\\" but this is not recommended. Backslash "\" is for special characters like "\t" tab, "\n" new line. Similarly "\\" denotes backslash and is used for paths under Windows. In WaveForms scripts slash "/" can be used under all operating systems as path separator. Path starting with tilde "~" stands for users folder, like File("~/Desktop/myfile.csv")

mma
 wait(seconds) Waits the specified time expressed in seconds. With a negative value, it waits until stopped. Returns false when the script is stopped; otherwise returns true.
 print(arg0,arg1,...)Prints the arguments to the Output window or to the standard output when this is closed.
 stdout(arg0,arg1,...)Prints the arguments to the standard output.
 clear()Clears the Output window content.
Device
 .isConnected()Returns true when the application is connected to a device, otherwise false.
 .nameGets the device name.
 .SNGets the device serial number.
 .triggerPC()Executes manual trigger.
 open(instr1, instr2...)Opens the specified instruments if these do not exists, like: open("Scope", "Wavegen")
Instrument#common instrument object, Instrument refers to Instrument1 like Scope to Scope1
 .single()Starts single acquisition.
 .run()Starts repeated acquisitions or scan mode.
 .stop()Stops the instrument.
 .wait()Waits for the capture to be completed and returns true. Returns false when the Script or instrument is stopped,
 .config()Applies configuration immediately.
 .windowGets the instrument window object.
 .Export(file)
 .Export(szFile, szView = "", fComments = true, fHeader = true, fLabel = true, fHeaderAsComment = false, szNotes = "")
Exports a view or instrument data or screenshot to the given file. The file format is identified based on file name extension: csv, txt, tdms, bmp, png. For view name expects like: Acquisition, XY1, FFT; Wavegen: Channel1; without name the instrument is saved. The comment, header, and labels boolean arguments enable or disable saving such information.
 .State
  .textGets the instrument state: 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.valueGets the refresh rate of the instrument.
 .Time
  .Position.value
  .Base.value
  .Base.realGets the full timespan of the capture
  .Samples.value
  .Samples.realGets the number of samples in capture
  .Rate.value
  .Rate.realGets the actual sample rate of the capture
  .takenGets the capture date time
  .taken3Gets precise capture time: seconds since epoch, ticks and number of ticks in a second
 .EyeEye Pattern
  .measure()Returns the measurement value like: Rate, Period, Cross, JitterP2P, JitterRMS, Width, Height, Opening, SNF, Zero, One, ZeroDev, OneDev, Amplitude, T1, T2, Rise, Fall, Window, Time, Crossings, Points
 Scope#
  .measure(name)Returns global measurements value, like custom Phase measurement.
  .MeasurementsProvides access to the Measurement view.
   .name.value .count .minimum .maximum .median .mean
  .Trigger
   .Trigger.textSets or gets the acquisition mode: Normal, Auto, None.
   .Type.textSets or gets the trigger type: Edge, Pulse, Transition.
   .Condition.textSets or gets the condition: Rising, Falling or Positive, Negative.
   .Source.textSets or gets the trigger source: Channel 1, Channel 2, Wavegen 1, etc.
   .Level.valueSets or gets the trigger level.
   .Hysteresis.valueSets or gets the trigger hysteresis.
   .LCondition.valueSets or gets the trigger length condition.
   .Length.valueSets or gets the trigger length.
   .HoldOff.valueSets or gets the trigger hold-off.
   .Filter.textSets or gets the trigger filter sample type to use when looking for trigger condition: Decimate, Average.
  .Time
   .Mode.textSets or gets the run-scan mode: Repeated, Screen, Shift, Record.
  .BufferSize.valueSets or gets the PC buffer size.
  .Buffer.valueSets or gets the selected PC buffer index.
  .Digital.checkedSets or gets the mixed mode using digital channels.
  .DigitalChannelsDigital channels, same as Analyzer#.Channels.
  .DigitalTriggerSame as Analyzer#.Trigger.
  .channel#The following properties are available for Math and Ref channels as well:
   .checkedSets or gets the channel visibility.
   .dataGets the data array with the channel samples.
   .TimeOfIndex(index)Returns the time value in seconds of the specified data index.
   .IndexOfTime(time)Returns the data index of the specified time value in seconds.
   .Sample(index)Returns the sample at specified index.
   .SampleAt(time)Returns the sample at specified time position expressed in seconds.
   .visibledataGets the data array of the visible samples with the current time options. This property is useful for measurements.
   .persistenceDataReturns array with: width and height followed by persistence values for each pixel.
   .TimeOfVisibleIndex(index)Returns the time value in seconds of the specified visible data index.
   .VisibleIndexOfData(time)Returns the visible data index of the specified time value in seconds.
   .VisibleSample(index)Returns the sample at specified visible index.
   .measure(name)Returns channel measurement value, such as Minimum, Maximum, Average, Peak2Peak, Low, High, Amplitude, Middle, etc.
   .Offset.value
   .Offset.realGets the actual offset of the capture
   .Range.value
   .Offset.realGets the actual range of the capture
   .histogramGets the histogram array in percentage.
   .HistogramIndex2Data(index)
   Returns the “voltage” value corresponding to the histogram array index.
  .Channel#Real channels
   .Attenuation.value
   .Noise.checked
   .SampleMode.textSets or gets the sampling mode: Decimate, Average, Min/Max.
  .Ref#Reference channels
   .setData(array, rate)Set data and specify sample rate in Hertz.
   .clone(channel)Clone with the respective channel.
   .TimeRefReference channel time.
   .Units.text
   .Noise.checked
  .Math#Math channels
   .Operation.textSets or gets the operation for simple mode: +, -.
   .ASets or gets the Channel A for simple mode.
   .BSets or gets the Channel B for simple mode.
   .Mode.textSets or gets the math mode: Simple, Custom, Filter.
   .Function.textSets or gets the custom function code.
   .Units.text
   .customFilterSets or gets the custom filter array.
  .Histogram
   .Autoscale.checked
   .Top.valueSets or gets the top of the scale to use when auto-scale is unchecked.
 Wavegen#
  .Custom
   .set(name,array)Set custom waveform data (normalized to +-1) identified by name.
  .Play
   .set(name,array)Set play waveform data (normalized to +-1) identified by name.
  .Synchronization.textSets or gets the synchronization mode: No synchronization, Independent, Synchronized, Auto synchronized.
  .StatesCommon synchronization states settings.
   .Trigger.text
   .Wait.value
   .Run.value
   .Repeat.value
   .RepeatTrigger.checked
  .Channel#
   .enableEnables or disables the channel
   .Mode.textSets or gets the configuration mode: Simple, Basic, etc.
   .Options
    .IdleOutput.textSets or gets the idle output value: Offset, Initial, Disabled.
   .StatesChannel states configuration.
   .Simple
    .Type.textSets or gets the predefined or custom waveform name: Sine, Square, etc.
    .Frequency, Offset, Amplitude, Symmetry, Phase
    .value
   .Basic
    .Type.textSets or gets the predefined or custom waveform name.
    .Frequency, Offset, Amplitude, Symmetry, Phase
     .value
     .Min.value
     .Max.value
    .Frequency, Offset, Amplitude, Symmetry, Phase
     .value
   .Sweep
    .Type.textSets or gets the predefined or custom waveform name.
    .Offset, Symmetry, Phase
     .value
    .Frequency
     .checkedSets or gets the sweeping enable.
     .Start.valueSets or gets the start frequency.
     .Stop.valueSets or gets the stop frequency.
     .Time.valueSets or gets the sweep time.
    .Amplitude
     .checkedSets or gets the damping enable.
     .Start.valueSets or gets the start amplitude.
     .Stop.valueSets or gets the stop amplitude.
     .Time.valueSets or gets the damp time.
 Logic#
  .TriggerTrigger configuration.
   .Trigger.textSets or gets the acquisition mode: Normal, Auto, None.
   .Clock.textSets or gets the clock source: Internal, External.
   .Source.textSets or gets the trigger source.
  .TimeTime configuration.
   .Mode.textSets or gets the run mode: Repeated, Screen, Shift, Record.
  .BufferSize.valueSets or gets the PC buffer size.
  .Buffer.valueSets or gets the selected PC buffer index.
  .AddTab(name, data array, frequency)
  .Channels
   .channelChannel like: DIO1, Bus1, SPI1.
    .nameSets or gets the channel name.
    .dataGets the text array.
    .eventsGets the events text array.
    .eventStampsGets the time stamp array.
    .measure(name)Returns channel measurement value, such as: Cycles, PosDuty, PosWidth
   .DIO#
    .DIO.valueSets or gets the digital I/O pin index.
    .Trigger.textSets or gets the trigger: Ignore, Rise, Fall, Edge, High, Low.
   .Bus#
    .Enable.DIO.valueSets or gets the enable pin.
    .Clock.DIO.valueSets or gets the clock pin.
    .Active.textSets or gets the active level of enable signal: Low, High.
    .Polarity.textSets or gets the sampling edge of the clock signal: Rising, Falling.
    .Format.text
    .Endianness.text
    .MSB.text
    .LSB.text
    .Pin#
     .DIO.valueSets or gets the digital I/O pin index.
   .SPI#
    .Select, Clock, Data
     .DIO.valueSets or gets the digital I/O pin index.
    .Active.textSets or gets the active level of select signal: Low, High.
    .Sample.textSets or gets the sampling clock edge: Rising, Falling.
    .First.textSets or gets the data bit order: LSB, MSB.
    .Bits.valueSets or gets the word bits.
    .Format.text
    .Leading.valueSets or gets the leading bits to skip.
    .Ending.valueSets or gets the ending bits to skip.
   .I2C#
    .Clock, Data
     .DIO.valueSets or gets the digital I/O pin index.
   .UART#
    .Data
     .DIO.valueSets or gets the digital I/O pin index.
    .Bits.valueSets or gets the word bits.
    .Parity.textSets or gets the parity setting: “None”, “Even”, “Odd”, “Mark (High)”, “Space (Low)”.
    .Rate.valueSets or gets the baud rate setting.
 Patterns#
  .States
   .Trigger.text
   .Wait.value
   .Run.value
   .Repeat.value
   .RepeatTrigger.checked
  .Preview.textSets or gets the preview mode: Manual, Auto.
  .Channels
   .channelSets or gets the channel like: DIO1, Bus1, SPI1.
    .nameSets or gets the channel name.
    .dataGets the preview data array.
    .customSets or gets the custom value array.
    .customzSets or gets the custom high impedance data array mask for TS output.
   .DIO#
    .Pin.valueSets or gets the digital I/O pin index.
    .Output.textSets or gets the otput mode: "PP", "OD", "OS", "TS"
    .Idle.textSets or gets the idle output: "Initial", "0", "1", "Z"
    .Type.textSets or gets the signal or bus type: "Constant", "Clock", "Random", "Binary Counter",...
    .Frequency.valueSets or gets the signal or bus frequency
    .Duty.valueSets or gets the duty of for Clock type
    .Divider.valueSets or gets the divider value for Pulse type
    .Low.valueSets or gets the low count for Pulse type
    .High.valueSets or gets the high count for Pulse type
   .Bus#
    .Format.text
    .Endianness.text
    .MSB.text
    .LSB.text
    .Pin#
     .DIO.valueSets or gets the digital I/O pin index.
 StaticIO
  .Channel#Groups of 8 signals.
   .Mode.textSets or gets the group mode: I/Os, Slider, Progress.
   .Input.valueGets the input value.
   .DIO#I/Os.
    .textSets or gets the output value: "0", "1", "Z".
    .valueSets or gets the output value: 0, 1, 2; where 2 represents Z, high impedance).
    .Input.valueGets the input (read) value: 0, 1.
    .Mode.textSets or gets the IO mode: LED, Button, Switch.
    .Button.textSets or gets the button mode: "0/1", "1/0", "Z/1", "1/Z", "Z/0", "0/Z".
    .Switch.textSets or gets the switch mode: "TS", "PP", "OS", "OD".
 Supplies
  .MasterEnable.checked
  .OutputFor Analog Discovery.
   .PositiveSupply.Enable.value1 enable and 0 disable
   .NegativeSupply.Enable.value1 enable and 0 disable
  .OutputFor Electronics Explorer.
   .PositiveSupply, NegativeSupply
    .Enable.value1 enable and 0 disable
    .Voltage.value
    .Current.value
   .DigitalSupply, Refernce1, Reference2
    .Enable.value1 enable and 0 disable
    .Voltage.value
  .InputFor Electronics Explorer
    .PositiveSupply, NegativeSupply, DigitalSupply
     .Voltage.value
     .Current.value
    .Voltmeter#
     .Voltage.value
 LoggerUses Scope inputs.
  .Input
   .Channel#
    .DC, TrueRMS, ACRMS
     .value
  .History.value
  .Samples.value
  .LoggersChannels in history list.
   .nameChannel like C1DC.
    .dataSets or gets the data array.
    .averageSets or gets the average value.
    .minimumSets or gets the minimum value.
    .maximumSets or gets the maximum value.
 DMMDMM of ADP5250
  .Measure.valueReturns the DMM reading.
  .Mode.value/textSets or gets the DMM mode
  .Range.valueSets or gets the range, 0 is auto range
  .Average.valueSets or gets the average time in seconds
 Spectrum#
  .FrequencyFrequency settings.
   .BINs.valueSets or gets the number of BINs.
   .Start.valueSets or gets the start frequency.
   .Stop.valueSets or gets the stop frequency.
   .Frequency.valueSets or gets the frequency for meter mode.
  .Channel#
   .Range.valueSets or gets the voltage range.
   .Offset.valueSets or gets the offset.
   .Attenuation.valueSets or gets the channel attenuation.
   .dataGets the time domain capture data.
   .dataRateGets the data sample rate.
  .Trace#
   .setSamples(array, hz)Set time domain data and specify sample rate.
   .measure(name)Returns measurements like: "NF", "SNR", "THD", "FF", "2nd".
   .measureFreq(name)Returns the frequency information of some measurements like "WoSpur ", "FF".
   .magnitudeSets or gets the magnitude data array in selected units.
   .frequencyReturns frequency points corresponding to magnitude array.
   .componentsReturns frequency points of peaks.
   .setMagnitude(array, hzMin, hzMax)Set magnitude data array, specify minimum and maximum frequencies.
 Network#
  .FrequencyFrequency settings.
   .Samples.valueSets or gets the number of steps.
   .Start.valueSets or gets the start frequency.
  .WavegenWaveGen settings.
   .Channel.textSets or gets the stimulus channel: "External", "WaveGen1", "WaveGen2".
   .Offset.valueSets or gets the stimulus signal offset.
   .Amplitude.valueSets or gets the stimulus signal amplitude.
   .Settle.valueSets or gets the settle time between frequency adjustment and capture.
  .Channel# Reference#
   .Range.valueSets or gets the channel voltage range.
   .Offset.valueSets or gets the channel offset.
   .Attenuation.valueSets or gets the channel attenuation.
   .Gain.valueSets or gets the gain, relation between WaveGen amplitude, and channel range.
   .magnitudeSets or gets the array of magnitude values.
   .phaseSets or get the array of phase values.
   .frequencyGets the array of frequency steps.
   .getIndex(hz)Return the index for the specified frequency.
   .getMagnitude(hz)Return the magnitude for the specified frequency.
   .getPhase(hz)Return the phase for the specified frequency.
   .setMagnitude(array)Set the array of magnitude values.
   .setSpectrum(array, index)Set the array of spectrum measurement values.
   .getSpectrum(index)Return the array of spectrum measurement values.
 Where index of 0 = THD+N, 1 = THD, 2 = HD2, 3 = HD3...
 Impedance#
  .FrequencyFrequency settings.
   .Samples.valueSets or gets the number of steps.
   .Start.valueSets or gets the start frequency for analyzer mode.
   .Stop.valueSets or gets the stop frequency for analyzer mode.
   .Frequency.valueSets or gets the frequency for meter mode.
  .WavegenWaveGen settings.
   .Offset.valueSets or gets the stimulus signal offset.
   .Amplitude.valueSets or gets the stimulus signal amplitude.
  .Resistor
   .resistorSets or gets the resistor value.
  .Channels
   .Channel1
    .Range.valueSets or gets the channel range.
    .Offset.valueSets or gets the channel offset.
    .Attenuation.valueSets or gets the channel attenuation.
  .Traces
   .TraceMain trace.
   .Ref#Reference traces.
    .getData(name)Returns array of data for the following names:
     "Frequency"frequency steps in hertz
     "Input Gain"values in dB units
     "Input Phase"values in degree units
     "Phase"values in degree units
     "Impedance"values in Ohm units
     "Resistance"values in Ohm units
     "Reactance"values in Ohm units
     "Admittance"values in Siemens units
     "Conductance"values in Siemens units
     "Susceptance"values in Siemens units
     "Series Inductance"values in Henry units
     "Parallel Inductance"values in Henry units
     "Series Capacitance"values in Farad units
     "Parallel Capacitance"values in Farad units
     "Dissipation factor"
     "Quality factor"
 Protocol
  .Mode.textBefore using a protocol functions, first select it in the interface or with this property: "UART", "SPI", "I2C", "CAN".
 
  .UART
   .Send(text, {true|false})
Send array of data with or without ending.
   .SendArray(array, {true|false})
Send array of data with or without ending.
   .Receiver()Initialize UART reception on RX.
   .Receive()Returns received text since initialization or last call.
   .ReceiveArray()Returns received RX data array since initialization or last call.
   .Receives()Returns received text since initialization or last call. [txtext, rxtext]
   .ReceiveArrays()Returns received TX and TX data array since initialization or last call. [[tx1,tx2...],[rx1,rx2,...]]
  .SPI
   .Start()Activates the select signal. Return true on success, otherwise returns false.
   .Stop()Deactivates the select signal. Return true on success, otherwise false.
   .ReadWrite(bits per word, [word1, word2...] )
 4-wire SPI data transfer. Returns the read array of words.
   .Write(bits per word, [word1, word2...] )
 3- or 4-wire SPI data write. Returns true on success, otherwise returns false.
   .Read(bits per word, number of words to read)
 4-wire SPI data read. Returns the read array of words from DQ1.
   .Read0(bits per word, number of words to read)
 3-wire SPI data read. Returns the read array of words from DQ0.
   .WriteDual(bits per word, [word1, word2...])
 Dual SPI data write to DQ0,1. Returns true on success, otherwise return false.
   .ReadDual(bits per word, number of words to read)
 Dual SPI data read from DQ0,1. Returns the read array of words.
   .WriteQuad(bits per word, [word1, word2...])
 Quad SPI data write to DQ0,1,2,3. Returns the read array of words.
   .ReadQuad(bits per word, number of words to read)
 Dual SPI data read from DQ0,1,2,3. Returns the read array of words.
   .DQ#.Initial.textInitial/idle value: "0","1", "Z".
   .Receiver()
 Start the SPI reception.
   .Receive() []
 Returns an array with alternating MOSI and MISO words for each transfer.
  .I2C
   .Clear()Returns true when the bus is free. It will try to resolve the SDA hold down issue.
   .Read()Returns true when acknowledged, otherwise false.
   .Read(address, number of bytes)
 Returns the read bytes array from the specified address.
   .Read(address, number of bytes to read, [sub address byte1, byte2...])
 Returns the read bytes array from the specified device address and subaddress using repeated start.
   .Write(address) Returns true when acknowledged, otherwise false.
   .Write(address, [byte1, byte2... ])
 Returns zero on success, or -1 on address NotAcKnowled, or the NAK byte index.
   .SlaveConfig(address, wr-bytes, [rd-byte1,rd-byte2,...], repeat)
 address: 7bit format and for any use -1
 wr-bytes: number of written bytes to ACK, 0 will NACK address write, negative will ACK unlimited bytes
 [rd-byte#]: one byte or array of bytes to return on read, negative value or empty array will NAK read
 repeat: true to respond multiple times, false for once, to stop after the first I2C stop.
   .SlaveStart(address, wr-ack, rd-ack)
 Start slave pausing for software processing after each word.
   .SlaveStop()
 Stop started or configured slave.
   SlaveStatus() [0=id, 1=data, 2=ack]
 Returns and array with the following values:
 id: 0 nop, 1 write, 2 read, 3 data, others error
 data: 7bit address or byte
 ack: true for ACK and false for NACK.
   .SlaveReceive(ack)
 Continue to receive and acknowledge or NACK.
   .SlaveRespond(byte, ack)
 Respond with data and acknowledge or NACK.
   .Receiver()
 Start the I2C reception.
   .Receive() []
 Returns an array with I2C transfers, numbers denoting:
 Positive values are at 9 bits which include address with read/write bit or data and acknowledge, [A6,...A0,RD|nWR,nACK|NACK] or [D7,...D0,nACK|NACK]. The -1 indicates start, -2 indicates restart, -3 indicates stop and other negative values indicates error.
  .CAN
   .Send(BI, IDE, IE, RTR, DCL, [data1, 2... ])
   .SendFD(BI, IDE, IE, RTR, EDL, BRS, ESI, DCL, [data1, 2... ])
 Returns true on success, otherwise returns false.
   .Receiver()
 Start the CAN reception.
   .Receive()
 Returns an array with CAN transfer when indices represent:
  0 BI: Base Identifier, 11bits
  1 SRR/RTR: Substitute Remote Request, 1bit
  2 IDE: Identifier Extension Flag, 1bit
  3 IE: Identifier Extension, 18bits
  4 RTR: Remote Transmission Request, 1bit
  5 EDL: Extended Data Length, 1bit
  6 R0: Reserved, 1bit
  7 BRS: Bit Rate Switch, 1bit
  8 ESI: Error State Indicator, 1bit
  9 DLC: Data Length Code, 4bits
  10 CRC: received circular redundancy check
  11 CRCD: calculated CRC
  12 ACK: 0 acknowledged or 1 unacknowledged
  13.. Data: data bytes
  .AVR
The following functions return the number of bytes written or read, and negative in case of error.
   .ProgrammingTest()
Tries to enter programming mode. Return true on success.
   .SignatureRead()
Reads and returns the chip signature.
   .ChipErase()
Performs chip erase. Returns 1 on success or -1 on failure.
   .FusesRead() [low, high, extended]
Reads and returns the fuse bytes.
   .FusesWrite([low, high, extended])
Writes the fuse bytes. Returns the number of bytes written or -1 on failure.
   .FuseLowWrite(byte)
Writes the fuse low byte. Returns the number of bytes written or -1 on failure.
   .FuseHighWrite(byte)
Writes the fuse high byte. Returns the number of bytes written or -1 on failure.
   .FuseExtWrite(byte)
Writes the fuse extended byte. Returns the number of bytes written or -1 on failure.
   .LockRead()
Reads and returns the lock bits.
   .LockWrite(value)
Writes the lock bits. Returns 1 on success and -1 on failure.
   .CalibRead() []
Reads and returns the calibration bytes.
   .HexRead(file, bytes = eeprom size)
Reads from hex file the given bytes size map and returns the array.
   .FlashRead(bytes = flash size, start = 0)
Reads and returns the given number of bytes from Flash at the specifier start address.
   .FlashWrite([byte array], erase = false, verify = false, start = 0)
Programs the Flash with the given array at the specified start address, optionally perfrom erase and verification. Returns the number of bytes written or -1 on failure.
   .EepromRead(bytes = eeprom size, start = 0)
Reads and returns the given number of bytes from EEPROM at the specifier start address.
   .EepromWrite([byte array], verify = false, start = 0)
Programs the EEPROM with the given array at the specified start address, optionally perfroms verification. Returns the number of bytes written or -1 on failure.
   .FlashReadFile(file, bytes = flash size)
Read the given number of bytes from Flash to file. Returns the number of bytes read or -1 on failure.
   .FlashWriteFile(file, erase = false, verify = false, start = 0)
Program Flash with the file (.hex or binary) content, optionally perfroms erase and verification. Returns the number of bytes read or -1 on failure.
   .EepromReadFile(file, bytes = eeprom size, start = 0)
Reads the given number of bytes from EEPROM to file, starting at EEPROM address. Returns the number of bytes read or -1 on failure.
   .EepromWriteFile(file, verify = false, start = 0)
Programs the EEPROM with the file content, starting at EEPROM address, optionally perfroms verification. Returns the number of bytes written or -1 on failure.
 File(file path)File object constructor.
  .exists()Returns true if the file exists, otherwise returns false.
  .getName()Returns the file name.
  .getPath()Returns the file path.
  .getSize()Returns file size in bytes.
  .isReadOnly()Returns true if the file is read-only, otherwise returns false.
  .isHidden()Returns 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()Reads file content as text.
  .read(size)Reads up to size bytes from the file as text.
  .readArray() Reads the entire file as text array. Expects values split by comma, white space, or new line.
  .write(text)Writes argument as text to file.
  .writeLine(text)Write argument as text to file followed by a new line.
  .append(text)Appends argument as text to file.
  .appendLine(text)Appends argument as text to file.
  .readInteger(max length = 0, big endian = false)
Reads file content as integer (32-bit) array.
- maximum length to read, with default value of zero no limitation.
- big endian default false, little endian, least significant byte first.
  .writeInteger(value or array, big endian = false)
Writes number or array of numbers as binary 32-bit integer to file.
  .appendInteger(value or array, big endian = false)
Appends number or array of numbers as binary 32-bit integer to file.
  .readUInt32(max length = 0, big endian = false) array
Reads file content as unsigned 32-bit integer array.
  .writeUInt32(value or array, big endian = false)
Writes number or array of numbers as binary 32-bit unsigned integer to file.
  .appendUInt32(value or array, big endian = false)
Appends number or array of numbers as binary 32-bit unsigned integer to file.
  .readUInt16(max length = 0, big endian = false) array
Reads file content as unsigned 16-bit integer array.
  .writeUInt16(value or array, big endian = false)
Writes number or array of numbers as binary 16-bit unsigned integer to file.
  .appendUInt16(value or array, big endian = false)
Appends number or array of numbers as binary 16-bit unsigned integer to file.
  .readFloat(max length = 0, big endian = false)
Reads file content as floating point (32-bit) number array.
  .writeFloat(value or array, big endian = false)
Writes number or array of numbers as binary 32-bit floating point number to file.
  .appendFloat(value or array, big endian = false)
Appends number or array of numbers as binary 32-bit floating point number to file.
  .readDouble(max length = 0, big endian = false)
Read file content as double precision floating point (64-bit) number array.
  .writeDouble(value or array, big endian = false)
Writes number or array of numbers as binary 64-bit floating point number to file.
  .appendDouble(value or array, big endian = false)
Append number or array of numbers as binary 64-bit floating point number to file.
 DirList(path) array
Returns a list with the directories in the given path.
 FileList(path) array
Returns a list with the files in the given path.
 FileWrite(file path, text or array)
Writes text or array to the given file. The array is delimited comma.
 FileWriteLine(file path, text or array)
Writes text or array ended by carriage return to the given file.
 FileAppend(file path, text or array)
Writes text or array to the given file. The array is delimited comma.
 FileAppendLine(file path, text or array)
Write text or array ended by carriage return to the given file.
 FileRead(file path) text
Reads text from the given file. The array is delimited comma.
 FileReadArray(file path, list separator) array
 FileImport(file path, skip first time column, list separator, decimal) 2d array
Imports CSV or TXT data from file, skipping the not numeric header rows. The arguments are optional.
 SerialPortList()Returns a list of available COM ports as: name 1, description 1, name 2, description 2, ...
 SerialPortCom(name, baud, send, receive time) received text
Simple usage for rare communication, specify non-zero time for reception
 SerialPort()Creates a serial port.
  .open(name, baud)Opens a serial port.
  .close()Closes the serial port.
  .write(text) number
  .read() textReads all remaining data from the serial port.
  .read(max) textReads at most max characters from the serial port.
  .readLine(max = 0) textReads a line from the serial port, but no more than max characters.
  .skip(max) textSkips up to max characters from the serial port.
  .readWait(seconds)Wait to receive data
  .writeWait(seconds)Wait the data to be written
  .readAvailable()Returns the number of incoming characters that are waiting to be read.
  .writeWaiting()Returns the number of characters that are waiting to be written.
  .canReadLine()Returns true if a line of data can be read from the serial port; otherwise returns false.
  .sendBreak()
 Pipe()Creates a pipe object.
  .listen(name)Initializes server to listen on the give name.
  .close()Closes the pipe or server.
  .connect(name, rd|wr, timeout)Tries to connect to server; 1 read, 2 write, 3 both; timeout in seconds.
  .write(byte array) numberreturn the written number of bytes
  .writeText(string) number
  .writeInt32(string) number
  .writeFloat(string) number
  .writeDouble(string) number
  .readAvailable()Returns the number of incoming bytes that are waiting to be read.
  .read(size) array
  .readText(length) string
  .readInt32(length) array
  .readFloat(length) array
  .readDouble(length) array
 Tcp()Creates a TCP object.
  .listen(name|address, port)Initializes server to listen on the give name.
  .close()Closes the TCP server or socket.
  .connect(name|address, port, rd|wr, timeout)Tries to connect to server.
  .write(byte array) numberreturn the written number of bytes
  .writeText(string) number
  .writeInt32(string) number
  .writeFloat(string) number
  .writeDouble(string) number
  .readAvailable()Returns the number of incoming bytes that are waiting to be read.
  .read(size) array
  .readText(length) string
  .readInt32(length) array
  .readFloat(length) array
  .readDouble(length) array
 ToolHelper functions
  .question(text)
Opens a Yes or No question message box with the given text. Returns true when Yes is pressed, otherwise returns false.
  .getText(label, text)
Gets 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.
  .getSaveFile(caption, path, filter)
Opens a file dialog and returns the file path. The filter has the following format: "Text (*.txt);CSV (*.csv)"
  .getOpenFile(caption, path, filter)
Opens a file dialog and returns an existing file path.
  .getDirectory(caption, path)
Returns an existing directory.
  .start(command, argument array, work directory)
Starts the program with the given arguments. Returns true on success, otherwise returns false.
  .exec(command, argument array, work directory, timeout = 10)
Executes the program with the given arguments. Returns the output of the command.
  .beep()Sounds the bell, using the default volume and sound.
  .workspacePath()Returns the path to the current workspace.
  .workspaceDir()Returns the directory of the current workspace.
 plot#Plots in Script tool.
  .X()X axis.
  .Y1-4()Y axis.
   .dataSets or gets the data array.
Setting data for X axis, the plot will become a XY plot.
   .colorSets or gets the color by name ( = "red") or hex ( = "#FF0000").
   .Units.textSets or gets the axis unit.
   .AutoScale.checkedSets or gets the auto scaling option.
   .Range.valueSets or gets the range value.
   .Offset.valueSets or gets the offset value.

 

5. Examples

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.Custom.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"

The following executes ping command and logs in output text filed. Code is compatible with Windows OS.

do{
  var date = new Date()
  var ping = Tool.exec("ping.exe", ["-n","1","127.0 0.1"])
  //print(p)
  var up = ping.indexOf("Received = 1")>0
  var log = date.toISOString()+" "+(up?"Up":"Down")
  if(!up) Tool.beep()
  print(log)
}while(wait(10))

The following configures DIO0 Custom TS bit sequence of [0,1,Z,Z]

Patterns.Custom.DIO0.customz = [0,0,1,1]
Patterns.Custom.DIO0.custom  = [0,1,0,1]

The following configures Bus Custom TS bit sequence of [b00,b01,b1Z,bZZ]

Patterns.Custom.Bus.customz = [0,0,1,3]
Patterns.Custom.Bus.custom  = [0,1,2,0]

The user interface elements are not intended to be used with Script but if it is needed these can be accessed under Instr.window... For instance the Scope X1 cursors can be controlled like:

Scope.window.splitter.plot.bottom.X1.Position.value = -0.001;

Simple SerialPort usage for rare communication:

if(!SerialPortCom("COM10", 9600, "Hello\n")) throw "COM error";
print(SerialPortCom("COM10", 9600, "?\n", 0.1));

List serial ports, write and read from the first one:

var list = SerialPortList();
print(list);
if(list.length){
  var com = new SerialPort();
  if(!com.open(list[0], 115200)) throw "COM open failed";
  com.write("hi\n");
  com.waitForBytesWritten(0.1);
  com.waitForReadyRead(0.1);
  print(com.read());
}