• 0
Sign in to follow this  
hugocoolens

converting dwfbat script to the new scripting language

Question

A few months ago I got an example of a batch script which ran fine under Waveforms 2. As I understand Waveforms 3 has a new scripting language. Could anyone here help me converting the old script (see below and attachment) to the new syntax?

WaveGen.1.Mode = "Basic"
WaveGen.1.Basic.Amplitude = 1
WaveGen.1.Basic.Offset= 0
WaveGen.1.Run

Scope.Channels.C1.Range = 2
Scope.Channels.C1.Offset = 0
Scope.Channels.C2.Range = 2
Scope.Channels.C2.Offset = 0

echo("Scope1-Input(Hz) (V)\tScope2-Output(Hz) (V)")

var hzStart = 1e3
var hzStop = 5e6
var steps = 100
var mul = Pow(10, (Lg(hzStop/hzStart)/(steps-1)))
var hz = hzStart
for i=1:1:steps
   WaveGen.1.Basic.Frequency = hz
   // time base = number of periods to capture / frequency
   Scope.Time.Base = 10/hz
   // wait between changing the frequency and acquisition
   Sleep(10) // 10ms
   Scope.Run
   Scope.Wait
   //echo(i+"\t"+hz +"\t"+ Scope.Measure.C1.Amplitude+"\t"+ Scope.Measure.C2.Amplitude )
   echo(hz +"\t"+ Log((Scope.Measure.C2.Amplitude/Scope.Measure.C1.Amplitude),10)*20)
   hz *= mul
end

kind regards,

hugo

bode_amplitude.dwfbat

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 1

The equivalent script in WaveForms3 java script looks like this:

Wavegen1.Channel1.Mode.text = "Basic"
Wavegen1.Channel1.Basic.Amplitude.value = 1
Wavegen1.Channel1.Basic.Offset.value = 0
Wavegen1.Channel1.run()

Scope1.Channel1.Range.value = 2
Scope1.Channel1.Offset.value = 0
Scope1.Channel2.Range.value = 2
Scope1.Channel2.Offset.value = 0

print("Scope1-Input(Hz) (V)\tScope2-Output(Hz) (V)")

