• 0

Question

I am trying to run scripts, but I haven't been able to find a good complete set of instructions/reference manual
Got the ECMA-262 manual and waveform 2015 ref. man. documents but neither tell me how to make a while loop that will stop when I press a key.

Also, why the data is not getting updated

for(outLoops=0;outLoops<10;outLoops++)

{

 

// reading 50 times, 5 seconds plus

for(loops=0;loops<10;loops++)

{

 

// acquire data

Scope1.single();

Scope1.wait();

 

data = Scope1.Channel2.data;

for(index=0;index<8;index++)

{

thresholdLow -= 0.01;

thresholdHigh = thresholdLow - 0.01;

data.forEach(function(sample){if((sample < thresholdLow)&&(sample > thresholdHigh))counter[index]++;});// build histogram

} //index

 

 

 

} // loops

 

 

 

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi @tomas61

You can use the wait() function or instrument.wait() or dialog like Tool.question() .getNumber() ...
See the examples or the Help tab in the application.

while(var i = 0; i < 10 && wait(1.5); i++) { ....

if(Scope.wait()) throw "Stopped"

if(!Tool.question("Continue?")) throw "Abort"

 

image.png.c002bee414d4ac0547d3f765af42c4ee.png

image.png.0408a78c7032fe8c14b359e77e025110.png

Share this post


Link to post
Share on other sites
  • 0

Thanks Attila,

But most importantly, why the variable data is not getting updated

 

It only works with the first set of data 

for(outLoops=0;outLoops<10;outLoops++)

{

// reading 50 times, 5 seconds plus

for(loops=0;loops<10;loops++)

{// acquire data

Scope1.single();

Scope1.wait();

data = Scope1.Channel2.data;

for(index=0;index<8;index++)

{

thresholdLow -= 0.01;

thresholdHigh = thresholdLow - 0.01;

data.forEach(function(sample){if((sample < thresholdLow)&&(sample > thresholdHigh))counter[index]++;});// build histogram

} //index

} // loops

 

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @tomas61

The data should be the data from the last capture.

You are performing 10x10 captures and the thresholdLow is decremented for each capture by 8x0.01 The threshold value for last capture will be 7.92 lower than for the first capture. You may want to initialize it for each capture.

Share this post


Link to post
Share on other sites
  • 0

Yep,

you were right, the bins weren't getting filled because my threshold was too big

Where do you get the info for commands like "Tool,question..."

Is there a main language reference book/document

Thanks

 

 

Share this post


Link to post
Share on other sites
  • 0

Thanks

One more, can you send an example on how to plot data from the script, keep getting parse error when trying "plot1.Y2.data[] = lData;"

if(!('Scope1' in this)) throw "Please open a Scope instrument";

Scope1.single();

if(!Scope1.wait()) throw "Stopped";

var average = 0;

var lData = Scope1.Channel1.data;

plot1.Y2.data[] = lData;

lData.forEach(function(sample){average += sample;})

average /= data.length;

print("Average: "+average+" V");

 

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