Exemplo n.º 1
0
def test_digital_out_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.DwfDigitalOut()
            dev.reset()

            low_level_patch.FDwfDigitalOutReset.assert_called_once_with(dev.hdwf)
Exemplo n.º 2
0
def test_init_default():
    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.DwfDigitalOut()

            low_level_patch.FDwfDeviceOpen.assert_called_once_with(-1)
            hdwf_patch.assert_called_once_with(low_level_patch.FDwfDeviceOpen.return_value)
Exemplo n.º 3
0
def test_device_in_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.DwfDigitalOut()
            dev.reset(parent=True)

            low_level_patch.FDwfDeviceReset.assert_called_once_with(dev.hdwf)
Exemplo n.º 4
0
def test_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.DwfDigitalOut(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)
Exemplo n.º 5
0
def test_repeat_trigger_set(repeat):
    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.DwfDigitalOut()

            dev.repeatTriggerSet(repeat)

            low_level_patch.FDwfDigitalOutRepeatTriggerSet.assert_called_once_with(dev.hdwf, repeat)
Exemplo n.º 6
0
def test_wait_set(wait_time):
    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.DwfDigitalOut()

            dev.waitSet(wait_time)

            low_level_patch.FDwfDigitalOutWaitSet.assert_called_once_with(dev.hdwf, wait_time)
Exemplo n.º 7
0
def test_trigger_source_set(trigger):
    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.DwfDigitalOut()

            dev.triggerSourceSet(trigger)

            low_level_patch.FDwfDigitalOutTriggerSourceSet.assert_called_once_with(dev.hdwf, trigger)
Exemplo n.º 8
0
def test_type_info(channel):
    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.DwfDigitalOut()

            dev.typeInfo(channel)

            low_level_patch.FDwfDigitalOutTypeInfo.assert_called_once_with(dev.hdwf, channel)
Exemplo n.º 9
0
def test_configure(start_stop):
    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.DwfDigitalOut()

            dev.configure(start_stop)

            low_level_patch.FDwfDigitalOutConfigure.assert_called_once_with(dev.hdwf, start_stop)
Exemplo n.º 10
0
def test_output_set(channel, output_type):
    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.DwfDigitalOut()

            dev.outputSet(channel, output_type)

            low_level_patch.FDwfDigitalOutOutputSet.assert_called_once_with(dev.hdwf, channel, output_type)
Exemplo n.º 11
0
def test_divider_init_set(channel, divider):
    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.DwfDigitalOut()

            dev.dividerInitSet(channel, divider)

            low_level_patch.FDwfDigitalOutDividerInitSet.assert_called_once_with(dev.hdwf, channel, divider)
Exemplo n.º 12
0
def test_idle_set(channel, idle_state):
    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.DwfDigitalOut()

            dev.idleSet(channel, idle_state)

            low_level_patch.FDwfDigitalOutIdleSet.assert_called_once_with(dev.hdwf, channel, idle_state)
Exemplo n.º 13
0
def test_data_set(channel, bits):
    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.DwfDigitalOut()

            dev.dataSet(channel, bits)

            low_level_patch.FDwfDigitalOutDataSet.assert_called_once_with(dev.hdwf, channel, bits)
Exemplo n.º 14
0
def test_counter_set(channel, low, high):
    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.DwfDigitalOut()

            dev.counterSet(channel, low, high)

            low_level_patch.FDwfDigitalOutCounterSet.assert_called_once_with(dev.hdwf, channel, low, high)
Exemplo n.º 15
0
def test_counter_init_set(channel, value, state):
    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.DwfDigitalOut()

            dev.counterInitSet(channel, state, value)

            low_level_patch.FDwfDigitalOutCounterInitSet.assert_called_once_with(dev.hdwf, channel, state, value)
Exemplo n.º 16
0
def test_channel_count():
    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.DwfDigitalOut()

            value = dev.channelCount()

            low_level_patch.FDwfDigitalOutCount.assert_called_once_with(dev.hdwf)
            assert value == low_level_patch.FDwfDigitalOutCount.return_value
Exemplo n.º 17
0
def test_data_info(channel):
    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.DwfDigitalOut()

            value = dev.dataInfo(channel)

            low_level_patch.FDwfDigitalOutDataInfo.assert_called_once_with(dev.hdwf, channel)
            assert value == low_level_patch.FDwfDigitalOutDataInfo.return_value
Exemplo n.º 18
0
def test_wait_info():
    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.DwfDigitalOut()

            value = dev.waitInfo()

            low_level_patch.FDwfDigitalOutWaitInfo.assert_called_once_with(dev.hdwf)
            assert value == low_level_patch.FDwfDigitalOutWaitInfo.return_value
Exemplo n.º 19
0
def test_repeat_status():
    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.DwfDigitalOut()

            value = dev.repeatStatus()
            low_level_patch.FDwfDigitalOutRepeatStatus.assert_called_once_with(dev.hdwf)

            assert value == low_level_patch.FDwfDigitalOutRepeatStatus.return_value
