Skip to content

Commit

Permalink
tools/js: Update the examples to the new scopy API.
Browse files Browse the repository at this point in the history
Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Nov 15, 2024
1 parent f1ffdf5 commit 4b97d80
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 57 deletions.
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()
29 changes: 7 additions & 22 deletions tools/js/startupscript.js
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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()

0 comments on commit 4b97d80

Please sign in to comment.