Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS updates #1829

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 107 additions & 28 deletions tools/js/README.md
Original file line number Diff line number Diff line change
@@ -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 <QString, QVariant>.
- `scopy.getPreference(QString prefName)`
- prefName: The name of the preference.
- return: A QPair of type <QString, QVariant>.
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<QString> 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.
16 changes: 12 additions & 4 deletions tools/js/active_learning/sar_adc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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()
19 changes: 15 additions & 4 deletions tools/js/examples/dio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){

Expand Down Expand Up @@ -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()
22 changes: 18 additions & 4 deletions tools/js/examples/power_dmm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){

Expand Down Expand Up @@ -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)
Expand All @@ -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()
27 changes: 21 additions & 6 deletions tools/js/examples/siggen_osc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){

Expand Down Expand Up @@ -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()
27 changes: 10 additions & 17 deletions tools/js/read_dmm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading
Loading