• 0
P. Fiery

Script to enable or disable FFT display in scope.

Question

From within a script, how do I perform the equivalent of checking the View-FFT item to display and activate the FFT?  

I want to turn on the FFT, perform an acquisition, access the FFT mag and freq array data, and then turn off the FFT for subsequent acquisitions. The reason for turning it off after the first acquisition is that I'm doing a large series of sequential acquisitions and keeping the FFT function active takes an extra few milliseconds per acquisition, which adds up and slows down my application appreciably. 

I've used the completion feature, which looks very helpful, except consider:

Scope1.FFT.Window.setChecked(true);  

This looks like it should do the trick, but it does nothing. Neither does the false argument, or 1 or 0. And there are many other plausible but unsatisfying things to try via the code completion feature. 

As a more general question then, how does one go from what one wants to do to finding the syntax to do it? Is there somewhere where all these possible statements are listed? 

Alternately, is there a way to dump all of the settings that configure what you see on the screen, then make the FFT graph visible, then dump all the settings again and look for what has changed to discover how to do such things in script?

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hi @P. Fiery

The Views can't be opened/closed from Script.

The FFT.Window refers to data windowing.

You could have 2 Scopes opened, one with and the other one without fft, and control them from Script as Scope1 and Scope2.

image.thumb.png.817ed49988ed54f647fdda4dfde6d300.png

Share this post


Link to post
Share on other sites
  • 0

Thank you Attila, this will probably be an effective work around. I  very much appreciate your support here. Coming to javascript from C,  I have gleaned a great deal from the answers you have given to others' questions.  

The AD2 is really a fine and powerful tool and the scripting makes it open-ended and even more useful. I have an expensive Tektronix scope on my bench but the only reason to ever turn it on is if I need 1G sampling.  An "AD3" could obviate it entirely. :)  

The AD2 with scripting is probably saving me about 6 months of time relative to how I was going to handle my current work before I tried scripting the AD2. But my script is getting quite long...

Question:

Is it possible to use some form of syntax such as src="filename.js"? I would be great to be able to keep a short "main" program within the editor integrated with AD2 script, and have all the functions in an external script. Having these two files side by side would be much more efficient than jumping around within one long script file, and it would be nice to work mostly in a full-featured JS editor.

Share this post


Link to post
Share on other sites
  • 0

Attila you may already be aware of all the following, but in the  hope of being helpful I offer a bug report on this beta release:

  1. The overall waveforms project file fails to store the window position of the script. Not sure this is so if the script is docked, but definitely when it is not docked. Minor issue.
  2. If the user has renamed script File 1 and File 2, the overall waveforms project file fails to store these new names.
  3. In general, the file save command within the script window functions like a file export. It seems that once the script is saved this way, no further reference is made by Waveforms to this saved .js file. 
  4. Consistent with #3, in the scenario where user has file 1 and file 2 and associated tabs, and user has checked the 'include' box for file 2 in the file 1 tab, removing file 2 maintains it's functionality in the script. The file tabs disappear though. Modifying file 2.js externally with another editor has no effect, so there must be a local copy in memory. Worse, if waveforms is now closed and reopened, the 'include' functionality is gone, along with file 2. (Though if the user saved it, it is on drive. )

And by the way, if one has un-docked the script and closes the script window before saving the overall waveform project, the entire script is gone. Gone irretrievably it seems, unless of course one has an earlier backup, or one has saved the script project separately from the waveforms project, or one has, (now with this new beta), saved the individual script file. This is the case in the last official non-beta release and it still is. 

My overview is this is on the way to what I'd like, (using an external editor running simultaneously with waveforms.exe, with the "main" program in the native waveforms script window and the functions in the separate concurrent editor application), but it's not there yet. 

In general, unless one is careful and knows there are pitfalls, it would be quite easy to lose one's code entirely, or lose the portion of it in "file 2", or think the file on disk was actually in use within waveforms, etc. I almost did so a few weeks ago, but fortunately I'd just made a backup so I lost only a few comments I'd added. 

Share this post


Link to post
Share on other sites
  • 0

Hi @P. Fiery

1. The loading of undocked window position seems to be working. The size might be adjusted from too small window to preferred dimension. This adjustment will be removed in the next version.
2. Solved.
3. Yes, open/save file is like import/export.
4. When there is only one file in the Script the tab-bar is hidden, like it was in earlier versions with no multiple file option. This, to simplify the interface, to have more space for editing.
The next app version will notice when any modification is made to the script code and ask to save changes or not.
The script is kept in the workspace (project) since is intended to be used to automate the instruments. It is likely to be usable only with the given instrument setup.
The workspace can contain everything that is needed for a project in one portable file: instrument setup, imported audio files, custom waveforms, reference waveforms, instructions in rich text View/Notes, scripts, notes on plot...

It is always a good practice to have regular backups with any project (software, document, WF workspace...)

If you want to load and run external script you can use the "-script" argument:
> "C:\Program Files (x86)\Digilent\WaveForms3\WaveForms.exe" -script myscript.js

The script editor is not too powerful, but you can use the Ctrl+Space or have View/ Code completion activated, to browse the available objects-functions.

image.png.da4134decc818a7170f0f04372062923.pngimage.png.6571d3185fff6a039273ae67420742c0.png

image.png.13961f749c157b779afc6ef0af5a7f6a.png

 

Share this post


Link to post
Share on other sites
  • 0

Attila, thank you, this works. And thanks for pointing out the script hints in the status bar; all this time and I didn't notice them.

Two additional things would make this coding environment sufficiently "complete" IMO:

  1. Within the script editor, please give us a hot key to sequence between different script tabs. CTRL+TAB would be consistent across the app.  OR:
    1. If possible, provide separate simultaneous instances of the script editor so one can view and edit all script files at once.
  2. Of course, a search and replace would be great to have. It's the one editor function I truly miss. I cut, paste to notepad, and do search and replace there as a workaround.

Helpful things: 

  1. A way to  clear the output window, other than quitting and restarting.
  2. If user accidentally closes a plot window, say PLOT1, it seems there is no way to bring back PLOT1. You have to instantiate a new plot, which will be automatically  PLOT2, and manually set the axis as they were, and manually change any references from PLOT1 to PLOT2.  
  3. The "safest" practice is to save everything: the individual scripts as .js, the script project, the scope project, waveform project, etc. This way, if user closes some child windows and saves the whole waveforms project that way, everything can be reassembled. Backups are good practice but one can still lose one's current post-backup work with a couple of thoughtless clicks perhaps to make screen space for multitasking.   I'm saving individual things now manually whenever I've edited something.  A "SAVE ALL" command would be great. 

Even without any of this, Waveforms + AD2 has about doubled my productivity as a consultant. And I have only begun to leverage it. So: Thank you for this great product! 

Two heads are useful:

image.thumb.png.c32475c2abdc62da4a74c8fe500f18a5.png

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @P. Fiery

https://forum.digilentinc.com/topic/8908-waveforms-beta-download/

1. Added Ctrl+Tab
2. Added Find Replace with optional pattern matching
1. The clear option was hidden in the output window context menu. Now I added clear() function and a button for this purpose.
2. You can use the setPlots function, like setPlots(3) to have 3 plots.
3. Added Save All and modified open to let you select multiple files.

Thank you for your feedback.

image.png.7637a954258d6890b35c636c6399f84e.png

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