I am trying to use python and the waveforms SDK to do a few different things. So far, I have been using the example python files and I have gotten help from @attila. I want three different AD3's to share a clock signal based off of the reference of a "master device". I want the three to then output a digital out clock signal and measure with analog in channels. All of this is working to my knowledge. I am now trying to turn on the +- voltage supplies to +-5v on all of the devices and having trouble. Everything runs as it should to my knowledge except the supplies do no turn on. Here is my code. Any suggestions?
from ctypes import*import sys
import time
import matplotlib.pyplot as plt
import numpy as np
from dwfconstants import*# Load the WaveForms library
dwf = cdll.dwf
# Initialize error message buffer
szerr = create_string_buffer(512)
dwf.FDwfGetLastErrorMsg(szerr)if szerr[0]!= b'\0':print(str(szerr.value))# Initialize device handle and list of device handles
hdwf = c_int(0)
rghdwf =[]
cChannel = c_int()
cDevice = c_int()
sts = c_byte()
cSamples =30000
rgdSamples =(c_double * cSamples)()# Buffers for device name and serial number
devicename = create_string_buffer(32)
serialnum = create_string_buffer(32)# Get and print WaveForms version
version = create_string_buffer(32)
dwf.FDwfGetVersion(version)print("DWF Version: "+ str(version.value))# Enumerate connected devices
dwf.FDwfEnum(c_int(0), byref(cDevice))print("Number of Devices: "+ str(cDevice.value))print("Connect trigger lines between devices for reference clock and triggering")
hdwfMaster = c_int(0)
dwf.FDwfParamSet(DwfParamExtFreq,10000000)# reference clock frequency
dwf.FDwfParamSet(DwfParamFrequency,100000000)# system clock frequency# Open each device and configure
dwf.FDwfEnum(c_int(0), byref(cDevice))for iDevice in range(cDevice.value):
dwf.FDwfDeviceOpen(c_int(iDevice), byref(hdwf))
dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(0), c_int(0), c_double(1))# enable positive supply
dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(0), c_int(1), c_double(5.0))# set voltage to 5 V
dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(1), c_int(0), c_double(1))# enable negative supply
dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(1), c_int(1), c_double(-5.0))# set voltage to -5 V
dwf.FDwfAnalogIOEnableSet(iDevice, c_int(1))# master enableif hdwf.value ==0:
dwf.FDwfGetLastErrorMsg(szerr)print(str(szerr.value))
dwf.FDwfDeviceCloseAll()
sys.exit(0)
rghdwf.append(hdwf.value)
dwf.FDwfDeviceAutoConfigureSet(hdwf,0)# the instruments will only be configured when FDwf###Configure is calledif hdwfMaster.value ==0:
hdwfMaster.value = hdwf.value
dwf.FDwfDeviceParamSet(hdwf,DwfParamClockMode,1)# reference clock output on Trigger 1
dwf.FDwfDeviceTriggerSet(hdwf,1, trigsrcPC)# Trigger 2 outputs TriggerPCelse:
dwf.FDwfDeviceParamSet(hdwf,DwfParamClockMode,2)# reference clock input on Trigger 1print(f"Configure Device {iDevice + 1}")
dwf.FDwfEnumDeviceName(c_int(iDevice), devicename)
dwf.FDwfEnumSN(c_int(iDevice), serialnum)print("\t"+ str(devicename.value))print("\t"+ str(serialnum.value))
dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcExternal2)
hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
cChannel = c_int()
dwf.FDwfDigitalOutCount(hdwf, byref(cChannel))for iChannel in range(cChannel.value):
dwf.FDwfDigitalOutEnableSet(hdwf, iChannel,1)# DIO-0
dwf.FDwfDigitalOutDividerSet(hdwf, iChannel, int(hzSys.value /1e3/2))# prescaler to 2kHz, SystemFrequency/1kHz/2
dwf.FDwfDigitalOutCounterSet(hdwf, iChannel,1,1)# 1 tick low, 1 tick high
dwf.FDwfDigitalOutRunSet(hdwf, iChannel, c_double(0.0001))
dwf.FDwfDigitalOutIdleSet(hdwf, iChannel,DwfDigitalOutIdleLow)
dwf.FDwfDigitalOutConfigure(hdwf,1)# Configure each device to trigger on External Trigger 1
dwf.FDwfAnalogInTriggerSourceSet(hdwf, c_int(12))# 12 = trigsrcExternal2
dwf.FDwfAnalogInFrequencySet(hdwf, c_double(1e6))# Set acquisition frequency to 1MHz
dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1))# Start analog input configuration# Wait for offsets to stabilize
time.sleep(5)# Wait until the last configured device is armed
hdwf.value = rghdwf[cDevice.value -1]whileTrue:
dwf.FDwfAnalogInStatus(hdwf, c_int(0), byref(sts))if sts.value ==1:# DwfStateArmedbreak
time.sleep(3)# Generate trigger signal on the first device to start both generators and acquisition
hdwf.value = rghdwf[0]
dwf.FDwfDeviceTriggerPC(hdwfMaster)
time.sleep(0.5)#Wait for acquisition to completewhileTrue:
dwf.FDwfAnalogInStatus(hdwf, c_int(0), byref(sts))if sts.value ==2:# DwfStateDonebreak# Plot the resultsfor iDevice in range(0, cDevice.value):
hdwf.value = rghdwf[iDevice]
dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))if sts.value !=2:# DwfStateDoneprint("Not triggered!")continue# Retrieve data from each channel and plot it
dwf.FDwfAnalogInChannelCount(hdwf, byref(cChannel))for iChannel in range(0, cChannel.value):
dwf.FDwfAnalogInStatusData(hdwf, iChannel, rgdSamples, c_int(cSamples))# Create a new figure for each channel
plt.figure()
plt.plot(np.fromiter(rgdSamples, dtype=float))
plt.title(f'Device {iDevice + 1}, Channel {iChannel + 1}')
plt.xlabel('Sample Index')
plt.ylabel('Voltage (V)')# Display the plots
plt.show()# Ensure all devices are closed
dwf.FDwfDeviceCloseAll()
Question
Maxpfeiff
I am trying to use python and the waveforms SDK to do a few different things. So far, I have been using the example python files and I have gotten help from @attila. I want three different AD3's to share a clock signal based off of the reference of a "master device". I want the three to then output a digital out clock signal and measure with analog in channels. All of this is working to my knowledge. I am now trying to turn on the +- voltage supplies to +-5v on all of the devices and having trouble. Everything runs as it should to my knowledge except the supplies do no turn on. Here is my code. Any suggestions?
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