Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
test-and-measurement:guides:waveforms-script-editor [2022/09/12 19:23] – changed forum.digilentinc.com to forum.digilent.com Jeffrey | test-and-measurement:guides:waveforms-script-editor [2024/02/28 19:27] (current) – [Prerequisites] James Colvin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using the Script Editor ====== | ||
+ | ~~TechArticle~~ | ||
+ | |||
+ | {{test-and-measurement: | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | This guide explains the use of WaveForms' | ||
+ | ---- | ||
+ | ===== Prerequisites ===== | ||
+ | * A Digilent Test & Measurement Device compatible with WaveForms: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * A Computer with WaveForms Software Installed | ||
+ | |||
+ | ---- | ||
+ | ===== Guide ===== | ||
+ | ==== 1. Opening the Script Editor ==== | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | === 1.1 === | ||
+ | Plug in the Test & Measurement Device, then start WaveForms and make sure the device is connected. | ||
+ | |||
+ | If no device is connected to the host computer when WaveForms launches, the **Device Manager** will be launched. Make sure that the device is plugged in and turned on, at which point it will appear in the Device Manager' | ||
+ | |||
+ | **Note:** //" | ||
+ | |||
+ | **Note:** //The Device Manager can be opened by clicking on the " | ||
+ | </ | ||
+ | <WRAP column half> | ||
+ | {{: | ||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group>< | ||
+ | === 1.2 === | ||
+ | Once the Welcome page loads, in the instrument panel at the left side of the window, click on the **Script** button to open the //Script Editor// instrument. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | |||
+ | === 1.3 === | ||
+ | When the //Script Editor// has opened, it will display the text editor (1), the output panel (2) below the editor, and the control toolbar (3) at the top. | ||
+ | |||
+ | </ | ||
+ | <WRAP column half> | ||
+ | {{: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== 2. Using the Script Editor ==== | ||
+ | |||
+ | //This section walks through how to use the //Script Editor//. Two examples are presented below. Other example scripts are available within the Script Editor.// | ||
+ | |||
+ | --> Oscilloscope and Waveform Generator # | ||
+ | |||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.1 Hardware Setup === | ||
+ | To demonstrate the //Script Editor//, the // | ||
+ | |||
+ | For devices using MTE cables, first, connect the Test & Measurement scope channel 1 pin (orange wire) to the device' | ||
+ | |||
+ | If you instead want to use BNC cables, or your device does not support MTE cables, please see [[waveforms-oscilloscope]] and/or [[waveforms-waveform-generator]] for additional information. | ||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.2 Software Setup === | ||
+ | For the //Script Editor// to make use of the instruments, | ||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | Return to the //Script// tab to view the //Script Editor// instrument. | ||
+ | |||
+ | Open the //Scope and Wavegen// example script, by selecting it from the **Example** dropdown. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | Prior to running the script, what it does and how it works will be briefly discussed: | ||
+ | |||
+ | - The " | ||
+ | - The second line checks whether the // | ||
+ | - Several options for the two instruments are then set. Using mostly default options, the Waveform Generator Channel 1 outputs a 1KHz sine wave with a 1V amplitude and an initial DC offset of 0.5V. The Oscilloscope trigger is set to capture repeated trigger events of the input signal rising past a 0V level. | ||
+ | - Next, both instruments are started with a " | ||
+ | - The remaining steps are looped 10 times, waiting for one second between each iteration - wait returns True once the number of seconds passed to it have elapsed. | ||
+ | - The " | ||
+ | - Several variables are then used to store some measurements about the data that was captured on Oscilloscope Channel 1. In this case, the " | ||
+ | * The " | ||
+ | * The " | ||
+ | - Lastly, the //Waveform Generator//' | ||
+ | |||
+ | Summarizing, | ||
+ | </ | ||
+ | <code javascript>// | ||
+ | clear() | ||
+ | if(!(' | ||
+ | |||
+ | Wavegen1.Channel1.Mode.text = " | ||
+ | Wavegen1.Channel1.Simple.Offset.value = 0.5; | ||
+ | Scope1.Trigger.Trigger.text = " | ||
+ | Wavegen1.run(); | ||
+ | Scope1.run(); | ||
+ | for(var idx = 0; wait(1) && idx < 10; idx++){ | ||
+ | // if(!Scope1.wait()) throw " | ||
+ | var middle = Scope1.Channel1.measure(" | ||
+ | var average = Scope1.Channel1.measure(" | ||
+ | print(idx+" | ||
+ | // adjust Wavegen offset | ||
+ | Wavegen1.Channel1.Simple.Offset.value -= middle/2; | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | More information on the functions and objects available in the //Script Editor// can be found in the in WaveForms' | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.3 Running the Script === | ||
+ | Return to the Scripts page by clicking on its tab in the bar at the top of the screen. | ||
+ | |||
+ | Click the Run ({{: | ||
+ | |||
+ | Print statements and uncaught errors are shown in the //Output// panel. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.4 Debugging === | ||
+ | If in the process of writing a script, the script needs to be stepped through to find errors, the Script Editor' | ||
+ | |||
+ | Debugging is done inside WaveForms itself, allowing the user to step through the execution of the script. The debugger is accessed by clicking the Debug ({{: | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | <-- | ||
+ | |||
+ | --> Protocol Analyzer # | ||
+ | |||
+ | <WRAP group> | ||
+ | === 2.1 Hardware Setup === | ||
+ | To demonstrate the //Script Editor//, the //Protocol Analyzer// instrument will be used to transmit and receive UART signals. | ||
+ | |||
+ | Connect the Test & Measurement Device' | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.2 Software Setup === | ||
+ | For the //Script Editor// to make use of the //Protocol Analyzer// instrument, it must be open in WaveForms. In WaveForms' | ||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | |||
+ | <WRAP group> <WRAP column half> | ||
+ | Open the //Protocol UART// example script, by selecting it from the **Example** dropdown. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | Prior to running the script, what it does and how it works will be briefly discussed: | ||
+ | |||
+ | The Protocol Analyzer instrument is configured in UART mode, and is used to send and receive data. First, the string " | ||
+ | </ | ||
+ | <code javascript>// | ||
+ | if(!(' | ||
+ | |||
+ | Protocol.Mode.text = " | ||
+ | Protocol.UART.Receiver() // reset receiver | ||
+ | |||
+ | Protocol.UART.Send(" | ||
+ | var rx = Protocol.UART.Receive() // receive text | ||
+ | print(rx) | ||
+ | |||
+ | Protocol.UART.Send(" | ||
+ | var rx = Protocol.UART.Receive() // receive text | ||
+ | print(escape(rx)) | ||
+ | |||
+ | Protocol.UART.SendArray([1, | ||
+ | var rx = Protocol.UART.ReceiveArray() // receive array | ||
+ | print(rx) | ||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | More information on the functions and objects available in the //Script Editor// can be found in the in WaveForms' | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.3 Running the Script === | ||
+ | Click the Run ({{: | ||
+ | |||
+ | Print statements and uncaught errors are shown in the //Output// panel. | ||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | <WRAP group> <WRAP column half> | ||
+ | === 2.4 Debugging === | ||
+ | If in the process of writing a script, the script needs to be stepped through to find errors, the Script Editor' | ||
+ | |||
+ | Debugging is done inside WaveForms itself, allowing the user to step through the execution of the script. The debugger is accessed by clicking the Debug ({{: | ||
+ | |||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | |||
+ | <-- | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== 3. Script Editor User Interface Overview ==== | ||
+ | //This section walks through the different controls and features present in the //Script Editor. | ||
+ | |||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | |||
+ | === 3.1 The Control Toolbar === | ||
+ | The control toolbar contains menus and control interfaces used to configure the //Script Editor//, listed below: | ||
+ | * //Debug//: Opens a QT Script Debugger window. | ||
+ | * //Run//: Executes the script. | ||
+ | * //Stop//: Stops debugging or execution of the script. For **Stop** to work, the code needs to use the // | ||
+ | * //Abort//: Forces the execution to halt immediately. | ||
+ | * //Zoom In// & //Zoom Out//: Used to increase or reduce the font size of the code editor respectively. | ||
+ | * //Clear//: Clears the Output Panel | ||
+ | * // | ||
+ | </ | ||
+ | <WRAP column half> | ||
+ | |||
+ | {{ reference: | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | === 3.2 The Menu Bar === | ||
+ | <WRAP group>< | ||
+ | **File** is used to open an existing WaveForms //Script Editor// project, save the current //Script Editor// project, or close the //Script Editor// | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | **Edit** contains buttons for Undo and Redo, as well as options for enabling shortcuts for code completion and finding and replacing. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | **Control** accesses the Debug, Run, Stop and Abort actions. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | **View** has options to enable the Output panel and a plotting window. | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | The **Window** menu can be used to access other instruments, | ||
+ | </ | ||
+ | {{: | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | === 3.3 The Search Toolbar === | ||
+ | <WRAP group>< | ||
+ | This toolbar can be used to search for certain parts in the script, and to replace those parts. Settings for wildcard support in the input string can be opened with the {{: | ||
+ | </ | ||
+ | {{ reference: | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | === 3.4 The Script Editor === | ||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | The Script Editor is an editor where the JavaScript code can be viewed and edited. | ||
+ | |||
+ | </ | ||
+ | <WRAP column half> | ||
+ | |||
+ | {{: | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | |||
+ | === 3.5 Output Panel === | ||
+ | |||
+ | The output panel contains the results of print() statements and error messages. | ||
+ | |||
+ | </ | ||
+ | <WRAP column half> | ||
+ | |||
+ | {{: | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | ---- | ||
+ | <WRAP group> | ||
+ | <WRAP column half> | ||
+ | |||
+ | === 3.6 WaveForms Help Tab === | ||
+ | Accessed via **Help** in the tab bar, the WaveForms Help Tab contains reference materials for all WaveForms instruments. | ||
+ | |||
+ | Section 4, //" | ||
+ | |||
+ | </ | ||
+ | <WRAP column half> | ||
+ | {{: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Next Steps ==== | ||
+ | |||
+ | For more guides on how to use the Digilent Test and Measurement Device, return to the device' | ||
+ | |||
+ | For more information on WaveForms visit the [[software: | ||
+ | |||
+ | For technical support, please visit the [[https:// |