I am trying to generate analogOut on the ad2 using the python sdk. In particular, I wish to change the amplitude and generate the waveform repeatedly. this code generates nothing, any ideas? Cheers - m
channel = c_int(0)
result = dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_int(1))
result = dwf.FDwfAnalogOutIdleSet(hdwf, channel, c_int(1)) # DwfAnalogOutIdleOffset
result = dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcPlayPattern) #funcCustom funcPlayPattern)
result = dwf.FDwfAnalogOutNodeDataSet(hdwf, channel, AnalogOutNodeCarrier, rgdSamples, int(cSamples))
if result != 1:
print(f'FAILED TO LOAD WAVEFORM, result = {result:d}')
breakpoint()
result = dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(pulseParams["Fs_Hz"]))
result = dwf.FDwfAnalogOutWaitSet(hdwf, channel, c_double( pulseParams["delayBetweenPulses_s"])) # run for pattern duration
result = dwf.FDwfAnalogOutRepeatTriggerSet(hdwf, channel, c_int(pulseParams["repeatTrigger"]))
# supports value up to 32768 or use 0 for infinite repeat
print(f'Number of pulses: {pulseParams["numPulses"]:d}')
result = dwf.FDwfAnalogOutRepeatSet(hdwf, channel, c_int(pulseParams["numPulses"])) # repeat N times
result = dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(3)) # auto configure 0 disabled, 1 enabled, 3 dynamic
print("Generating trigger...")
sts = c_ubyte(0)
for amplitude in pulseParams["amplitude_Vpp"]:
result = dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(amplitude))
result = dwf.FDwfAnalogOutRunSet(hdwf, channel, c_double(cSamples/pulseParams["Fs_Hz"])) # run for pattern duration
#dwf.FDwfDeviceTriggerSet( hdwf, int idxPin, trigsrcPC) # trigsrcExternal1 trigsrcPC
result = dwf.FDwfAnalogOutTriggerSourceSet(hdwf, channel, trigsrcExternal1 ) # 11 = trigsrcExternal1
#result = dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(1))
while True:
result = dwf.FDwfAnalogOutStatus(hdwf, channel, byref(sts))
#print(f'result = {result:d} ; sts = {sts.value : d}')
if sts.value == DwfStateDone.value : break # DwfStateDone, see AnalogOut_play.py example
print(f'Amplitude {amplitude:f} complete')
Question
mikeyc
Hi there,
I am trying to generate analogOut on the ad2 using the python sdk. In particular, I wish to change the amplitude and generate the waveform repeatedly. this code generates nothing, any ideas? Cheers - m
channel = c_int(0)
result = dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_int(1))
result = dwf.FDwfAnalogOutIdleSet(hdwf, channel, c_int(1)) # DwfAnalogOutIdleOffset
result = dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcPlayPattern) #funcCustom funcPlayPattern)
result = dwf.FDwfAnalogOutNodeDataSet(hdwf, channel, AnalogOutNodeCarrier, rgdSamples, int(cSamples))
if result != 1:
print(f'FAILED TO LOAD WAVEFORM, result = {result:d}')
breakpoint()
result = dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(pulseParams["Fs_Hz"]))
result = dwf.FDwfAnalogOutWaitSet(hdwf, channel, c_double( pulseParams["delayBetweenPulses_s"])) # run for pattern duration
result = dwf.FDwfAnalogOutRepeatTriggerSet(hdwf, channel, c_int(pulseParams["repeatTrigger"]))
# supports value up to 32768 or use 0 for infinite repeat
print(f'Number of pulses: {pulseParams["numPulses"]:d}')
result = dwf.FDwfAnalogOutRepeatSet(hdwf, channel, c_int(pulseParams["numPulses"])) # repeat N times
result = dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(3)) # auto configure 0 disabled, 1 enabled, 3 dynamic
print("Generating trigger...")
sts = c_ubyte(0)
for amplitude in pulseParams["amplitude_Vpp"]:
result = dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(amplitude))
result = dwf.FDwfAnalogOutRunSet(hdwf, channel, c_double(cSamples/pulseParams["Fs_Hz"])) # run for pattern duration
#dwf.FDwfDeviceTriggerSet( hdwf, int idxPin, trigsrcPC) # trigsrcExternal1 trigsrcPC
result = dwf.FDwfAnalogOutTriggerSourceSet(hdwf, channel, trigsrcExternal1 ) # 11 = trigsrcExternal1
#result = dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(1))
while True:
result = dwf.FDwfAnalogOutStatus(hdwf, channel, byref(sts))
#print(f'result = {result:d} ; sts = {sts.value : d}')
if sts.value == DwfStateDone.value : break # DwfStateDone, see AnalogOut_play.py example
print(f'Amplitude {amplitude:f} complete')
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now