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: 10/17/2013 Requires: Python 2.7, 3.3 or later """ import dwf import time #print DWF version print("DWF Version: " + dwf.FDwfGetVersion()) #open device print("Opening first device") dwf_aio = dwf.DwfAnalogIO() print("Device USB supply voltage, current and device temperature:") #monitor voltage, current, temperature #60 times, once per second for i in range(60): # wait between readings; the update rate is approximately 1Hz time.sleep(1) # fetch analog IO status from device dwf_aio.status() # get system monitor readings deviceVoltage = dwf_aio.channelNodeStatus(2, 0) deviceCurrent = dwf_aio.channelNodeStatus(2, 1) deviceTemperature = dwf_aio.channelNodeStatus(2, 2) print("%.4f V\t%.4f A\t%.4fdegC" % ( deviceVoltage, deviceCurrent, deviceTemperature))