Jump to content
  • 0

AD PRO 3000 AnalogIn Coupling 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()

Hello,

I have a question about programming with Waveform SDK.

I use an ADP3450 and I want to change the coupling of the Input channels from DC to AC. 

I added to the program the command below

dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1))

,but it didn't work.

Could somebody tell me how to get the program to work properly?

I attach the program of my python.

Thank you.

 

Edited by Take4
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @Take4

It is, it should work.

I've added the following to your code:
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(0.5))

Getting this with AC: dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(1))

image.png

 

and this with DC: dwf.FDwfAnalogInChannelCouplingSet(hdwf, c_int(-1), c_int(0))

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