Jump to content
  • 0

AD PRO 3000 Waveform SDK


Take4

Question

from ctypes import *
from dwfconstants import *
import math
import time
import matplotlib.pyplot as plt
import sys
import numpy
import csv

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

#--------declare ctype variables----------
hdwf = c_int()
sts = c_byte()
hzAcq = c_double(1000000)
N = 262144
rgdSamples1 = (c_double*N)()
rgdSamples2 = (c_double*N)()
cAvailable = c_int()
cLost = c_int()
cCorrupted = c_int()
fLost = 0
fCorrupted = 0

#-----------print(DWF version)---------------
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print("DWF Version: "+str(version.value))

#---------------open device-------------------
print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

if hdwf.value == hdwfNone.value:
    szerr = create_string_buffer(512)
    dwf.FDwfGetLastErrorMsg(szerr)
    print(str(szerr.value))
    print("failed to open device")
    quit()

#------------------------------------Waveform setting------------------------------------------
print("Generating sine wave...")
dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(500))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(0.2))
dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1))

#---------------------------------set up for aquisition----------------------------------------
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_int(1))
dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1))
dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq)
dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(N/hzAcq.value)) # -1 infinite record length

#wait at least 2 seconds for the offset to stabilize
time.sleep(2)

print("Starting oscilloscope")
dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))

cSamples = 0

Channel1_data = []
Channel2_data = []

#---------------------------------------------Start aquisition-------------------------------------------------
while cSamples < N:
    dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
    if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
        # Acquisition not yet started.
        continue

    dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
    
    cSamples += cLost.value

    if cLost.value :
        fLost = 1
    if cCorrupted.value :
        fCorrupted = 1

    if cAvailable.value==0 :
        continue

    if cSamples+cAvailable.value > N :
        cAvailable = c_int(N-cSamples)
    
    dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples1, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data
    dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgdSamples2, sizeof(c_double)*cSamples), cAvailable) # get channel 2 data
    cSamples += cAvailable.value

dwf.FDwfAnalogOutReset(hdwf, c_int(0))
dwf.FDwfDeviceCloseAll()

print("Recording done")
if fLost:
    print("Samples were lost! Reduce frequency")
if fCorrupted:
    print("Samples could be corrupted! Reduce frequency")

#aquiring data length
data_length = len(rgdSamples1)

#Storing data in arrays
for i in range(data_length):
    Channel1_data.append(rgdSamples1[i])
    Channel2_data.append(rgdSamples2[i])

#--------------------------stored in csv file------------------------------
with open('record.csv', mode = 'w', newline = '') as file:
    writer = csv.writer(file)
    for item1, item2 in zip(Channel1_data, Channel2_data):
        writer.writerow([item1, item2])
    
plt.plot(numpy.fromiter(rgdSamples1, dtype = numpy.float64))
plt.plot(numpy.fromiter(rgdSamples2, dtype = numpy.float64))
plt.show()

2023-08-06224024.thumb.png.635e865acdb83ae0b09e748a0a7d59f1.png

The top waveform was obtained from the Waveform application and the bottom waveform was obtained using the Waveform SDK.

 

Hello, 

I have a question regarding the behavior of WaveForm SDK when acquiring waveforms.

I use an ADP3450 and I want to get the same waveforms in the WaveForms app and the WaveForm SDK, but this makes a difference.

Is this a difference between the settings in the SDK and the application?

Can someone please help me with a solution to this?

I attach the program of my python and the screen shot of the setting for acquiring waveforms in the application.

 

Below is a screen shot of the settings for waveform acquisition in the application.

2023-09-18231530.thumb.png.9be63b0519ce9bc851f5a7b19157b678.png

This is the entire WaveForms setup screen.

2023-09-18231710.png.bfa5c7162d9be64b28e9cd815f521b14.png

And, this image is the setting for acquiring waveforms.

 

Thank you.

Edited by Take4
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @Take4

It seems that the offset is the main difference in the data read by your Python script. What happens if you add an FdwfAnalogInChannelOffsetSet() for both channels?

Also, consider using pydwf. It will make your life a lot easier going forward.

To get a taste: here's the AnalogInRecordMode.py example supplied with pydwf.

Edited by reddish
Link to comment
Share on other sites

  • 0

Hi @Take4

The ADP3X50 input channels have two input ranges 2V and 50V. Configure dwf.FDwfAnalogInChannelRangeSet(hdwf, channel#, c_double(2.0))

With newer software version you don't have to complicate with Record mode, the default normal (acqmodeSingle) allows you to capture 128Mi samples, see AnalogIn_Trigger.py and other examples.

The latest versions also provide device buffering, memory segmentation, low latency <1us for consecutive captures.

image.png

Link to comment
Share on other sites

  • 0

Hi @attila

Thank you for your help.

I set analog input to 2V by dwf.FDwfAnalogInChannelRangeSet(hdwf, channel#, c_double(2.0)) and got the waveform below.

The new version looks useful, I'll consider updating.

One more question, can the sample mode be changed from the SDK?

Thank you.

2023-09-20002434.png.660b373fa3e86d4f5520ed18436f6df0.png

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...