• 0
Jonboy

API or software interface to Waveforms 2015

Question

Is there an API or Software interface to the Waveforms 2015 software?  I would like to use Waveforms 2015 as the interface to an Analog Discovery 2 for making various measurements but pass that data to another piece of software such as LabView, TestStand, or Python, etc. as part of a larger automated test sequence.  Basically I would like to incorporate Waveforms 2015 into a larger test environment that may contain additional test equipment.

I am aware of the SDK that allows for LabView and Python to control the Analog Discovery 2 directly. However, this prevents Waveforms 2015 from being used at the same time and requires me to re-develop all of the measurement setup and algorithms already developed in Waveforms 2015.  I am also aware of and I am using the Script tool inside of Waveforms 2015 for test sequences, but this still only gives me access to the features within a single Waveforms 2015. 

Is it possible to programmatically open a saved workspace, open a saved script, run the script or a particular tool such as the Scope or Impedance Analyzer, and read the measured values or save them to a file for storage? 

For example, let's say I would like to have a saved workspace/script to run a curve trace measurement using the waveform generator and scope. Then I would like to open a different saved workspace/script to perform a series resistance measurement using the Impedance Analyzer that in turn uses the waveform generator and scope pins.  Finally I would like to perform a functional test by using a different saved workspace/script to generate a waveform and capture it on a scope and make some basic measurements on the signal.  Can all of this be accomplished in a single automated process using Waveforms 2015 as the interface to the Analog Discovery 2?  Or would I need use the SDK to re-develop all of the tool algorithms such as the scope and impedance analyzer measurements by interfacing directly to the Analog Discovery 2 directly, but result in a large amount of extra development work to basically duplicate the Waveforms 2015 features?

Thanks

Share this post


Link to post
Share on other sites

14 answers to this question

Recommended Posts

  • 1

Hi @Jonboy

To interface the WaveForms application with other applications you could use the Script tool. 
You can save the needed data (measurements) in files (File.write/append..) and execute external applications or scripts with Tool.start(program, argument array, work directory)

The workspace opening can't be automated, but you might not even need it since you can have at the same time (in one workspace) multiple instruments opened and configured.
Multiple instruments can be opened under File/New and from script can be accessed like: Scope1, Scope2
When an instrument is started (.Run(), .Single()) it will automatically take ownership of the required hardware resources, like Scope1 takes control over Scope resource, Impedance1 takes control over Scope and Wavegen channel 1 resource.

Scope1.run()
for( var i = 0; i < 10 && Scope1.wait(); i++){
    var f = File("C:/temp/data.txt")
    f.write("") // clear
    f.appendLine(Scope1.Channel1.measure("Average"))
    f.appendLine(Scope1.Channel1.measure("Peak2Peak"))
    Tool.start("C:/python-2.7.6/python.exe", ["test.py"], "C:/temp")
}

 

Share this post


Link to post
Share on other sites
  • 1

Hi @bvleo

The WF beta version adds "-runscript" argument which starts the Script, with up to 1 second delay.
https://forum.digilentinc.com/topic/8908-waveforms-beta-download/
> WaveForms.exe workspace1.dwf3work
> WaveForms.exe -runscript
> WaveForms.exe -runscript workspace1.dwf3work

Thank you for the observation. Information about Spectrum Analyzer is missing from the help.
You can discover the objects/functions without help by pressing Ctrl+Space in the editor:
image.png.dc0643a19d9f7e4b47593ea46ac0c4d1.png

Edited by attila

Share this post


Link to post
Share on other sites
  • 0

Atilla,

Is is possible to run a script automatically upon opening it? We have a project that utilizes a Python interface and would like to have it call a script, run it, and then look at the data in a file created by the script. Like Jonboy, we're trying to use WF in a testing environment, so we'd like to have the whole process automated without the need to press UI buttons within WF.

Also, is there documented changes to the Scripting interface available for WF 3.6.8? In some of your other posts you've shown examples using the previously unavailable Spectrum measurements Script functions, but we haven't been able to locate any documentation regarding what functions are available.

Thank you!

Edited by bvleo

Share this post


Link to post
Share on other sites
  • 0

@attila

Thank you for your response. I've downloaded the beta and will try the -runscript argument. Do I use this in the Python code or at the start of the WF script? An example would be appreciated, as I am learning as I go and a lot of this is new to me.

