mariusgreuel/dwfpy

Inclusion of Analog Discovery 3

Closed this issue · 5 comments

After downloading the source and trying to make edits to duplicate instances of AnalogDiscovery2 and ANALOG_DISCOVERY2 to include references to the new AD3, I still wound up with some issues access the device with the dwfpy package. With that said, all is not lost. For those interested the core functionality appears to still be maintained with the core dwf.Device class. I'm sure there is some functionality that is lost but it can still work to some degree.

I didn't go through all of the examples, but for my limited usage (i.e., just the waveform out channels and the scope functions), the following appears to work:

with dwf.Device() as device:    
    print(f'Found device: {device.name} ({device.serial_number})')

    scope = device.analog_input
    wavegen = device.analog_output
    ##....Do your thing....

There is a branch for the AD3, however, due to the lack of an AD3, I have not tested anything. Could you please try https://github.com/mariusgreuel/dwfpy/tree/ad3 and provide feedback?

That said, you can always use dwf.Device() instead of an overloaded class, however, the device specific features such as power will be harder to access.

For some information on how to install the dwfpy package locally, see Developer Cheat Sheet.

I also have an AD3 so will be slowly testing and making PRs. Thanks for this package!

Thanks for pushing the new update that supports AD3. From the limited tests I had time to do, all seemed to work fine. I didn't test all of the capabilities but did play around with larger buffers and callbacks. Awesome work. Much appreciated.

For those looking to build on these tests here's the general framework I was working with via the jupyter notebook:

%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt

import dwfpy as dwf

with dwf.Device() as device:
    print(f'Found device: {device.name} ({device.serial_number})')

Separate Cell:

fig = plt.figure(figsize=(10, 6))
grid = plt.GridSpec(3, 3, hspace=0.2, wspace=0.2)
runAx = fig.add_subplot(grid[0, :])
mainAx = fig.add_subplot(grid[1:3, :])

plt.ion()

fig.show()
fig.canvas.draw()

DAQ Cell--Note you need to wire the waveform generator out to the input channels.

"""
DWF Python Example

This script is adapted from part of dwfpy: https://github.com/mariusgreuel/dwfpy
"""

print(f'DWF Version: {dwf.Application.get_version()}')

numSubSamples = 5
numRuns = 10
bufSize = 8192*2

runAve = np.zeros(numSubSamples)

with dwf.AnalogDiscovery3() as device: #for AD3
# with dwf.AnalogDiscovery2() as device: #for AD2    
# with dwf.Device() as device: #for AD3 Generic
    print(f'Found device: {device.name} ({device.serial_number})')

    scope = device.analog_input
    wavegen = device.analog_output  

    print('Generating square wave...')
#     wavegen[0].setup('sine', frequency=2000, amplitude=1, offset=1, start=False)
    wavegen[0].setup('noise', amplitude=2, frequency = 10000, start=False)
    wavegen[1].setup('pulse', frequency = 10, amplitude = 2, symmetry = 0.2, start = False)
    
    wavegen[0].configure(start = True)
    wavegen[1].configure(start = True)

    print('Starting repeated acquisitions...')
    scope[0].setup(range=5)
    scope.setup_edge_trigger(mode='normal', channel=1, slope='rising', level=0.5, hysteresis=0.01)
    scope.single(sample_rate=1e6, buffer_size=bufSize, configure=True, start=True)
    
    k = 0
    
    for m in range(numSubSamples):
        
        tempSamples = np.zeros(bufSize)
        tempAverages = np.zeros(numRuns)
        
        for i in range(numRuns):
            k += 1

            scope.wait_for_status(dwf.Status.DONE, read_data=True)
            samplesA = scope[0].get_data()
            samplesB = scope[1].get_data()   
            
            tempSamples += samplesA/numSubSamples
            tempAverages[i] = samplesA.mean()


        ###PLOTTING
        runAx.clear()
        mainAx.clear()
        runAve[m] = tempAverages.mean()
        runAx.plot(runAve, 'ro-', mfc = 'w', label = m+1)

        mainAx.plot(np.roll(samplesA, int(bufSize/2)), label = k)#
        mainAx.legend()
        runAx.legend()
        fig.canvas.draw()

Can confirm that the AD3 branch seems to work pretty well. Some things are superfluous - like the AD3 doesn't have an AUX channel anymore. I'm still just running through the examples. Let me know if there's anything I can check specifically.