예제 #1
0
    def __init__(self, channel, v_range, hz_acq, n_samples):
        gr.sync_block.__init__(self,
                               name="AD2_AnalogIn_Record_f",
                               in_sig=None,
                               out_sig=[numpy.float32])
        #print DWF version
        print("DWF Version: " + dwf.FDwfGetVersion())

        #open device with configure
        self.hdwf = dwf.Dwf(-1, 1)  # 1:Scope Buffer Size 16k

        #set up acquisition
        self.dwf_ai = dwf.DwfAnalogIn(self.hdwf)
        self.dwf_ai.channelEnableSet(channel, True)
        self.dwf_ai.channelRangeSet(channel, v_range)
        self.dwf_ai.acquisitionModeSet(self.dwf_ai.ACQMODE.RECORD)
        self.dwf_ai.frequencySet(hz_acq)
        self.dwf_ai.recordLengthSet(-1)  #infinite time
        buffer_size = self.dwf_ai.bufferSizeGet()
        print "BufferSize " + str(buffer_size)

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

        #begin acquisition
        self.dwf_ai.configure(False, True)
        print("begin acquisition")

        self.rgdSamples = [0.0] * n_samples
        self.cSamples = 0
        self.fLost = False
        self.fCorrupted = False
예제 #2
0
def test_dwf_close():
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()
            dev.close()

            dev.hdwf.close.assert_called_once()
예제 #3
0
def test_init_dwf():
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()
            digital_dev = dwf.DwfDigitalOut(dev)

            low_level_patch.FDwfDeviceOpen.assert_called_once_with(-1)
            hdwf_patch.assert_called_once_with(low_level_patch.FDwfDeviceOpen.return_value)
예제 #4
0
def test_dwf_reset():
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            dev.reset()

            low_level_patch.FDwfDeviceReset.assert_called_once()
예제 #5
0
def test_dwf_auto_configure_get():
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            dev.autoConfigureGet()

            low_level_patch.FDwfDeviceAutoConfigureGet.assert_called_once()
예제 #6
0
def test_dwf_trigger_pc():
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            dev.triggerPC()
            low_level_patch.FDwfDeviceTriggerPC.assert_called_once_with(
                dev.hdwf)
예제 #7
0
def test_dwf_enable_set(config):
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            dev.enableSet(config)

            low_level_patch.FDwfDeviceEnableSet.assert_called_once_with(
                dev.hdwf, config)
예제 #8
0
def test_dwf_init_device_id_and_device_config(device_id, device_cfg):
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf(device_id, device_cfg)

            low_level_patch.FDwfDeviceConfigOpen.assert_called_once_with(
                device_id, device_cfg)
            hdwf_patch.assert_called_once_with(
                low_level_patch.FDwfDeviceConfigOpen.return_value)
예제 #9
0
def test_dwf_trigger_set(pin, source):
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            dev.triggerSet(pin, source)

            low_level_patch.FDwfDeviceTriggerSet.assert_called_once_with(
                dev.hdwf, pin, source)
예제 #10
0
def test_dwf_trigger_get(pin, source):
    with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
        with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
            dev = dwf.Dwf()

            low_level_patch.FDwfDeviceTriggerGet.return_value = source
            value = dev.triggerGet(pin)

            low_level_patch.FDwfDeviceTriggerGet.assert_called_once_with(
                dev.hdwf, pin)
            assert value == source
예제 #11
0
def test_dwf_trigger_info():
    with unittest.mock.patch.object(dwf.api, '_make_set') as make_patch:
        with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch:
            with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
                dev = dwf.Dwf()

                dev.triggerInfo()

                low_level_patch.FDwfDeviceTriggerInfo.assert_called_once_with(
                    dev.hdwf)
                make_patch.assert_called_once_with(
                    low_level_patch.FDwfDeviceTriggerInfo.return_value,
                    dev.TRIGSRC)
예제 #12
0
    def __init__(self, channel, v_range, hz_acq, n_samples):
        gr.sync_block.__init__(self,
            name="AD2_AnalogIn_Shift_f",
            in_sig=None,
            out_sig=[numpy.float32])

        #open device
        print("Opening first device")
        self.hdwf = dwf.Dwf()
        #set up acquisition
        self.dwf_ai = dwf.DwfAnalogIn(self.hdwf)
        self.dwf_ai.channelEnableSet(channel, True)
        self.dwf_ai.channelRangeSet(channel, v_range)
        self.dwf_ai.acquisitionModeSet(self.dwf_ai.ACQMODE.SCAN_SHIFT)
        self.dwf_ai.frequencySet(hz_acq)
        self.dwf_ai.bufferSizeSet(n_samples)
        self.rgdSamples = []
        self.ary_num = 0

        print("wait at 2 seconds for the offset to stabilize")
        time.sleep(2)

        #begin acquisition
        self.dwf_ai.configure(False, True)
예제 #13
0
"""
    Modified from:
        Python Example stepper motor driver
        Author:  D Mecer
        Revision: 11/27/2013
"""

import time
import dwf
from tkinter import *

master = Tk()
step_time = 0.001
hdwf = dwf.Dwf()
digo = dwf.DwfDigitalOut(hdwf)
digio = dwf.DwfDigitalIO(hdwf)

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

# generate on D0 - D3 50 Hz pulse (100MHz/500000/(3+1)), 25% duty (3low 1high)
for ch in range(4):
    digo.enableSet(ch, True)
    digo.dividerSet(ch, 500000)
    digo.counterSet(ch, 3, 1)

digio.outputEnableSet(0x00F0)
digio.outputSet(0x00F0)


def step_forward():
    digo.configure(0)
def hdwf():
    """Get a handle for the device to test with."""
    device = dwf.DwfEnumeration()[0]
    hdwf = dwf.Dwf(device)
    yield hdwf
    hdwf.close()
예제 #15
0
def test_dwf_init_none():
    with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
        low_level_patch.FDwfDeviceOpen.return_value = dwf.Dwf.DEVICE_NONE

        with pytest.raises(RuntimeError):
            dwf.Dwf()