Hey, I seem to be having a very difficult time with the documentation on the WaveForms SDK using python. I can read/write all DIOs and do everything else using the GUI waveforms, but I cannot read DIN pin 8-23. I have been able to read DINs 0-7.
I made a function to read a certain DIN, but then overwrote a few things because of troubleshooting, so the "pin_index" is really not used here as it prints all the pins out.
Can you please help me figure out why I cannot see DIN pins 8-23? I should add that I have another Digital Discovery outputting simple high signals to pins 0, 3, 7, 8, and 20, but I only get 0,3, and 7 to show up.
from ctypes import*import configparser
import sys
# Load the dwf libraryif 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")def initialize_devices():"""
Initialize the Digilent Digital Discoveries
"""
cDevice = c_int()
devicename = create_string_buffer(64)
serialnum = create_string_buffer(16)# Enumerate devices
dwf.FDwfEnum(c_int(0), byref(cDevice))
devices =[]for iDevice in range(cDevice.value):
dwf.FDwfEnumDeviceName(c_int(iDevice), devicename)
dwf.FDwfEnumSN(c_int(iDevice), serialnum)
devices.append((devicename.value.decode('utf-8'), serialnum.value.decode('utf-8')))return devices
devices = initialize_devices()print(devices)def open_device_by_serial(target_serial_number):"""
Open a device by its serial number
"""
cDevice = c_int()
serialnum = create_string_buffer(16)# Enumerate devices
dwf.FDwfEnum(c_int(0), byref(cDevice))# Find the device with the target serial numberfor iDevice in range(cDevice.value):
dwf.FDwfEnumSN(c_int(iDevice), serialnum)if serialnum.value.decode('utf-8')== target_serial_number:
hdwf = c_int()
dwf.FDwfDeviceOpen(c_int(iDevice), byref(hdwf))if hdwf.value ==0:raiseRuntimeError("Failed to open device.")return hdwf
raiseValueError(f"No device with serial number {target_serial_number} was found.")def read_din_pin(pin_index):
hdwf = open_device_by_serial(My_Serial)# Declare ctype variables
sts = c_byte()
cSamples =8192
rgwSamples =(c_uint32*cSamples)()# Adjusted for 32 bits
cAvailable = c_int()
cLost = c_int()
cCorrupted = c_int()
fLost =0
fCorrupted =0# Set up acquisition
dwf.FDwfDigitalInInternalClockInfo(hdwf, byref(c_double()))
dwf.FDwfDigitalInDividerSet(hdwf, c_double(10))
dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(32))# Adjusted for 32 bits
dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
dwf.FDwfDigitalInTriggerAutoTimeoutSet(hdwf, c_double(10))
dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(0))
dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(0))# Set sensible mask for specific pin
mask =1<< pin_index # This will create a mask that enables only the specified pin
dwf.FDwfDigitalInSampleSensibleSet(hdwf, c_int(mask))# Set trigger position
dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(8191))# 8191 is one less than cSamples# Start signal generation
dwf.FDwfDigitalInConfigure(hdwf, c_bool(False), c_bool(True))# Wait until donewhileTrue:
dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))if sts.value ==2:# DONEbreak
time.sleep(0.1)# Get sample
dwf.FDwfDigitalInStatusData(hdwf, rgwSamples,4*cSamples)# Adjusted for 32 bitsprint(rgwSamples[:10])# Close device
dwf.FDwfDeviceCloseAll()# Extract pin state from sample (for easier reading)for pin_index in range(24):
pin_state =(rgwSamples[0]>> pin_index)&1print(f"Pin {pin_index}: {pin_state}")return pin_state
read_din_pin(0)
Question
AstroKevin
Hey, I seem to be having a very difficult time with the documentation on the WaveForms SDK using python. I can read/write all DIOs and do everything else using the GUI waveforms, but I cannot read DIN pin 8-23. I have been able to read DINs 0-7.
I made a function to read a certain DIN, but then overwrote a few things because of troubleshooting, so the "pin_index" is really not used here as it prints all the pins out.
Can you please help me figure out why I cannot see DIN pins 8-23? I should add that I have another Digital Discovery outputting simple high signals to pins 0, 3, 7, 8, and 20, but I only get 0,3, and 7 to show up.
Link to comment
Share on other sites
2 answers 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