Jump to content
  • 0

Scripts


tomas61

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

 

 

 

Link to comment
Share on other sites

19 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

Link to comment
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

 

 

 

Link to comment
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.

Link to comment
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");

 

Link to comment
Share on other sites

  • 0

Hi Attila,

 

Why the  "

var data = Scope1.Channel2.data;

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

plot1.Y1.data = data;" is different than the data displayed in the scope

 

how do I plot a bidimensional array

 

Thanks

Script plot.png

Link to comment
Share on other sites

  • 0

Thanks

how do I format a number to display only two decimal points in print

print(totalCounter);

will print this

2.2000000000000006

What is the base language you use for script, (java, python, etc)

This would be so much easier with a good user manual

 

Link to comment
Share on other sites

  • 0

How do I define bi dimensional arrays?

var peakCounter = [];

var peakCounter = [][]; ---syntax error

 

var peakCounter = [,];---doesn't give me a syntax error but it doesn't work, it only follows the index after the comma

Thanks

Link to comment
Share on other sites

  • 0
On 5/18/2020 at 8:28 AM, attila said:

Hi @tomas61

See the Help tab, press F1 or Browse under Help menu.

1. To round a number to 2 decimals you can use: round(value*100)/100
2. To format the number for text conversion use: value.toFixed(2)

image.png.9373a3fb16834aa8ea64913512dc7ad2.png

Hi @attila

What is equivalent to "Ctrl+Space" combination key if I use Waveforms in a Mac laptop? Thk ! 

Link to comment
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
×
×
  • Create New...