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.DwfDigitalIn() dev.reset(parent=True) low_level_patch.FDwfDeviceReset.assert_called_once_with(dev.hdwf)
def test_divider_set(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.DwfDigitalIn() dev.dividerSet(divider) low_level_patch.FDwfDigitalInDividerSet.assert_called_once_with( dev.hdwf, divider)
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.DwfDigitalIn() low_level_patch.FDwfDeviceOpen.assert_called_once_with(-1) hdwf_patch.assert_called_once_with( low_level_patch.FDwfDeviceOpen.return_value)
def test_clock_source_set(clock): 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.DwfDigitalIn() dev.clockSourceSet(clock) low_level_patch.FDwfDigitalInClockSourceSet.assert_called_once_with( dev.hdwf, clock)
def test_buffer_size_set(size): 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.DwfDigitalIn() dev.bufferSizeSet(size) low_level_patch.FDwfDigitalInBufferSizeSet.assert_called_once_with( dev.hdwf, size)
def test_trigger_auto_timeout_set(value): 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.DwfDigitalIn() dev.triggerAutoTimeoutSet(value) low_level_patch.FDwfDigitalInTriggerAutoTimeoutSet.assert_called_once_with( dev.hdwf, value)
def test_trigger_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.DwfDigitalIn() value = dev.triggerGet() low_level_patch.FDwfDigitalInTriggerGet.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInTriggerGet.return_value
def test_trigger_position_set(samples): 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.DwfDigitalIn() dev.triggerPositionSet(samples) low_level_patch.FDwfDigitalInTriggerPositionSet.assert_called_once_with( dev.hdwf, samples)
def test_sample_mode_set(sample_mode): 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.DwfDigitalIn() dev.sampleModeSet(sample_mode) low_level_patch.FDwfDigitalInSampleModeSet.assert_called_once_with( dev.hdwf, sample_mode)
def test_trig_src_set(trig_src): 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.DwfDigitalIn() dev.triggerSourceSet(trig_src) low_level_patch.FDwfDigitalInTriggerSourceSet.assert_called_once_with( dev.hdwf, trig_src)
def test_acq_mode_set(acq_mode): 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.DwfDigitalIn() dev.acquisitionModeSet(acq_mode) low_level_patch.FDwfDigitalInAcquisitionModeSet.assert_called_once_with( dev.hdwf, acq_mode)
def test_configure(start, reconfigure): 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.DwfDigitalIn() dev.configure(reconfigure, start) low_level_patch.FDwfDigitalInConfigure.assert_called_once_with( dev.hdwf, reconfigure, start)
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.DwfDigitalIn(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)
def test_sample_format_set(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.DwfDigitalIn() dev.sampleFormatSet(bits) low_level_patch.FDwfDigitalInSampleFormatSet.assert_called_once_with( dev.hdwf, bits)
def test_trigger_auto_timeout_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.DwfDigitalIn() value = dev.triggerAutoTimeoutInfo() low_level_patch.FDwfDigitalInTriggerAutoTimeoutInfo.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInTriggerAutoTimeoutInfo.return_value
def test_status_record(): 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.DwfDigitalIn() value = dev.statusRecord() low_level_patch.FDwfDigitalInStatusRecord.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInStatusRecord.return_value
def test_internal_clock_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.DwfDigitalIn() value = dev.internalClockInfo() low_level_patch.FDwfDigitalInInternalClockInfo.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInInternalClockInfo.return_value
def test_buffer_size_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.DwfDigitalIn() value = dev.bufferSizeInfo() low_level_patch.FDwfDigitalInBufferSizeInfo.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInBufferSizeInfo.return_value
def test_sample_format_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.DwfDigitalIn() value = dev.sampleFormatGet() low_level_patch.FDwfDigitalInSampleFormatGet.assert_called_once_with( dev.hdwf) assert value == low_level_patch.FDwfDigitalInSampleFormatGet.return_value
def test_clock_source_info(clock): 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.DwfDigitalIn() low_level_patch.FDwflDigitalInClockSourceInfo.return_value = clock value = dev.clockSourceInfo() low_level_patch.FDwfDigitalInClockSourceInfo.assert_called_once_with( dev.hdwf)
def test_trig_src_info(trig_src): 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.DwfDigitalIn() low_level_patch.FDwfDigitalInTriggerSourceInfo.return_value == trig_src value = dev.triggerSourceInfo() low_level_patch.FDwfDigitalInTriggerSourceInfo.assert_called_once_with( dev.hdwf)
def test_trigger_set(triggers): (low_level, high_level, rising_edge, falling_edge) = triggers 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.DwfDigitalIn() dev.triggerSet(low_level, high_level, rising_edge, falling_edge) low_level_patch.FDwfDigitalInTriggerSet.assert_called_once_with( dev.hdwf, low_level, high_level, rising_edge, falling_edge)
def test_sample_mode_info(sample_mode): 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.DwfDigitalIn() low_level_patch.FDwfDigitalInSampleModeInfo.return_value == sample_mode value = dev.sampleModeInfo() low_level_patch.FDwfDigitalInSampleModeInfo.assert_called_once_with( dev.hdwf)
def test_acq_mode_info(acq_mode): 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.DwfDigitalIn() low_level_patch.FDwfDigitalInAcquisitionModeInfo.return_value == acq_mode value = dev.acquisitionModeInfo() low_level_patch.FDwfDigitalInAcquisitionModeInfo.assert_called_once_with( dev.hdwf)
def test_status_auto_triggered(return_value): with unittest.mock.patch.object(dwf.api, "_HDwf") as hdwf_patch: with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch: low_level_patch.FDwfDigitalInStatusAutoTriggered.return_value = return_value dev = dwf.DwfDigitalIn() value = dev.statusAutoTriggered() low_level_patch.FDwfDigitalInStatusAutoTriggered.assert_called_once_with( dev.hdwf) assert value == return_value
def test_status(read, 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.DwfDigitalIn() low_level_patch.FDwfDigitalInStatus.return_value = state value = dev.status(read) assert value == state low_level_patch.FDwfDigitalInStatus.assert_called_once_with( dev.hdwf, read)
def test_status_data(sample_format, samples, data, expected): 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.DwfDigitalIn() low_level_patch.FDwfDigitalInSampleFormatGet.return_value = sample_format low_level_patch.FDwfDigitalInStatusData.return_value = data value = dev.statusData(samples) assert value == expected low_level_patch.FDwfDigitalInStatusData.assert_called_once()
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')
Original Author: Digilent, Inc. 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
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.DwfDigitalIn()