Jump to content
  • 0

Script to enable or disable FFT display in scope.


P. Fiery

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?

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

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

 

 

Link to comment
Share on other sites

Hi @P. Fiery

Thank you for the observation. It is fixed for the next version.
This problem occurred on application close having detached script plot windows. This did not manifest under win10, the app closed normally.

The context could be cleared for each script run, but I let to keep it to have code completion for variables, like this:
image.png.bba867078c573c593d1144ead90a9cc2.png

You could use this as feature to check if this is the first run of the script, like:
image.png.966d77b171e3e339bfe2e52b3a1f80aa.png

 

Link to comment
Share on other sites

This latest beta, (and the previous), have been very good. I have no complaints, and no "must have" additional requests. The ability to control the FFT window instance is welcome, thank you.. 

There is still a bug though that manifests on my Windows 7 desktop system: When exiting the waveform application in any of the usual ways of closing an app, the script window closes right away. The plot child windows of the script don't close properly, nor does the main Waveforms window. This happens whether I choose to save the project on exit or not. The windows hang, the cursor hourglasses, and the usual microsoft error window allows me to close the app. There seem to be no negative side effects to this.

One thing I've noticed is that some variables declared without var in root scope will retain their values from run to run. I now realize this is probably because they are not just global but bound to the parent window of script. Specifically:

  1. load the waveforms app
  2. write and run this code:  testvar = 10;
  3. edit the code to this: print(testvar);     // testvar = 10;
  4. run this revised code. The output is "10".

Adding "use strict" to the file ahead of this doesn't flag this as an error. Should "use strict" work as in the JS standard?

On further experimentation I now realize that all variables and constants declared at rood scope retain their values from run to run. That is, you can run once, and then print any of these variables in the code before they are declared and the output will be the values they held at the end of the previous run of the script.

After reading up on the inner details of variable scope in javascript, I've placed all my code into functions. (All my functions were written as 'pure' so this wasn't too difficult.)  There are a very few variables and several constants still declared with var and const at root scope and therefore properly global. However, these do persist from one run to the next.

The plotn.Yn.data arrays persist too, and these may be very large in my script application.

Is this behavior as intended? Could it be the reason for the crash on exit bug I'm experiencing?


 

Link to comment
Share on other sites

Attila, this seems fine so far and thank you for this great work.

The "all files" button in the search bar executes a "replace all" across all open script files. I discovered this when I had the letter "i" as the Find argument and nothing as the Replace argument. Clicking 'All Files' deleted all instances of the letter "i" in both my script files. Logical, but yikes. Perhaps both "Replace All" and "All Files" should include a "Confirm?" interaction? 

Nothing seems to be broken in this latest rev. I'll be using this every day for the next while. Thanks again!

Link to comment
Share on other sites

Attila, thanks again, this is just great. I'm sure everyone using script will welcome these features. I've used most of these new features for a few hours now. Within the Waveforms app itself everything seems to be fine, but saving and exiting exhibit the following misbehavior:

  1. The waveforms app crashes during exiting. I didn't check closely enough to see if it saves the project before crashing.
  2. The previous "save project" and "save .js" functionality works correctly. However, the new "save all" item does the following:
    1. It asks for a folder, and writes to this folder my two script tabs out under the names I'm using. No problem.
    2. However, the next time I do this, the result is shown below. "Functions" and "Main" are meant to be pairs within one code version so of course the copy suffix should match. 
    3. Upon the third use of "save all", nothing at all seems to happen on disk. 

image.png.f9556f14aeac3de2f79ea62bf0fede91.png

In the "bug or feature?" department, pasting text into the new Find: <text> search feature immediately causes the first instance of the text to be selected and highlights all other instances in the script tab window that has focus. Note that this first search occurs consequent to the paste, not due to clicking "Next". (Not really a problem, perhaps it's the more efficient behavior. )  Switching to the other tab again automatically selects the first and highlights the remaining instances of <text> found there. If user searches for something else in the 2nd tab window, this different text is found as expected. However, upon returning to the first tab the original <text> is still highlighted. This may be good and useful behavior. Initiating another search clears the highlight.  

Finally, the "All Files" toolbar item is part of the search suite, but it seems to do nothing at all, not even in the context I detailed just above.

CTRL+F invokes "find" - great!  And upon CTRL+F any text in one's copy buffer is pasted into Find and instantly found. Perfect!

I discovered child windows in the script editor can be surfaced or hidden with a right-click in the upper menu area. Plot1 was there, unchecked so that's all good.

Clearing the output window - ah, relief, thank you!

With these features, I found working on a complex script to be fast and efficient. 

Oh: FYI. I'm running Windows 7 still. It's fully updated, but it's not Windows 10.  I will be making this project portable soon on a Win 10 laptop. 

(I dread having to move my desktop to Win 10.  I have so much software on this machine and it all works perfectly. Some is older XP engineering software that is second-nature to me now. Alas.) 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...