Thank you!

-bvleo

Share this post


Link to post
Share on other sites
  • 0

Hi @bvleo

From Python you can execute an external application like this:

import subprocess
subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe', '-runscript'])

Share this post


Link to post
Share on other sites
  • 0

Hi @attila,

The final iteration of our project is supposed to run on Raspberry Pi. Looking at the Beta page you linked, I don't see any versions that are compatible with ARM processors. Is there any ARM-compatible version of WF that will be able to use the "-runscript" argument?

Thank you,

-bvleo

Share this post


Link to post
Share on other sites
  • 0

Hi @attila,

Not sure if I should start a new thread, but I'm struggling with the stuff being discussed here.  I'm trying to use Python to open a workspace and then run a script in the workspace.

import subprocess
subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', 'phase_noise_237.dwf3work'])

subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', '-runscript export_data.dwf3script'])

 

I want to open the "phase_noise_237.dwf3work" workspace, and then run the script "export_data.dwf3script", which is saved as a part of that workspace.

Waveforms opens, but does not open the workspace. Then I open the workspace by hand, and then run the python code to run the script, it tries to open Waveforms again.

Thanks,
Phil

Share this post


Link to post
Share on other sites
  • 0

Hi @Phil_D

Try calling to load the workspace and to run script one after the other.

subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', 'phase_noise_237.dwf3work'])
subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', '-runscript'])

Share this post


Link to post
Share on other sites
  • 0

Thanks @attila.

Now, I'm using this:

import subprocess
subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe','C:/Users/phild/Documents/phase_noise_408.dwf3work'])
subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe','-runscript'])

At this point, Waveforms opens, and the specified workspace does load automatically now, which is good! 🤩 (Side note: I had to move the workspace to a different directory so that it could be found.  Originally, it was in the same directory as WaveForms.exe, but it wouldn't load from there.) The script is still not running automatically though.

Any thoughts on why the script isn't running automatically?

Thanks,

Phil

ps: I am running Waveforms Version 3.8.2 32-bit Qt 5.6.3 Windows 7

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Hey @Phil_D

I too had a problem with getting WaveForms to run automatically, and my group didn't find a way to make it work through the suggested code. However, we did have success when we commanded Python to simulate an F5 key press, which is a shortcut in WF to run the script. We used the library "uinput". Here's a sample of the actual command we used. I'm not certain that it's all you need, as I was not the primary Python programmer for this project, but at least it'll give you an idea of what needs to be done for this workaround. The sleep timers are there to give the program time to start and load the workspace.

waveform_Call = subprocess.Popen("exec " + waveforms, shell = True)
    waveform_Call
    time.sleep(10)
        device = uinput.Device([
                uinput.KEY_FN,
        uinput.KEY_F5,
        ])
    time.sleep(1)
        device.emit_combo([
        uinput.KEY_FN,
        uinput.KEY_F5,
        ])

Edited by bvleo
formatting

Share this post


Link to post
Share on other sites
  • 0

Hi @Phil_D

I just notice that the -runscript is only working when the instruments are in docking window mode.
My bad, runscript is only looking for docked Script window. It will be fixed in the next software version.

image.png.f4b614274ce43764dd55c6c2cd451514.png

Share this post


Link to post
Share on other sites
  • 0

Hi @Phil_D @bvleo

The issue is fixed in the latest beta version. You can call: 
subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe','default.dwf3work','-runscript'])

When a WF app instance is running, the above call will notify it to load and run the script. The '-runscript' will supress the 'save current workspace' message.

 

Share this post


Link to post
Share on other sites
  • 0

Thank you @attila!  This update seems to be working for me!

Also, thank you for the suggestion @bvleo!

For anyone reading this thread and trying to do something similar, I created a python script with these commands:

import subprocess
subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe','C:/Users/User/pxm_2019/pn_410.dwf3work'])
subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe','C:/Users/User/pxm_2019/pn_410.dwf3work','-runscript'])

This opens Waveforms, opens my workspace with the saved script (that is open within the saved workspace), and then runs the script.

If Waveforms is already open, then I can just create a second python script with the second line deleted.

ps: If you try to copy and paste code out of here into notepad, you'll probably get some extra characters and python will give errors, so watch out for that.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now