Exemplo n.º 20
0
def test_trigger_source_get(trigger):
    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.DwfDigitalOut()

            low_level_patch.FDwfDigitalOutTriggerSourceGet.return_value = trigger
            value = dev.triggerSourceGet()

            low_level_patch.FDwfDigitalOutTriggerSourceGet.assert_called_once_with(dev.hdwf)
            assert value == trigger
Exemplo n.º 21
0
def status(state):
    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.DwfDigitalOut()
            low_level_patch.FDwfDigitalOutStatus.return_value = state

            value = dev.status(state)

            low_level_patch.FDwfDigitalOutStatus.assert_called_once_with(dev.hdwf, state)
            assert value == state
Exemplo n.º 22
0
def test_counter_get(channel, counter):
    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.DwfDigitalOut()

            low_level_patch.FDwfDigitalOutCounterGet.return_value = counter

            value = dev.counterGet(channel)

            low_level_patch.FDwfDigitalOutCounterGet.assert_called_once_with(dev.hdwf, channel)
            assert value == counter
Exemplo n.º 23
0
def test_repeat_trigger_get(repeat):
    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.DwfDigitalOut()

            low_level_patch.FDwfDigitalOutRepeatTriggerGet.return_value = repeat

            value = dev.repeatTriggerGet()

            low_level_patch.FDwfDigitalOutRepeatTriggerGet.assert_called_once_with(dev.hdwf)
            assert value == repeat
Exemplo n.º 24
0
def test_idle_get(channel, idle_state):
    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.DwfDigitalOut()

            low_level_patch.FDwfDigitalOutIdleGet.return_value = idle_state

            value = dev.idleGet(channel)

            low_level_patch.FDwfDigitalOutIdleGet.assert_called_once_with(dev.hdwf, channel)
            assert value == idle_state
Exemplo n.º 25
0
def test_output_get(channel, output_type):
    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.DwfDigitalOut()

            low_level_patch.FDwfDigitalOutOutputGet.return_value = output_type

            value = dev.outputGet(channel)

            low_level_patch.FDwfDigitalOutOutputGet.assert_called_once_with(dev.hdwf, channel)
            assert value == output_type
Exemplo n.º 26
0
    def __init__(self, device_number=0, config=0):
        """
        Connect to device with optional configuration.

        It connects to device with device_number as listed by the enumerate_devices() function of this module.
        Note that the default value of 0 will simply connect to the first device found.
        The possible configurations are also returned by enumerate_devices(). Note that enumerate devices is run at time
        of module import and stored in the variable devices. Note that the information returned by enumerate_devices()
        (or stored in the variable devices) can be diplayed in more readable form with the function print_device_list()
        of this module.

        :param device_number: the device number (default: 0)
        :type device_number: int
        :param config: configuration number (default: 0)
        :type config: int
        """
        self.logger = logging.getLogger(__name__)
        super().__init__(device_number, config)

        self.AnalogIn = dwf.DwfAnalogIn(self)
        self.AnalogOut = dwf.DwfAnalogOut(self)
        self.DigitalIn = dwf.DwfDigitalIn(self)
        self.DigitalOut = dwf.DwfDigitalOut(self)

        # Not sure yet what these do:
        self.AnalogIO = dwf.DwfAnalogIO(self)
        self.DigitalIO = dwf.DwfDigitalIO(self)

        # create short name references
        self.ai = self.AnalogIn
        self.ao = self.AnalogOut
        self.di = self.DigitalIn
        self.do = self.DigitalOut

        self.basic_analog_return_std = False  # will be overwritten by preset_basic_analog()
        self._read_timeout = 1  # will be overwritten by preset_basic_analog()
        self._last_ao0 = 0  # will be overwritten by write_analog()
        self._last_ao1 = 0  # will be overwritten by write_analog()
        self._time_stabilized = time.time(
        )  # will be overwritten by write_analog()
        self.preset_basic_analog()

        self.logger.debug('DfwController object created')
Exemplo n.º 27
0
    def __init__(self,
                 hdwf,
                 pin,
                 cal=None,
                 limits=None,
                 slope=1.1 / 120,
                 t_mid=1.5,
                 theta_min=-80,
                 theta_max=80):
        self.device = dwf.DwfDigitalOut(hdwf)
        self.pin = None
        self.set_pin(pin)

        self.theta_min = theta_min
        self.theta_max = theta_max
        self.t_mid = t_mid
        self.slope = slope

        self.cc = True
Exemplo n.º 28
0
   Original Revision: 11/24/2014

   Requires:                       
       Python 2.7, 3.3 or later
"""

import dwf
import math

#print DWF version
print("DWF Version: " + dwf.FDwfGetVersion())

#open device
print("Opening first device")
dwf_di = dwf.DwfDigitalIn()
dwf_do = dwf.DwfDigitalOut(dwf_di)

print("Configuring Digital Out / In...")

# generate counter
for i in range(16):
    dwf_do.enableSet(i, True)
    dwf_do.dividerSet(i, 0x01 << i)
    dwf_do.counterSet(i, 1000, 1000)

dwf_do.configure(True)

# set number of sample to acquire
N_SAMPLES = 100000

# in record mode samples after trigger are acquired only
Exemplo n.º 29
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)
Exemplo n.º 30
0
def test_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.DwfDigitalOut()