Exemplo n.º 1
0
def test_dwf_enumeration(param):
    with unittest.mock.patch.object(dwf.api, '_l') as low_level_patch:
        with unittest.mock.patch.object(dwf.api, 'DwfDevice') as dev_patch:
            low_level_patch.FDwfEnum.return_value = 1
            value = dwf.DwfEnumeration(param)

            # Was FDwfEnum called with `param`
            low_level_patch.FDwfEnum.assert_called_once_with(param)

            # Was DwfDevice instantiated with the correct index
            dev_patch.assert_called_once_with(0)
Exemplo n.º 2
0
def ad_print_devices_info():
    """
    Print device info and get number of connected devices.

    :return: int: number of devices
    """
    devices = dwf.DwfEnumeration()
    print("Number of Devices: " + str(len(devices)))

    for i, device in enumerate(devices):
        print("------------------------------")
        print("Device " + str(i) + " : ")
        print("\t" + device.deviceName())
        print("\t" + device.SN())

    return len(devices)
Exemplo n.º 3
0
def enumerate_devices():
    """
    List connected devices and their possible configurations.
    Note: Use print_device_list() to easily display the result in readable form.

    :return: list of dictionaries containing information about the devices found
    :rtype: list
    """
    devices = []
    try:
        last_err_msg = dwf.FDwfGetLastErrorMsg()
        if last_err_msg:
            logging.getLogger(__name__).warning(last_err_msg)
        # enumerate devices
        devs = dwf.DwfEnumeration()
        ch = lambda n=0, b=0: {'ch': n, 'buf': b}

        for i, device in enumerate(devs):
            dev_dict = {'info': {}, 'configs': []}
            dev_dict['info']['SN'] = device.SN()
            dev_dict['info']['deviceName'] = device.deviceName()
            dev_dict['info']['userName'] = device.userName()
            dev_dict['dev'] = device

            if device.isOpened():
                logging.getLogger(__name__).warning(
                    f"Can't connect to device {i} ({dev_dict['info']['SN']}), a connection is already open.\n"
                    "Note that the list was stored in " + __name__ +
                    ".devices at the moment of import.")
                dev_dict[
                    'configs'] = "Couldn't connect to device for further information"
            else:
                dwf_ai = dwf.DwfAnalogIn(device)
                channel = dwf_ai.channelCount()
                _, hzFreq = dwf_ai.frequencyInfo()
                dev_dict['info']['maxAIfreq'] = hzFreq
                dwf_ai.close()

                n_configs = dwf.FDwfEnumConfig(i)
                for iCfg in range(0, n_configs):
                    aic = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIAnalogInChannelCount)  # 1
                    aib = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIAnalogInBufferSize)  # 7
                    aoc = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIAnalogOutChannelCount)  # 2
                    aob = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIAnalogOutBufferSize)  # 8
                    dic = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIDigitalInChannelCount)  # 4
                    dib = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIDigitalInBufferSize)  # 9
                    doc = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIDigitalOutChannelCount)  # 5
                    dob = dwf.FDwfEnumConfigInfo(
                        iCfg, dwf.DECIDigitalOutBufferSize)  # 10
                    dev_dict['configs'].append({
                        'ai': ch(aic, aib),
                        'ao': ch(aoc, aob),
                        'di': ch(dic, dib),
                        'do': ch(doc, dob)
                    })
                dwf_ai.close()
            devices.append(dev_dict)
    except:
        from sys import exc_info
        logging.getLogger(__name__).warning(
            "Exception occured while enumerating devices:\n",
            exc_info()[0])
    return devices
Exemplo n.º 4
0
   Requires:                       
       Python 2.7, 3.3 or later
"""

import dwf
import sys

#check library loading errors, like: Adept Runtime not found
print(dwf.FDwfGetLastErrorMsg())

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

#enumerate and print device information
devs = dwf.DwfEnumeration()
print("Number of Devices: " + str(len(devs)))

for i, device in enumerate(devs):
    print("------------------------------")
    print("Device " + str(i) + " : ")
    print("\t" + device.deviceName())
    print("\t" + device.SN())

    if not device.isOpened():
        dwf_ai = dwf.DwfAnalogIn(device)
        channel = dwf_ai.channelCount()
        _, hzFreq = dwf_ai.frequencyInfo()
        print("\tAnalog input channels: " + str(channel))
        print("\tMax freq: " + str(hzFreq))
        dwf_ai.close()
def hdwf():
    """Get a handle for the device to test with."""
    device = dwf.DwfEnumeration()[0]
    hdwf = dwf.Dwf(device)
    yield hdwf
    hdwf.close()
import pytest
import dwf

from hardware.signal_generator import AnalogDiscovery2SignalGenerator
from hardware.oscilloscope import AnalogDiscovery2Oscilloscope

if not dwf.DwfEnumeration():
    pytest.skip("skipping AnalogDiscovery2 tests, no device present",
                allow_module_level=True)

@pytest.fixture
def hdwf():
    """Get a handle for the device to test with."""
    device = dwf.DwfEnumeration()[0]
    hdwf = dwf.Dwf(device)
    yield hdwf
    hdwf.close()


def test_pass(hdwf):
    ado = AnalogDiscovery2Oscilloscope(hdwf)
    adsg = AnalogDiscovery2SignalGenerator(hdwf)

    # assert ado


def test_2(hdwf):
    ado = AnalogDiscovery2Oscilloscope(hdwf)
    adsg = AnalogDiscovery2SignalGenerator(hdwf)
    cho = ado.get_channel(0)
    chsg = adsg.get_channel((0, 'carrier'))
Exemplo n.º 7
0
   Modified by: MURAMATSU Atsushi <*****@*****.**>   
   Revised: 2016-04-21
   Original Author:  Digilent, Inc.
   Original Revision: 10/17/2013

   Requires:                       
       Python 2.7, 3.3 or later
"""

import dwf
import time
import matplotlib.pyplot as plt

print("Version: " + dwf.FDwfGetVersion())

cdevices = dwf.DwfEnumeration()
print("Number of Devices: " + str(len(cdevices)))

if len(cdevices) == 0:
    print("no device detected")
    quit()

print("Opening first device")
hdwf = dwf.Dwf()

print("Configure and start first analog out channel")
dwf_ao = dwf.DwfAnalogOut(hdwf)
dwf_ao.nodeEnableSet(0, dwf_ao.NODE.CARRIER, True)
print("1 = Sine wave")
dwf_ao.nodeFunctionSet(0, dwf_ao.NODE.CARRIER, dwf_ao.FUNC.SINE)
dwf_ao.nodeFrequencySet(0, dwf_ao.NODE.CARRIER, 3000.0)