diff --git a/tools/js/README.md b/tools/js/README.md index 84c75b4c30..d49efa9e27 100644 --- a/tools/js/README.md +++ b/tools/js/README.md @@ -1,33 +1,112 @@ # About Scripts Scopy Scripting Guide is available at: https://wiki.analog.com/university/tools/m2k/scopy/scripting-guide -# New features (Scopy2) +# What's new? -1. Adding a new device in device browser - - Command: `scopy.addDevice(QString category, QString uri)` - - category: Device category type ("iio" for example) - - uri: Use the context at the provided URI -2. Establishing a connection with a device - - Commands: - - `scopy.connectDevice(int idx)` - - idx: The index represents the position of the device in the device browser - - `scopy.connectDevice(QString devID)` - - devID: The device ID that was returned upon adding it to the device browser +## Scopy Environment-Oriented Commands + +1. Accept the license in advance. The command can be used after resetting the license preference or if the application is being used for the first time + - `scopy.acceptLicense()` +2. Print Scopy about page + - `scopy.aboutPage()` +3. Start/stop the device scanning process + - `scopy.startScan(bool scanState)` + - scanState: True for start, false for stop. + - return: True if the scan started, false otherwise. +4. Running a script from a given file + - `scopy.runScript(QString scriptPath, bool exitApp = true)` + - scriptPath: The path to the script. + - exitApp: If set to true, the application will be closed after running the given script. + - `scopy.runScriptList(QStringList scriptPathList, bool exitApp = true)` + - scriptPathList: A list of paths for multiple scripts. + - exitApp: If set to true, the application will be closed after running the given script. +5. Get Scopy preferences + - `scopy.getPreferences()` + - return: A QMap with pairs of type . + - `scopy.getPreference(QString prefName)` + - prefName: The name of the preference. + - return: A QPair of type . +6. Assign a value to a preference + - `scopy.setPreference(QString prefName, QVariant value)` + - prefName: The name of the preference. + - value: The value to be assigned to the preference. +7. Load a configuration file + - `scopy.loadSetup(QString filename, QString path)` + - filename: The name of the configuration file. + - path: The path to that file (application directory path by default). + - return: True if the file was loaded, false otherwise. +8. Save the changes of a configuration file + - `saveSetup(QString filename, QString path)` + - filename: The name of the configuration file. + - path: The path where the file should be saved (application directory path by default). + - return: True if the file was saved, false otherwise. + +## Device-Oriented Commands + +1. Add a new device to the device browser + - `scopy.addDevice(QString uri, QString cat = "iio", bool async = false)` + - uri: Use the context at the provided URI. + - cat: Device category type ("iio" for example). + - async: Determine whether the device creation is performed synchronously or asynchronously (false by default). + - return: The device id on success, an empty QString otherwise. + - `scopy.addDevice(QString uri, QList plugins, QString cat = "iio", bool async = false)` + - uri: Use the context at the provided URI. + - plugins: Active plugin list. + - cat: Device category type ("iio" for example). + - async: Determine whether the device creation is performed synchronously or asynchronously (false by default). + - return: The device id on success, an empty QString otherwise. +2. Device connection + - `scopy.connectDevice(int idx)` + - idx: The index represents the position of the device in the device browser. + - return: True if the device was successfully connected, false otherwise. + - `scopy.connectDevice(QString devID)` + - devID: The device ID that was returned upon adding it to the device browser. + - return: True if the device was successfully connected, false otherwise. 3. Device disconnection - - Commands: - - `scopy.disconnectDevice()` - - Disconnects the last connected device - - `scopy.disconnectDevice(QString devID)` - - devID: The device ID that was returned upon adding it to the device browser -4. Switching the plugin tools - - Each plugin includes a list of tools, allowing you to choose which one to be the current tool - - Commands: - - `scopy.switchTool(QString toolName)` - - toolName: The name of the desired tool from the last connected device - - `scopy.switchTool(QString devID, QString toolName)` - - devID: The device ID that was returned upon adding it to the device browser - - toolName: The name of the desired tool -5. Running a script from a given file - - Command: `scopy.runScript(QString scriptPath, bool exitApp = true)` - - scriptPath: The path to the script - - exitApp: If set to true, the application will be closed after running the given script + - `scopy.disconnectDevice()` + - Disconnects the last connected device. + - return: True if the device was successfully disconnected, false otherwise. + - `scopy.disconnectDevice(QString devID)` + - devID: The device ID that was returned upon adding it to the device browser. + - return: True if the device was successfully disconnected, false otherwise. +4. Remove a device from device browser + - `scopy.removeDevice(int idx)` + - idx: The index represents the position of the device in the device browser. + - return: True if the device was successfully removed, false otherwise. + - `scopy.removeDevice(QString uri, QString cat = "iio")` + - uri: Use the context at the provided URI. + - cat: Device category type ("iio" for example). + - return: True if the device was successfully removed, false otherwise. +5. Switching the plugin tools + - `scopy.switchTool(QString toolName)` + - toolName: The name of the desired tool from the last connected device. + - return: True if the tool was successfully switched, false otherwise. + - `scopy.switchTool(QString devID, QString toolName)` + - devID: The device ID returned upon adding the device to the device browser. + - toolName: The name of the desired tool. + - return: True if the tool was successfully switched, false otherwise. +7. Get the active tools of the most recently connected device + - `scopy.getTools()` + - return: A QStringList which contains the device tools. + - `scopy.getToolsForPlugin(QString plugin)` + - return: A QStringList containing the `plugin` tools. +8. Get the names of currently connected devices. + - `scopy.getDevicesName()` + - return: A QStringList containing the devices. +9. Get the plugin list of a device + - `scopy.getPlugins(int idx)` + - idx: The index represents the position of the device in the device browser. + - return: A QStringList containing the plugins. + - `scopy.getPlugins(QString uri, QString cat = "iio")` + - uri: Use the context at the provided URI. + - cat: Device category type ("iio" for example). + - return: A QStringList containing the plugins. +10. Start or stop a specific tool of the most recently connected device + - `scopy.runTool(QString tool, bool flag)` + - tool: The name of the tool. + - flag: True if we want the tool to run, false if not. + - return: True if the running state was changed, false otherwise. +11. Get the current running state of the button + - `scopy.getToolBtnState(QString tool)` + - tool: The name of the tool. + - return: The state of the button on success, false otherwise. diff --git a/tools/js/active_learning/sar_adc.js b/tools/js/active_learning/sar_adc.js index d9b07b4d06..46422c1d19 100644 --- a/tools/js/active_learning/sar_adc.js +++ b/tools/js/active_learning/sar_adc.js @@ -37,9 +37,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -/* Perform tool reset */ -launcher.reset() - /* Comparator Input Voltage */ var input_voltage = 2 @@ -193,12 +190,21 @@ function successive_approximation(max_val) { max = digital_output - 1 else break - } + } } /* Main function */ function main (){ + /* Feel free to modify this as needed */ + var uri = "ip:192.168.2.1" + + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) + msleep(1000) + if (!connected) + return Error() + set_signal_generator() msleep(100) @@ -219,4 +225,6 @@ function main (){ } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main() \ No newline at end of file diff --git a/tools/js/examples/dio.js b/tools/js/examples/dio.js index 1048beb09d..4c919751b1 100644 --- a/tools/js/examples/dio.js +++ b/tools/js/examples/dio.js @@ -37,9 +37,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -/* Perform tool reset */ -launcher.reset() - /* Setup DigitalIO */ function set_dio(){ @@ -82,11 +79,25 @@ function binary_counter(){ /* main function */ function main(){ + /* Feel free to modify this as needed */ + var uri = "ip:192.168.2.1" + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) + msleep(1000) + if (!connected) + return Error() + scopy.switchTool("Digital I/O") set_dio() - binary_counter() + msleep(1000) + + scopy.disconnectDevice(devId) + scopy.removeDevice(uri) + msleep(1000) } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main() \ No newline at end of file diff --git a/tools/js/examples/power_dmm.js b/tools/js/examples/power_dmm.js index f6b2c3336c..34bafef180 100644 --- a/tools/js/examples/power_dmm.js +++ b/tools/js/examples/power_dmm.js @@ -37,9 +37,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -/* Perform tool reset */ -launcher.reset() - /* Set Power Supply */ function set_power_supply(){ @@ -93,11 +90,23 @@ function set_dmm(){ /* main function */ function main(){ + /* Feel free to modify this as needed */ + var uri = "ip:192.168.2.1" + + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) + msleep(1000) + if (!connected) + return Error() + + scopy.switchTool("Power Supply") set_power_supply() msleep(1000) + scopy.switchTool("Digital I/O") + set_dmm() msleep(1000) @@ -113,7 +122,12 @@ function main(){ /* Print Channel 2 value to console */ printToConsole(ch2) - + + scopy.disconnectDevice(devId) + scopy.removeDevice(uri) + msleep(1000) } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main() \ No newline at end of file diff --git a/tools/js/examples/siggen_osc.js b/tools/js/examples/siggen_osc.js index df41ae8d6b..46ce6035d3 100644 --- a/tools/js/examples/siggen_osc.js +++ b/tools/js/examples/siggen_osc.js @@ -37,9 +37,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -/* Perform tool reset */ -launcher.reset() - /*Setup Signal Generator*/ function set_signal_generator(){ @@ -92,20 +89,38 @@ function set_oscilloscope(){ /* Setup main function */ function main(){ - + /* Feel free to modify this as needed */ + var uri = "ip:192.168.2.1" + + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) + msleep(1000) + if (!connected) + return Error() + + scopy.switchTool("Signal Generator") + set_signal_generator() msleep(1000) + + scopy.switchTool("Oscilloscope") set_oscilloscope() - msleep(1000) - /* Read Channel 1 Peak-to-Peak Value */ var pp = osc.channels[0].peak_to_peak + msleep(1000) + /* Print value to Console */ printToConsole(pp) + + scopy.disconnectDevice(devId) + scopy.removeDevice(uri) + msleep(1000) } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main() diff --git a/tools/js/read_dmm.js b/tools/js/read_dmm.js index 5132bfa439..0cd41fc8ab 100755 --- a/tools/js/read_dmm.js +++ b/tools/js/read_dmm.js @@ -79,30 +79,23 @@ function run_tests() { siggen.running = false } -function connect(host) { - print("Connecting to " + host + "...") - - var success = launcher.connect("ip:" + host) - - if (success) - print("Connected!") - else - print("Failed!") - - return success; -} - function main() { - /* hardcoded for now */ - var host = "192.168.2.1" + /* Feel free to modify this as needed */ + var uri = "ip:192.168.2.1" - var connected = connect(host) + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) + msleep(1000) if (!connected) return Error() run_tests() - launcher.disconnect() + scopy.disconnectDevice(devId) + scopy.removeDevice(uri) + msleep(1000) } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main() diff --git a/tools/js/startupscript.js b/tools/js/startupscript.js index b1acead1d9..a35efe5088 100644 --- a/tools/js/startupscript.js +++ b/tools/js/startupscript.js @@ -1,27 +1,12 @@ #!/usr/bin/scopy -s -/* This is the script that starts scopy up and connects to the emulator */ -var host = "127.0.0.1" - - -function connect(host) { - print("Connecting to " + host + "...") - - var success = launcher.connect("ip:" + host) - - if (success) - print("Connected!") - else - print("Failed!") - - return success; -} - +/* Before running this example it is necessary to run: iio-emu adalm2000 */ +var uri = "127.0.0.1" function main() { - /* hardcoded for now */ - var connected = connect(host) + var devId = scopy.addDevice(uri) + var connected = scopy.connectDevice(devId) if (!connected) return Error() @@ -30,9 +15,9 @@ function main() { /* Run oscilloscope */ osc.running=true /* Focus oscilloscope */ - launcher.focused_instrument=0 - /* Resume control to the application*/ - returnToApplication(); + scopy.switchTool("Oscilloscope") } +/* To keep the application session after running a certain script */ +/* use the command line options: -r or --keep-running. */ main()