var hzStart = 1e3
var hzStop = 5e6
var steps = 100
var mul = Math.pow(10, (Math.log(hzStop/hzStart)/Math.LN10/(steps-1)))
var hz = hzStart
for(var i=1; i <= steps; i++){
   Wavegen1.Channel1.Basic.Frequency.value = hz
   // time base = number of periods to capture / frequency
   Scope1.Time.Base.value = 10/hz
   // wait between changing the frequency and acquisition
   wait(0.01) // 10ms
   Scope1.single()
   Scope1.wait()
   //echo(i+"\t"+hz +"\t"+ Scope.Measure.C1.Amplitude+"\t"+ Scope.Measure.C2.Amplitude )
   print(hz +"\t"+ Math.log(Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10*20)
   hz *= mul
}

 

Edited by attila

Share this post


Link to post
Share on other sites
  • 1

Thank you for the correction.
 

Writing/logging to file can be done like this:
 

var file = File("C:/log.txt")
file.write("") //clear
//...
var sz = hz +"\t"+ Math.log(Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10*20
file.appendLine(sz)

See help for more options.
 

On recent MS Windows, writing to C: from applications without root permission will be placed to:
C:\Users\[user]\AppData\Local\VirtualStore\

Edited by attila

Share this post


Link to post
Share on other sites
  • 0

The equivalent script in WaveForms3 java script looks like this:

Wavegen1.Channel1.Mode.text = "Basic"
Wavegen1.Channel1.Basic.Amplitude.value = 1
Wavegen1.Channel1.Basic.Offset.value = 0
Wavegen1.Channel1.run()

Scope1.Channel1.Range.value = 2
Scope1.Channel1.Offset.value = 0
Scope1.Channel2.Range.value = 2
Scope1.Channel2.Offset.value = 0

print("Scope1-Input(Hz) (V)\tScope2-Output(Hz) (V)")

var hzStart = 1e3
var hzStop = 5e6
var steps = 100
var mul = Math.pow(10, (Math.log(hzStop/hzStart)/Math.LN10/(steps-1)))
var hz = hzStart
for(var i=1; i <= steps; i++){
   Wavegen1.Channel1.Basic.Frequency.value = hz
   // time base = number of periods to capture / frequency
   Scope1.Time.Base.value = 10/hz
   // wait between changing the frequency and acquisition
   wait(0.01) // 10ms
   Scope1.single()
   Scope1.wait()
   //echo(i+"\t"+hz +"\t"+ Scope.Measure.C1.Amplitude+"\t"+ Scope.Measure.C2.Amplitude )
   print(hz +"\t"+ Math.log(Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10*20)
   hz *= mul
}

 

​wow, great thank you very much!

 

kind regards,

hugo

Edited by attila

Share this post


Link to post
Share on other sites
  • 0

Could you please mark the answers on your questions to have the post closed.

Thank you

​Could clarify what you mean by  "mark the answers"? Is this the same as clicking on "You like this"?

hugo

Edited by hugocoolens

Share this post


Link to post
Share on other sites
  • 0

I was thinking on the check mark on the left side of the reply, "Mark this as a best answer".

​Oh, now I see what you mean, I'll do my homework from now on

thanks again for all the help

hugo

Share this post


Link to post
Share on other sites
  • 0

The equivalent script in WaveForms3 java script looks like this:

Wavegen1.Channel1.Mode.text = "Basic"
Wavegen1.Channel1.Basic.Amplitude.value = 1
Wavegen1.Channel1.Basic.Offset.value = 0
Wavegen1.Channel1.run()

Scope1.Channel1.Range.value = 2
Scope1.Channel1.Offset.value = 0
Scope1.Channel2.Range.value = 2
Scope1.Channel2.Offset.value = 0

print("Scope1-Input(Hz) (V)\tScope2-Output(Hz) (V)")

var hzStart = 1e3
var hzStop = 5e6
var steps = 100
var mul = Math.pow(10, (Math.log(hzStop/hzStart)/Math.LN10/(steps-1)))
var hz = hzStart
for(var i=1; i <= steps; i++){
   Wavegen1.Channel1.Basic.Frequency.value = hz
   // time base = number of periods to capture / frequency
   Scope1.Time.Base.value = 10/hz
   // wait between changing the frequency and acquisition
   wait(0.01) // 10ms
   Scope1.single()
   Scope1.wait()
   //echo(i+"\t"+hz +"\t"+ Scope.Measure.C1.Amplitude+"\t"+ Scope.Measure.C2.Amplitude )
   print(hz +"\t"+ Math.log((Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10)*20)
   hz *= mul
}

 

​I noticed there was something wrong with the brackets in the last print statement:

Here is a corrected version:

print(hz +"\t"+ Math.log(Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10*20)

 

kind regards,

Hugo

Share this post


Link to post
Share on other sites
  • 0

The equivalent script in WaveForms3 java script looks like this:

Wavegen1.Channel1.Mode.text = "Basic"
Wavegen1.Channel1.Basic.Amplitude.value = 1
Wavegen1.Channel1.Basic.Offset.value = 0
Wavegen1.Channel1.run()

Scope1.Channel1.Range.value = 2
Scope1.Channel1.Offset.value = 0
Scope1.Channel2.Range.value = 2
Scope1.Channel2.Offset.value = 0

print("Scope1-Input(Hz) (V)\tScope2-Output(Hz) (V)")

var hzStart = 1e3
var hzStop = 5e6
var steps = 100
var mul = Math.pow(10, (Math.log(hzStop/hzStart)/Math.LN10/(steps-1)))
var hz = hzStart
for(var i=1; i <= steps; i++){
   Wavegen1.Channel1.Basic.Frequency.value = hz
   // time base = number of periods to capture / frequency
   Scope1.Time.Base.value = 10/hz
   // wait between changing the frequency and acquisition
   wait(0.01) // 10ms
   Scope1.single()
   Scope1.wait()
   //echo(i+"\t"+hz +"\t"+ Scope.Measure.C1.Amplitude+"\t"+ Scope.Measure.C2.Amplitude )
   print(hz +"\t"+ Math.log((Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10)*20)
   hz *= mul
}

 

​Is it possible to write the output data to a file?

 

regards,

hugo

Share this post


Link to post
Share on other sites
  • 0

Thank you for the correction.
 

Writing/logging to file can be done like this:
 

var file = File("C:/log.txt")
file.write("") //clear
//...
var sz = hz +"\t"+ Math.log(Scope1.Channel2.measure("Amplitude")/Scope1.Channel1.measure("Amplitude"))/Math.LN10*20
file.appendLine(sz)

See help for more options.
 

On recent MS Windows, writing to C: from applications without root permission will be placed to:
C:\Users\[user]\AppData\Local\VirtualStore\

​thanks this works like a charm under linux (no drive-letters needed ;-)

hugo

 

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
Sign in to follow this