Jump to content
  • 0

converting dwfbat script to the new scripting language


hugocoolens

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

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

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
}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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\

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...