def __init__(self, hdwf, pins, use_half_steps=False, step_time=0.002): self.device = dwf.DwfDigitalIO(hdwf) self.step_time = step_time self._pin_mask = None self._masked_steps = None self.set_pins(pins, use_half_steps) self.position = 0
def dio(request): ''' Mock up the Digital IO class by `patching` the low level API (dwf.api._l), and verifying the correct functions are called. ''' patcher = unittest.mock.patch.object(dwf.api, '_l') low_level_patch = patcher.start() dwf_dio = dwf.DwfDigitalIO() # Make sure that the HDWF Close doesn't get called (throws an error due to # back mocking dwf_dio.hdwf.close = unittest.mock.MagicMock() def _close(): patcher.stop() request.addfinalizer(_close) return (dwf_dio, low_level_patch)
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')
""" 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)
Original Author: Digilent, Inc. Original Revision: 10/17/2013 Requires: Python 2.7, 3.3 or later """ import dwf import sys #print DWF version print("DWF Version: " + dwf.FDwfGetVersion()) #open device print("Opening first device") dwf_dio = dwf.DwfDigitalIO() print("Preparing to read Digital IO pins...") # enable output/mask on 8 LSB IO pins, from DIO 0 to 7 dwf_dio.outputEnableSet(0x00FF) # set value on enabled IO pins dwf_dio.outputSet(0x0012) # fetch digital IO information from the device dwf_dio.status() # read state of all pins, regardless of output enable dwRead = dwf_dio.inputStatus() #print dwRead as bitfield (32 digits, removing 0b at the front) print("Digital IO Pins: " + bin(dwRead)[2:].zfill(32))